-
Notifications
You must be signed in to change notification settings - Fork 70
/
test.bats
executable file
·142 lines (118 loc) · 3.29 KB
/
test.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bats
load "assert"
exec0() {
if [ -z "$BINFMT_EMULATOR" ]; then
run ./execargv0 "$@"
else
PATH=/crossarch/usr/bin:/crossarch/bin:$PATH run buildkit-qemu-$BINFMT_EMULATOR ./execargv0 "$@"
fi
}
execdirect() {
if [ -z "$BINFMT_EMULATOR" ]; then
run "$@"
else
PATH=/crossarch/usr/bin:/crossarch/bin:$PATH run buildkit-qemu-$BINFMT_EMULATOR "$@"
fi
}
@test "exec-single" {
exec0 ./printargs foo bar1 bar2
assert_success
assert_output "foo bar1 bar2"
}
@test "exec-multi" {
exec0 ./execargv0 ./printargs ./printargs baz
assert_success
assert_output "baz"
}
@test "exec-multi-abs" {
exec0 ./execargv0 $(pwd)/printargs $(pwd)/printargs baz
assert_success
assert_output "baz"
}
@test "exec-multi-path" {
cp $(pwd)/printargs /usr/bin/test-printargs
exec0 test-printargs test-printargs abc
assert_success
assert_output "test-printargs abc"
}
@test "exec-direct" {
execdirect test-printargs foo bar1
assert_success
assert_output "test-printargs foo bar1"
}
@test "exec-direct-abs" {
execdirect $(pwd)/printargs foo bar1
assert_success
assert_output "$(pwd)/printargs foo bar1"
}
@test "shebang" {
exec0 ./shebang.sh arg1 arg2
assert_success
assert_output "./printargs $(pwd)/shebang.sh arg2"
}
@test "shebang-arg" {
exec0 ./shebang2.sh arg1 arg2
assert_success
assert_output "./printargs arg $(pwd)/shebang2.sh arg2"
}
@test "shebang-abs" {
exec0 ./shebang3.sh arg1 arg2
assert_success
assert_output "/work/printargs $(pwd)/shebang3.sh arg2"
}
@test "shebang-multi" {
exec0 ./shebang4.sh arg1 arg2
assert_success
assert_output "/work/printargs $(pwd)/shebang3.sh $(pwd)/shebang4.sh arg2"
}
@test "shebang-direct" {
execdirect ./shebang.sh foo bar1
assert_success
if [ -n "$BINFMT_EMULATOR" ]; then
# FIXME: direct exec patches should be fixed to not prepend workdir
assert_output "./printargs /work/shebang.sh foo bar1"
else
assert_output "./printargs ./shebang.sh foo bar1"
fi
}
@test "relative-exec" {
exec0 env env ./printargs foo bar1 bar2
assert_success
assert_output "./printargs foo bar1 bar2"
}
@test "path-based-exec" {
PATH="$PATH:/work" exec0 env env printargs foo bar1 bar2
assert_success
assert_output "printargs foo bar1 bar2"
}
@test "shebang-path" {
exec0 ./shebang-path.sh ./shebang-path.sh foo bar1
assert_success
assert_output "./printargs /work/shebang-path.sh foo bar1"
}
@test "shebang-path-shell" {
exec0 ./shebang-path2.sh ./shebang-path2.sh foo bar1
assert_success
assert_output "./printargs foo bar1"
}
@test "shell-command-relative" {
if [ -n "$BINFMT_EMULATOR" ]; then
skip "prepend_workdir_if_relative is altering the behaviour for args when run under emulation"
fi
exec0 sh sh -c './shebang-path.sh foo bar1 bar2'
assert_success
assert_output "./printargs ./shebang-path.sh foo bar1 bar2"
}
@test "shell-command-relative-direct" {
if [ -n "$BINFMT_EMULATOR" ]; then
skip "prepend_workdir_if_relative is altering the behaviour for args when run under emulation"
fi
execdirect sh -c './shebang-path.sh foo bar1 bar2'
assert_success
assert_output "./printargs ./shebang-path.sh foo bar1 bar2"
}
@test "shell-command-relative-nested" {
exec0 sh sh -c './shebang-path2.sh foo bar1 bar2'
assert_success
assert_output "./printargs foo bar1 bar2"
}