diff options
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/awk.tests | 14 | ||||
-rwxr-xr-x | testsuite/busybox.tests | 19 | ||||
-rwxr-xr-x | testsuite/diff.tests | 63 | ||||
-rwxr-xr-x | testsuite/env.tests | 71 | ||||
-rwxr-xr-x | testsuite/make.tests | 765 | ||||
-rwxr-xr-x | testsuite/runtest | 18 | ||||
-rwxr-xr-x | testsuite/sh.tests | 118 |
7 files changed, 1062 insertions, 6 deletions
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index be25f6696..af9ed5359 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -480,6 +480,20 @@ testing 'awk backslash+newline eaten with no trace' \ | |||
480 | "Hello world\n" \ | 480 | "Hello world\n" \ |
481 | '' '' | 481 | '' '' |
482 | 482 | ||
483 | optional PLATFORM_MINGW32 | ||
484 | testing 'awk match line ending' \ | ||
485 | "awk '/world$/'" \ | ||
486 | "world\n" \ | ||
487 | "" \ | ||
488 | "hello\r\nworld\r\n" | ||
489 | |||
490 | testing 'awk backslash+CRLF eaten with no trace' \ | ||
491 | "awk -f -" \ | ||
492 | "Hello world\n" \ | ||
493 | '' \ | ||
494 | 'BEGIN { printf "Hello\\\r\n world\\n" }\n' | ||
495 | SKIP= | ||
496 | |||
483 | # User-supplied bug (SEGV) example, was causing use-after-realloc | 497 | # User-supplied bug (SEGV) example, was causing use-after-realloc |
484 | testing 'awk assign while assign' \ | 498 | testing 'awk assign while assign' \ |
485 | "awk '\$5=\$\$5=\$0'; echo \$?" \ | 499 | "awk '\$5=\$\$5=\$0'; echo \$?" \ |
diff --git a/testsuite/busybox.tests b/testsuite/busybox.tests index beb17440c..2ce09b281 100755 --- a/testsuite/busybox.tests +++ b/testsuite/busybox.tests | |||
@@ -7,11 +7,22 @@ | |||
7 | . ./testing.sh | 7 | . ./testing.sh |
8 | test -f "$bindir/.config" && . "$bindir/.config" | 8 | test -f "$bindir/.config" && . "$bindir/.config" |
9 | 9 | ||
10 | ln -s `which busybox` unknown | 10 | if [ -f "$bindir/busybox.exe" ]; then |
11 | # Copy rather than link busybox.exe: we can only make hard | ||
12 | # links which can't be deleted because Windows sees the | ||
13 | # executable as running. | ||
14 | suffix=".exe" | ||
15 | lncmd="cp" | ||
16 | else | ||
17 | suffix="" | ||
18 | lncmd="ln -s" | ||
19 | fi | ||
20 | |||
21 | $lncmd "$(which busybox)" unknown$suffix | ||
11 | 22 | ||
12 | testing "busybox as unknown name" "./unknown 2>&1" \ | 23 | testing "busybox as unknown name" "./unknown 2>&1" \ |
13 | "unknown: applet not found\n" "" "" | 24 | "unknown: applet not found\n" "" "" |
14 | rm unknown | 25 | rm unknown$suffix |
15 | 26 | ||
16 | # We need busybox --help to be enabled for the rest of tests | 27 | # We need busybox --help to be enabled for the rest of tests |
17 | test x"$CONFIG_BUSYBOX" = x"y" \ | 28 | test x"$CONFIG_BUSYBOX" = x"y" \ |
@@ -23,7 +34,7 @@ optional FEATURE_VERBOSE_USAGE | |||
23 | testing "busybox --help busybox" "true | busybox --help busybox 2>&1 | cat" "$HELPDUMP\n" "" "" | 34 | testing "busybox --help busybox" "true | busybox --help busybox 2>&1 | cat" "$HELPDUMP\n" "" "" |
24 | SKIP= | 35 | SKIP= |
25 | 36 | ||
26 | ln -s `which busybox` busybox-suffix | 37 | $lncmd "$(which busybox)" busybox-suffix$suffix |
27 | for i in busybox ./busybox-suffix | 38 | for i in busybox ./busybox-suffix |
28 | do | 39 | do |
29 | testing "$i" "$i 2>&1 | cat" "$HELPDUMP\n" "" "" | 40 | testing "$i" "$i 2>&1 | cat" "$HELPDUMP\n" "" "" |
@@ -42,6 +53,6 @@ do | |||
42 | testing "$i --help unknown" "$i --help unknown 2>&1" \ | 53 | testing "$i --help unknown" "$i --help unknown 2>&1" \ |
43 | "unknown: applet not found\n" "" "" | 54 | "unknown: applet not found\n" "" "" |
44 | done | 55 | done |
45 | rm busybox-suffix | 56 | rm busybox-suffix$suffix |
46 | 57 | ||
47 | exit $FAILCOUNT | 58 | exit $FAILCOUNT |
diff --git a/testsuite/diff.tests b/testsuite/diff.tests index 0ced0f248..ee0567a80 100755 --- a/testsuite/diff.tests +++ b/testsuite/diff.tests | |||
@@ -123,6 +123,69 @@ testing "diff always takes context from old file" \ | |||
123 | "abc\na c\ndef\n" \ | 123 | "abc\na c\ndef\n" \ |
124 | "a c\n" | 124 | "a c\n" |
125 | 125 | ||
126 | optional PLATFORM_MINGW32 LONG_OPTS | ||
127 | testing "diff LF line endings" \ | ||
128 | 'diff -u - input' \ | ||
129 | "\ | ||
130 | --- - | ||
131 | +++ input | ||
132 | @@ -1,4 +1,4 @@ | ||
133 | a | ||
134 | b | ||
135 | +c | ||
136 | d | ||
137 | -e | ||
138 | " \ | ||
139 | "a\nb\nc\nd\n" \ | ||
140 | "a\nb\nd\ne\n" | ||
141 | |||
142 | testing "diff --binary LF line endings" \ | ||
143 | 'diff --binary -u - input' \ | ||
144 | "\ | ||
145 | --- - | ||
146 | +++ input | ||
147 | @@ -1,4 +1,4 @@ | ||
148 | a | ||
149 | b | ||
150 | +c | ||
151 | d | ||
152 | -e | ||
153 | " \ | ||
154 | "a\nb\nc\nd\n" \ | ||
155 | "a\nb\nd\ne\n" | ||
156 | |||
157 | testing "diff CRLF line endings" \ | ||
158 | 'diff -u - input' \ | ||
159 | "\ | ||
160 | --- - | ||
161 | +++ input | ||
162 | @@ -1,4 +1,4 @@ | ||
163 | a | ||
164 | b | ||
165 | +c | ||
166 | d | ||
167 | -e | ||
168 | " \ | ||
169 | "a\r\nb\r\nc\r\nd\r\n" \ | ||
170 | "a\r\nb\r\nd\r\ne\r\n" | ||
171 | |||
172 | testing "diff --binary CRLF line endings" \ | ||
173 | 'diff --binary -u - input' \ | ||
174 | "\ | ||
175 | --- - | ||
176 | +++ input | ||
177 | @@ -1,4 +1,4 @@ | ||
178 | a | ||
179 | b | ||
180 | +c | ||
181 | d | ||
182 | -e | ||
183 | " \ | ||
184 | "a\r\nb\r\nc\r\nd\r\n" \ | ||
185 | "a\r\nb\r\nd\r\ne\r\n" | ||
186 | |||
187 | SKIP= | ||
188 | |||
126 | # testing "test name" "commands" "expected result" "file input" "stdin" | 189 | # testing "test name" "commands" "expected result" "file input" "stdin" |
127 | 190 | ||
128 | # clean up | 191 | # clean up |
diff --git a/testsuite/env.tests b/testsuite/env.tests new file mode 100755 index 000000000..8b810e44b --- /dev/null +++ b/testsuite/env.tests | |||
@@ -0,0 +1,71 @@ | |||
1 | #!/bin/sh | ||
2 | # Copyright 2022 by Ron Yorston | ||
3 | # Licensed under GPLv2, see file LICENSE in this source tree. | ||
4 | |||
5 | . ./testing.sh | ||
6 | |||
7 | # testing "test name" "commands" "expected result" "file input" "stdin" | ||
8 | |||
9 | optional PLATFORM_MINGW32 | ||
10 | # Not so much a test of 'env' as of whether environment variables | ||
11 | # (or the lack thereof) are correctly passed to child processes. | ||
12 | testing "environment variables 1a" \ | ||
13 | "V=set env sh -c 'env | grep ^V='" \ | ||
14 | "V=set | ||
15 | " "" "" | ||
16 | |||
17 | testing "environment variables 1b" \ | ||
18 | "V= env sh -c 'env | grep ^V='" \ | ||
19 | "V= | ||
20 | " "" "" | ||
21 | |||
22 | testing "environment variables 1c" \ | ||
23 | "env sh -c 'env | grep ^V='" \ | ||
24 | "" "" "" | ||
25 | |||
26 | testing "environment variables 2a" \ | ||
27 | "V=set sh -c 'env | grep ^V='" \ | ||
28 | "V=set | ||
29 | " "" "" | ||
30 | |||
31 | testing "environment variables 2b" \ | ||
32 | "V= sh -c 'env | grep ^V='" \ | ||
33 | "V= | ||
34 | " "" "" | ||
35 | |||
36 | testing "environment variables 2c" \ | ||
37 | "sh -c 'env | grep ^V='" \ | ||
38 | "" "" "" | ||
39 | |||
40 | testing "environment variables 3a" \ | ||
41 | "V=set env sh -c 'echo \${V-unset}'" \ | ||
42 | "set | ||
43 | " "" "" | ||
44 | |||
45 | testing "environment variables 3b" \ | ||
46 | "V= env sh -c 'echo \${V-unset}'" \ | ||
47 | " | ||
48 | " "" "" | ||
49 | |||
50 | testing "environment variables 3c" \ | ||
51 | "env sh -c 'echo \${V-unset}'" \ | ||
52 | "unset | ||
53 | " "" "" | ||
54 | |||
55 | testing "environment variables 4a" \ | ||
56 | "V=set sh -c 'echo \${V-unset}'" \ | ||
57 | "set | ||
58 | " "" "" | ||
59 | |||
60 | testing "environment variables 4b" \ | ||
61 | "V= sh -c 'echo \${V-unset}'" \ | ||
62 | " | ||
63 | " "" "" | ||
64 | |||
65 | testing "environment variables 4c" \ | ||
66 | "sh -c 'echo \${V-unset}'" \ | ||
67 | "unset | ||
68 | " "" "" | ||
69 | SKIP= | ||
70 | |||
71 | exit $FAILCOUNT | ||
diff --git a/testsuite/make.tests b/testsuite/make.tests new file mode 100755 index 000000000..376bdcc15 --- /dev/null +++ b/testsuite/make.tests | |||
@@ -0,0 +1,765 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./testing.sh | ||
4 | unset MAKEFLAGS | ||
5 | rm -rf make.tempdir | ||
6 | |||
7 | # testing "test name" "command" "expected result" "file input" "stdin" | ||
8 | |||
9 | testing "make basic makefile" \ | ||
10 | "make -f -" "target\n" "" ' | ||
11 | target: | ||
12 | @echo target | ||
13 | ' | ||
14 | |||
15 | testing "make .DEFAULT rule for prerequisite" \ | ||
16 | "make -f - 2>/dev/null" "source\n" "" ' | ||
17 | .DEFAULT: | ||
18 | @echo $@ | ||
19 | target: source | ||
20 | ' | ||
21 | |||
22 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
23 | touch target.xyz | ||
24 | testing "make empty command overrides inference rule" \ | ||
25 | "make -f - target 2>/dev/null" "" "" ' | ||
26 | .SUFFIXES: .xyz | ||
27 | .xyz: | ||
28 | @echo xyz | ||
29 | target: ; | ||
30 | ' | ||
31 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
32 | |||
33 | # Macros should be expanded before suffix substitution. The suffixes | ||
34 | # can be obtained by macro expansion. | ||
35 | testing "make macro expansion and suffix substitution" \ | ||
36 | "make -f -" "src1.o src2.o\n" "" ' | ||
37 | DOTC = .c | ||
38 | DOTO = .o | ||
39 | SRC1 = src1.c | ||
40 | SRCS = $(SRC1) src2.c | ||
41 | target: | ||
42 | @echo $(SRCS:$(DOTC)=$(DOTO)) | ||
43 | ' | ||
44 | |||
45 | # Indeed, everything after the <colon> can be obtained by macro | ||
46 | # macro expansion. | ||
47 | testing "make macro expansion and suffix substitution 2" \ | ||
48 | "make -f -" "src1.o src2.o\n" "" ' | ||
49 | DOTS = .c=.o | ||
50 | SRC1 = src1.c | ||
51 | SRCS = $(SRC1) src2.c | ||
52 | target: | ||
53 | @echo $(SRCS:$(DOTS)) | ||
54 | ' | ||
55 | |||
56 | # It should be possible for an inference rule to determine that a | ||
57 | # prerequisite can be created using an explicit rule. | ||
58 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
59 | testing "make inference rule with explicit rule for prerequisite" \ | ||
60 | "make -f -" "touch x.p\ncat x.p >x.q\n" "" ' | ||
61 | .SUFFIXES: .p .q | ||
62 | x.q: | ||
63 | x.p: | ||
64 | touch $@ | ||
65 | .p.q: | ||
66 | cat $< >$@ | ||
67 | ' | ||
68 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
69 | |||
70 | # Austin Group defect report 875 clarifies certain aspects of the | ||
71 | # behaviour of inference rules. Study of this resulted in a number | ||
72 | # of changes to pdpmake, though this test passed anyway. | ||
73 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
74 | touch test.j test.k | ||
75 | testing "make proper handling of inference rules 1" \ | ||
76 | "make -f -" \ | ||
77 | ".j.l\n" "" ' | ||
78 | .SUFFIXES: .j .k .l | ||
79 | .j.l: | ||
80 | @echo .j.l | ||
81 | .k.l: | ||
82 | @echo .k.l | ||
83 | test.l: test.k | ||
84 | test.j: | ||
85 | test.k: | ||
86 | ' | ||
87 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
88 | |||
89 | # There was a bug where the failure of a build command didn't result | ||
90 | # in make returning a non-zero exit status. | ||
91 | testing "make return error if command fails" \ | ||
92 | "make -f - >/dev/null 2>&1; test \$? -gt 0 && echo OK" "OK\n" "" ' | ||
93 | target: | ||
94 | @exit 42 | ||
95 | ' | ||
96 | |||
97 | # An equal sign in a command on a target rule was detected as a | ||
98 | # macro assignment. | ||
99 | testing "make equal sign in inline command" \ | ||
100 | "make -f -" "a = a\n" "" ' | ||
101 | a = a | ||
102 | target:;@echo a = $(a) | ||
103 | ' | ||
104 | |||
105 | # Ensure an inline command on a target rule can be detected even if | ||
106 | # the semicolon is obfuscated. | ||
107 | testing "make equal sign in obfuscated inline command" \ | ||
108 | "make -f -" "a = a\n" "" ' | ||
109 | a = a | ||
110 | semi = ; | ||
111 | target:$(semi)@echo a = $(a) | ||
112 | ' | ||
113 | |||
114 | # When a build command fails and the '-k' option has been provided | ||
115 | # (continue execution on error) no further commands should be executed | ||
116 | # for the current target. | ||
117 | testing "make failure of build command with -k" \ | ||
118 | "make -k -f - 2>/dev/null" "OK\n" "" ' | ||
119 | all: bar baz | ||
120 | bar: | ||
121 | @echo OK | ||
122 | @false | ||
123 | @echo Not reached | ||
124 | baz: | ||
125 | @: | ||
126 | ' | ||
127 | # Build commands with a '+' prefix are executed even with the -q option. | ||
128 | testing "make execute build command with + prefix and -q" \ | ||
129 | "make -q -f - 2>/dev/null" "OK\n" "" ' | ||
130 | all: bar | ||
131 | bar: | ||
132 | @+echo OK | ||
133 | ' | ||
134 | |||
135 | # The -t option touches files that are out-of-date unless the target | ||
136 | # has no commands or they're already up-to-date. | ||
137 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
138 | touch baz | ||
139 | testing "make check -t option" \ | ||
140 | "make -t -f - 2>/dev/null" "touch bar\n" "" ' | ||
141 | all: foo bar baz | ||
142 | foo: | ||
143 | bar: | ||
144 | @echo bar | ||
145 | baz: | ||
146 | @echo baz | ||
147 | ' | ||
148 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
149 | |||
150 | # Build commands with a '+' prefix are executed even with the -t option. | ||
151 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
152 | testing "make execute build command with + prefix and -t" \ | ||
153 | "make -t -f - 2>/dev/null" "OK\n" "" ' | ||
154 | all: bar | ||
155 | bar: | ||
156 | @+echo OK | ||
157 | ' | ||
158 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
159 | |||
160 | # A macro created using ::= remembers it's of type immediate-expansion. | ||
161 | # Immediate expansion also occurs when += is used to append to such a macro. | ||
162 | testing "make appending to immediate-expansion macro" \ | ||
163 | "make -f -" \ | ||
164 | "hello 1 2 3\nhello 4 4\n" "" ' | ||
165 | world = 1 | ||
166 | hello ::= hello $(world) | ||
167 | world = 2 | ||
168 | hello += $(world) | ||
169 | world = 3 | ||
170 | hello += $(world) | ||
171 | world = 4 | ||
172 | |||
173 | world = 1 | ||
174 | reset ::= hello $(world) | ||
175 | world = 2 | ||
176 | # No longer immediate-expansion | ||
177 | reset = hello $(world) | ||
178 | world = 3 | ||
179 | reset += $(world) | ||
180 | world = 4 | ||
181 | |||
182 | target: | ||
183 | @echo $(hello) | ||
184 | @echo $(reset) | ||
185 | ' | ||
186 | |||
187 | # Since GNU make and bmake interpret := macro assignments differently, | ||
188 | # POSIX has ::= for the GNU variant and :::= for BSD. | ||
189 | testing "make different styles of := macro assignment" \ | ||
190 | "make -f -" \ | ||
191 | '65 a a $A\n' "" ' | ||
192 | A = a | ||
193 | GNU ::= $A | ||
194 | BSD1 :::= $A | ||
195 | BSD2 :::= $$A | ||
196 | A = 65 | ||
197 | |||
198 | target: | ||
199 | @echo '\''$(A) $(GNU) $(BSD1) $(BSD2)'\'' | ||
200 | ' | ||
201 | |||
202 | # Similar to the above but for macro assignments on the command line. | ||
203 | # POSIX has ::= for the GNU variant and :::= for BSD. | ||
204 | testing "make := macro assignment on command line" \ | ||
205 | "make -f - A=a 'GNU::=\$A' 'BSD1:::=\$A' 'BSD2:::=\$\$A' A=65" \ | ||
206 | '65 a a $A\n' "" ' | ||
207 | target: | ||
208 | @echo '\''$(A) $(GNU) $(BSD1) $(BSD2)'\'' | ||
209 | ' | ||
210 | |||
211 | # basic pattern macro expansion | ||
212 | testing "make basic pattern macro expansion" \ | ||
213 | "make -f -" \ | ||
214 | "obj/util.o obj/main.o\n" "" ' | ||
215 | SRC = src/util.c src/main.c | ||
216 | OBJ = $(SRC:src/%.c=obj/%.o) | ||
217 | |||
218 | target: | ||
219 | @echo $(OBJ) | ||
220 | ' | ||
221 | |||
222 | # pattern macro expansion; match any value | ||
223 | testing "make pattern macro expansion; match any value" \ | ||
224 | "make -f -" \ | ||
225 | "any_value.o\n" "" ' | ||
226 | SRC = any_value | ||
227 | OBJ = $(SRC:%=%.o) | ||
228 | |||
229 | target: | ||
230 | @echo $(OBJ) | ||
231 | ' | ||
232 | |||
233 | # pattern macro expansion with empty rvalue | ||
234 | testing "make pattern macro expansion with empty rvalue" \ | ||
235 | "make -f -" \ | ||
236 | "\n" "" ' | ||
237 | SRC = util.c main.c | ||
238 | OBJ = $(SRC:%.c=) | ||
239 | |||
240 | target: | ||
241 | @echo $(OBJ) | ||
242 | ' | ||
243 | |||
244 | # pattern macro expansion with multiple <percent> in rvalue | ||
245 | # POSIX requires the first <percent> to be expanded, others | ||
246 | # may or may not be expanded. Permit either case. | ||
247 | testing "make pattern macro expansion with multiple <percent> in rvalue" \ | ||
248 | "make -f - | sed 's/mainmainmain/main%%/'" \ | ||
249 | "main%%\n" "" ' | ||
250 | SRC = main.c | ||
251 | OBJ = $(SRC:%.c=%%%) | ||
252 | |||
253 | target: | ||
254 | @echo $(OBJ) | ||
255 | ' | ||
256 | |||
257 | # pattern macro expansion; zero match | ||
258 | testing "make pattern macro expansion; zero match" \ | ||
259 | "make -f -" \ | ||
260 | "nsnp\n" "" ' | ||
261 | WORD = osop | ||
262 | REPL = $(WORD:os%op=ns%np) | ||
263 | |||
264 | target: | ||
265 | @echo $(REPL) | ||
266 | ' | ||
267 | |||
268 | # Check that MAKE will contain argv[0], e.g make in this case | ||
269 | testing "make basic MAKE macro expansion" \ | ||
270 | "make -f -" \ | ||
271 | "make\n" "" ' | ||
272 | target: | ||
273 | @echo $(MAKE) | ||
274 | ' | ||
275 | |||
276 | # Check that MAKE defined as environment variable will overwrite default MAKE | ||
277 | testing "make MAKE macro expansion; overwrite with env macro" \ | ||
278 | "MAKE=hello make -f -" \ | ||
279 | "hello\n" "" ' | ||
280 | target: | ||
281 | @echo $(MAKE) | ||
282 | ' | ||
283 | |||
284 | # Check that MAKE defined on the command-line will overwrite MAKE defined in | ||
285 | # Makefile | ||
286 | testing "make MAKE macro expansion; overwrite with command-line macro" \ | ||
287 | "make -f - MAKE=hello" \ | ||
288 | "hello\n" "" ' | ||
289 | MAKE = test | ||
290 | |||
291 | target: | ||
292 | @echo $(MAKE) | ||
293 | ' | ||
294 | |||
295 | # POSIX draft states that if make was invoked using relative path, MAKE must | ||
296 | # contain absolute path, not just argv[0] | ||
297 | testing "make MAKE macro expansion; turn relative path into absolute" \ | ||
298 | "../runtest-tempdir-links/make -f -" \ | ||
299 | "ok\n" "" ' | ||
300 | target: | ||
301 | @test -e "$(MAKE)" && test "$(MAKE)" = "$$(env which make)" && echo ok | ||
302 | ' | ||
303 | |||
304 | # $? contains prerequisites newer than target, file2 in this case | ||
305 | # $^ has all prerequisites, file1 and file2 | ||
306 | touch -t 202206171200 file1 | ||
307 | touch -t 202206171201 target | ||
308 | touch -t 202206171202 file2 | ||
309 | testing "make compare \$? and \$^ internal macros" \ | ||
310 | "make -f -" \ | ||
311 | "file2\nfile1 file2\n" "" ' | ||
312 | target: file1 file2 | ||
313 | @echo $? | ||
314 | @echo $^ | ||
315 | ' | ||
316 | rm -f target file1 file2 | ||
317 | |||
318 | # Phony targets are executed (once) even if a matching file exists. | ||
319 | # A .PHONY target with no prerequisites is ignored. | ||
320 | touch -t 202206171201 target | ||
321 | testing "make phony target" \ | ||
322 | "make -f -" \ | ||
323 | "phony\n" "" ' | ||
324 | .PHONY: target | ||
325 | .PHONY: | ||
326 | target: | ||
327 | @echo phony | ||
328 | ' | ||
329 | rm -f target | ||
330 | |||
331 | # Phony targets aren't touched with -t | ||
332 | testing "make phony target not touched" \ | ||
333 | "make -t -f - >/dev/null && test -f target && echo target" \ | ||
334 | "" "" ' | ||
335 | .PHONY: target | ||
336 | target: | ||
337 | @: | ||
338 | ' | ||
339 | rm -f target | ||
340 | |||
341 | # Include files are created or brought up-to-date | ||
342 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
343 | testing "make create include file" \ | ||
344 | "make -f -" \ | ||
345 | "made\n" "" ' | ||
346 | target: | ||
347 | @echo $(VAR) | ||
348 | mk: | ||
349 | @echo "VAR = made" >mk | ||
350 | include mk | ||
351 | ' | ||
352 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
353 | |||
354 | # Include files are created or brought up-to-date even when the -n | ||
355 | # option is given. | ||
356 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
357 | testing "make create include file even with -n" \ | ||
358 | "make -n -f -" \ | ||
359 | "echo made\n" "" ' | ||
360 | target: | ||
361 | @echo $(VAR) | ||
362 | mk: | ||
363 | @echo "VAR = made" >mk | ||
364 | include mk | ||
365 | ' | ||
366 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
367 | |||
368 | # Failure to create an include file isn't an error. (Provided the | ||
369 | # include line is ignoring non-existent files.) | ||
370 | testing "make failure to create include file is OK" \ | ||
371 | "make -f -" \ | ||
372 | "OK\n" "" ' | ||
373 | target: | ||
374 | @echo OK | ||
375 | mk: | ||
376 | @: | ||
377 | -include mk | ||
378 | ' | ||
379 | |||
380 | # $^ skips duplicate prerequisites, $+ doesn't | ||
381 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
382 | touch file1 file2 file3 | ||
383 | testing "make skip duplicate entries in \$^ but not \$+" \ | ||
384 | "make -f -" \ | ||
385 | "file1 file2 file3\nfile1 file2 file2 file3 file3\n" "" ' | ||
386 | target: file1 file2 file2 file3 file3 | ||
387 | @echo $^ | ||
388 | @echo $+ | ||
389 | ' | ||
390 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
391 | |||
392 | # Assign the output of a shell command to a macro. | ||
393 | testing "make shell assignment" \ | ||
394 | "make -f -" \ | ||
395 | "1 2 3 4\n" "" ' | ||
396 | hello != echo 1; echo 2; echo 3; echo; echo | ||
397 | |||
398 | target: | ||
399 | @echo "$(hello) 4" | ||
400 | ' | ||
401 | |||
402 | # Nested macro expansion is allowed. This should be compatible | ||
403 | # with other implementations. | ||
404 | testing "make nested macro expansion" \ | ||
405 | "make -f -" "0 bc\n1 d\n2\n3\n4 bcd\n5 bcd\n" "" ' | ||
406 | a = b | ||
407 | b = c | ||
408 | c = d | ||
409 | $(a:.q=.v)$(b:.z=.v) = bc | ||
410 | bcd = bcd | ||
411 | target: | ||
412 | @echo 0 $(bc) | ||
413 | @echo 1 $($($(a))) | ||
414 | @echo 2 $($(a) $(b) $(c)) | ||
415 | @echo 3 $($a $b $c) | ||
416 | @echo 4 $($(a)$(b)$(c)) | ||
417 | @echo 5 $($a$b$c) | ||
418 | ' | ||
419 | |||
420 | # .WAIT is allowed as a prerequisite. Since parallel builds aren't | ||
421 | # implemented it doesn't have any effect. | ||
422 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
423 | touch file1 file2 | ||
424 | testing "make .WAIT is allowed as a prerequisite" \ | ||
425 | "make -f -" \ | ||
426 | "file1 file2\n" "" ' | ||
427 | target: file1 .WAIT file2 | ||
428 | @echo $? | ||
429 | ' | ||
430 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
431 | |||
432 | # Escaped newlines inside macro expansions in commands get different | ||
433 | # treatment than those outside. In POSIX 2017 the output is 'a b ab'. | ||
434 | testing "make replace escaped NL in macro in command with space" \ | ||
435 | "make -f -" \ | ||
436 | "a b a b\n" "" ' | ||
437 | M=word | ||
438 | N=${M:word=a\\ | ||
439 | b} | ||
440 | target: | ||
441 | @echo ${N} ${M:word=a\\ | ||
442 | b} | ||
443 | ' | ||
444 | |||
445 | # The CURDIR macro is supported in POSIX 2024. | ||
446 | testing "make CURDIR macro" \ | ||
447 | "make -f -" \ | ||
448 | "OK\n" "" ' | ||
449 | target: | ||
450 | @test "$(CURDIR)" = "$$(pwd -P)" && echo OK | ||
451 | ' | ||
452 | # The CURDIR environment variable doesn't affect the macro | ||
453 | export CURDIR=/you/are/here | ||
454 | testing "make CURDIR macro not affected by environment" \ | ||
455 | "make -f -" \ | ||
456 | "OK\n" "" ' | ||
457 | target: | ||
458 | @test "$(CURDIR)" != "/you/are/here" && echo OK | ||
459 | ' | ||
460 | |||
461 | # The -e option makes the CURDIR macro match the environment | ||
462 | testing "make with -e CURDIR macro is affected by the environment" \ | ||
463 | "make -e -f -" \ | ||
464 | "/you/are/here\n" "" ' | ||
465 | target: | ||
466 | @echo $(CURDIR) | ||
467 | ' | ||
468 | unset CURDIR | ||
469 | |||
470 | # The fix for an equal sign in an inline command on a target rule broke | ||
471 | # a complex chain of macro assignments generated by autotools. | ||
472 | testing "make complex chain of macro assignments" \ | ||
473 | "make -f -" "flag 1\n" "" ' | ||
474 | FLAG_ = $(FLAG_$(VALUE)) | ||
475 | FLAG_0 = flag 0 | ||
476 | FLAG_1 = flag 1 | ||
477 | MYFLAG = $(FLAG_$(VALUE)) | ||
478 | VALUE = 1 | ||
479 | |||
480 | target: | ||
481 | @echo $(MYFLAG) | ||
482 | ' | ||
483 | |||
484 | # POSIX 2024 permits additional characters in macro and target names | ||
485 | testing "make allow - and / in target names, - in macro names" \ | ||
486 | "make -f -" \ | ||
487 | "/hello\nhel-lo\nmac-ro\n" "" ' | ||
488 | target: ./hello hel-lo | ||
489 | @echo $(mac-ro) | ||
490 | ./hello: | ||
491 | @echo /hello | ||
492 | hel-lo: | ||
493 | @echo hel-lo | ||
494 | mac-ro = mac-ro | ||
495 | ' | ||
496 | |||
497 | testing "make double-colon rule" \ | ||
498 | "make -f -" "target1\ntarget2\n" "" ' | ||
499 | target:: | ||
500 | @echo target1 | ||
501 | target:: | ||
502 | @echo target2 | ||
503 | ' | ||
504 | |||
505 | # There was a bug whereby the modification time of a file created by | ||
506 | # double-colon rules wasn't correctly updated. This test checks that | ||
507 | # the bug is now fixed. | ||
508 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
509 | touch -t 202206171200 file1 | ||
510 | touch -t 202206171201 intermediate | ||
511 | touch -t 202206171202 target | ||
512 | touch -t 202206171203 file2 | ||
513 | testing "make target depends on prerequisite updated by double-colon rule" \ | ||
514 | "make -f -" \ | ||
515 | "file2\n" "" ' | ||
516 | target: intermediate | ||
517 | @cat intermediate | ||
518 | intermediate:: file1 | ||
519 | @echo file1 >>intermediate | ||
520 | intermediate:: file2 | ||
521 | @echo file2 >>intermediate | ||
522 | ' | ||
523 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
524 | |||
525 | # Use chained inference rules to determine prerequisites. | ||
526 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
527 | touch target.p | ||
528 | testing "make chained inference rules" \ | ||
529 | "make -s -f - target.s" \ | ||
530 | "target.q\ntarget.r\ntarget.s\n" "" ' | ||
531 | .SUFFIXES: .p .q .r .s | ||
532 | .p.q: | ||
533 | @cp $< $*.q | ||
534 | @echo $*.q | ||
535 | .q.r: | ||
536 | @cp $< $*.r | ||
537 | @echo $*.r | ||
538 | .r.s: | ||
539 | @cp $< $*.s | ||
540 | @echo $*.s | ||
541 | ' | ||
542 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
543 | |||
544 | # make supports *, ? and [] wildcards in targets and prerequisites | ||
545 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
546 | touch -t 202206171201 t1a t2aa t3b | ||
547 | touch s1a s2aa s3b | ||
548 | testing "make expand wildcards in filenames" \ | ||
549 | "make -f - t1a t2aa t3b" \ | ||
550 | "t1a s1a s2aa s3b\nt2aa s1a s2aa s3b\nt3b s1a s2aa s3b\n" "" ' | ||
551 | t1? t2* t3[abc]: s1? s2* s3[abc] | ||
552 | @echo $@ $? | ||
553 | ' | ||
554 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
555 | |||
556 | # A '#' character in a macro expansion doesn't start a comment | ||
557 | testing "make hash in macro expansion isn't a comment" \ | ||
558 | "make -f -" \ | ||
559 | ": hash # hash\n" "" ' | ||
560 | HASH = hash | ||
561 | hash = $(HASH:hash=#) | ||
562 | target: | ||
563 | : hash $(hash) hash | ||
564 | ' | ||
565 | |||
566 | # A '#' character can be escaped with a backslash | ||
567 | testing "make backslash-escaped hash isn't a comment" \ | ||
568 | "make -f -" \ | ||
569 | ": hash # hash\n" "" ' | ||
570 | hash = \\# | ||
571 | target: | ||
572 | : hash $(hash) hash | ||
573 | ' | ||
574 | |||
575 | # A '#' character in a command line doesn't start a comment | ||
576 | testing "make hash in command line isn't a comment" \ | ||
577 | "make -f -" \ | ||
578 | ": hash # hash\n" "" ' | ||
579 | target: | ||
580 | : hash # hash | ||
581 | ' | ||
582 | |||
583 | # Austin Group defect report 875 (mentioned above) actually used | ||
584 | # suffixes '.a .b .c'. This doesn't matter in POSIX mode but it | ||
585 | # caused a failure (now fixed) when chained inference rules were | ||
586 | # allowed. The '.a.c' and the built-in '.c.a' inference rules | ||
587 | # resulted in a loop. | ||
588 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
589 | touch test.a test.b | ||
590 | testing "make proper handling of inference rules 2" \ | ||
591 | "make -f -" \ | ||
592 | ".a.c\n" "" ' | ||
593 | .SUFFIXES: .a .b .c | ||
594 | .a.c: | ||
595 | @echo .a.c | ||
596 | .b.c: | ||
597 | @echo .b.c | ||
598 | test.c: test.b | ||
599 | test.a: | ||
600 | test.b: | ||
601 | ' | ||
602 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
603 | |||
604 | # Don't use the shell -e option when running commands. | ||
605 | testing "make no shell -e option when running commands" \ | ||
606 | "make -f -" "OK\n" "" ' | ||
607 | target: | ||
608 | @false; echo OK | ||
609 | ' | ||
610 | |||
611 | # Macros and targets may be mixed on the command line | ||
612 | testing "make allow mixed macros and targets" \ | ||
613 | "make -f - FOO=foo foo BAR=bar bar" "foo\nbar\nfoo\nbar\n" "" ' | ||
614 | foo: | ||
615 | @echo $(FOO) | ||
616 | @echo $(BAR) | ||
617 | bar: | ||
618 | @echo $(FOO) | ||
619 | @echo $(BAR) | ||
620 | ' | ||
621 | |||
622 | # $* and $< are supported for target rules | ||
623 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
624 | touch src.c src.h | ||
625 | testing 'make support $* and $< for target rules' \ | ||
626 | "make -f -" "src.c src.h\nsrc.o\nsrc\nsrc.c\n" "" ' | ||
627 | src.o: src.c src.h | ||
628 | @echo "$?" | ||
629 | @echo "$@" | ||
630 | @echo "$*" | ||
631 | @echo "$<" | ||
632 | ' | ||
633 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
634 | |||
635 | # ifeq/ifneq conditionals are supported | ||
636 | testing 'make support ifeq and ifneq conditionals' \ | ||
637 | "make -f -" "A OK\nB OK\n" "" ' | ||
638 | A = a | ||
639 | B = b | ||
640 | target: | ||
641 | ifeq ($(A),a) | ||
642 | @echo A OK | ||
643 | else | ||
644 | @echo A not OK | ||
645 | endif | ||
646 | ifneq "a" "$B" | ||
647 | @echo B OK | ||
648 | endif | ||
649 | ' | ||
650 | |||
651 | # An empty original suffix indicates that every word should have | ||
652 | # the new suffix added. If neither suffix is provided the words | ||
653 | # remain unchanged. | ||
654 | testing "make macro expansion and suffix substitution 3" \ | ||
655 | "make -f -" "src1.c src2.c\nsrc1 src2\n" "" ' | ||
656 | SRCS = src1 src2 | ||
657 | target: | ||
658 | @echo $(SRCS:=.c) | ||
659 | @echo $(SRCS:=) | ||
660 | ' | ||
661 | |||
662 | # Skip duplicate entries in $? and $^ | ||
663 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
664 | touch -t 202206171200 file1 file3 | ||
665 | touch -t 202206171201 target | ||
666 | touch -t 202206171202 file2 | ||
667 | testing "make skip duplicate entries in \$? and \$^" \ | ||
668 | "make -f -" \ | ||
669 | "file2\nfile1 file2 file3\n" "" ' | ||
670 | target: file1 file2 file2 file3 file3 | ||
671 | @echo $? | ||
672 | @echo $^ | ||
673 | ' | ||
674 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
675 | |||
676 | # Skip duplicate entries in $? and $^, with each double-colon rule | ||
677 | # handled separately | ||
678 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
679 | touch -t 202206171200 file1 file3 | ||
680 | touch -t 202206171201 target | ||
681 | touch -t 202206171202 file2 | ||
682 | testing "make skip duplicate entries: double-colon rules" \ | ||
683 | "make -f -" \ | ||
684 | "file2\nfile1 file3 file2\nfile2\nfile2 file3\n" "" ' | ||
685 | target:: file1 file3 file1 file2 file3 | ||
686 | @echo $? | ||
687 | @echo $^ | ||
688 | target:: file2 file3 file3 | ||
689 | @echo $? | ||
690 | @echo $^ | ||
691 | ' | ||
692 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
693 | |||
694 | # Skip duplicate entries in $? and $^, with each double-colon rule | ||
695 | # handled separately. No prerequisites out-of-date in the first. | ||
696 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
697 | touch -t 202206171200 file1 file3 | ||
698 | touch -t 202206171201 target | ||
699 | touch -t 202206171202 file2 | ||
700 | testing "make skip duplicate entries: double-colon rules, only second invoked" \ | ||
701 | "make -f -" \ | ||
702 | "file2\nfile2 file3\n" "" ' | ||
703 | target:: file1 file3 file1 file3 | ||
704 | @echo $? | ||
705 | @echo $^ | ||
706 | target:: file2 file3 file3 | ||
707 | @echo $? | ||
708 | @echo $^ | ||
709 | ' | ||
710 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
711 | |||
712 | # .DEFAULT rules with no commands or some prerequisites are ignored. | ||
713 | # .DEFAULT rules with commands can be redefined. | ||
714 | testing "make: .DEFAULT rule" \ | ||
715 | "make -f - default" "default2\n" "" ' | ||
716 | .DEFAULT: ignored | ||
717 | .DEFAULT: | ||
718 | @echo default1 | ||
719 | .DEFAULT: | ||
720 | @echo default2 | ||
721 | target: | ||
722 | ' | ||
723 | |||
724 | testing "make: double-colon rule" \ | ||
725 | "make -f -" "target1\ntarget2\n" "" ' | ||
726 | target:: | ||
727 | @echo target1 | ||
728 | target:: | ||
729 | @echo target2 | ||
730 | ' | ||
731 | |||
732 | # Double-colon rules didn't work properly if their target was phony: | ||
733 | # - they didn't ignore the presence of a file matching the target name; | ||
734 | # - they were also invoked as if they were a single-colon rule. | ||
735 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
736 | touch -t 202206171200 file1 | ||
737 | touch -t 202206171201 target | ||
738 | testing "make phony target of double-colon rule" \ | ||
739 | "make -f - 2>&1" \ | ||
740 | "unconditional\nconditional\n" "" ' | ||
741 | .PHONY: target | ||
742 | target:: | ||
743 | @echo unconditional | ||
744 | target:: file1 | ||
745 | @echo conditional | ||
746 | file1: | ||
747 | @touch file1 | ||
748 | ' | ||
749 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
750 | |||
751 | # GNU make and BSD make don't allow the use of inference rules | ||
752 | # for phony targets. In POSIX mode the output is "phony.xyz\n". | ||
753 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
754 | touch phony.xyz | ||
755 | testing "make don't use inference rule for phony target" \ | ||
756 | "make -f -" "make: nothing to be done for phony\n" "" ' | ||
757 | .PHONY: phony | ||
758 | .SUFFIXES: .xyz | ||
759 | .xyz: | ||
760 | @echo $< | ||
761 | phony: | ||
762 | ' | ||
763 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
764 | |||
765 | exit $FAILCOUNT | ||
diff --git a/testsuite/runtest b/testsuite/runtest index 44f9cd1a1..adbcb1178 100755 --- a/testsuite/runtest +++ b/testsuite/runtest | |||
@@ -99,6 +99,20 @@ if [ x"$1" = x"-v" ]; then | |||
99 | shift | 99 | shift |
100 | fi | 100 | fi |
101 | 101 | ||
102 | if [ -f "$bindir/busybox.exe" ]; then | ||
103 | suffix=".exe" | ||
104 | lnflag="" | ||
105 | |||
106 | # Some tests require /bin/echo and /bin/true exist | ||
107 | test ! -d /tmp && mkdir /tmp | ||
108 | test ! -d /bin && mkdir /bin | ||
109 | test ! -f /bin/echo.exe && cp "$bindir/busybox.exe" /bin/echo.exe | ||
110 | test ! -f /bin/true.exe && cp "$bindir/busybox.exe" /bin/true.exe | ||
111 | else | ||
112 | suffix="" | ||
113 | lnflag="-s" | ||
114 | fi | ||
115 | |||
102 | implemented=$( | 116 | implemented=$( |
103 | printf "busybox " # always implemented | 117 | printf "busybox " # always implemented |
104 | "$bindir/busybox" 2>&1 | | 118 | "$bindir/busybox" 2>&1 | |
@@ -128,7 +142,7 @@ for i in $implemented; do | |||
128 | # Note: if $LINKSDIR/applet exists, we do not overwrite it. | 142 | # Note: if $LINKSDIR/applet exists, we do not overwrite it. |
129 | # Useful if one wants to run tests against a standard utility, | 143 | # Useful if one wants to run tests against a standard utility, |
130 | # not an applet. | 144 | # not an applet. |
131 | ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null | 145 | ln $lnflag "$bindir/busybox$suffix" "$LINKSDIR/$i$suffix" 2>/dev/null |
132 | done | 146 | done |
133 | 147 | ||
134 | # Set up option flags so tests can be selective. | 148 | # Set up option flags so tests can be selective. |
@@ -146,7 +160,7 @@ for applet in $applets; do | |||
146 | 160 | ||
147 | # Is this a new-style test? | 161 | # Is this a new-style test? |
148 | if [ -f "$applet.tests" ]; then | 162 | if [ -f "$applet.tests" ]; then |
149 | if [ ! -e "$LINKSDIR/$applet" ]; then | 163 | if [ ! -e "$LINKSDIR/$applet$suffix" ]; then |
150 | # (avoiding bash'ism "${applet:0:4}") | 164 | # (avoiding bash'ism "${applet:0:4}") |
151 | if ! echo "$applet" | grep "^all_" >/dev/null; then | 165 | if ! echo "$applet" | grep "^all_" >/dev/null; then |
152 | echo "SKIPPED: $applet (not built)" | 166 | echo "SKIPPED: $applet (not built)" |
diff --git a/testsuite/sh.tests b/testsuite/sh.tests new file mode 100755 index 000000000..0eccf20bc --- /dev/null +++ b/testsuite/sh.tests | |||
@@ -0,0 +1,118 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Test sh scripts | ||
4 | # | ||
5 | # Copyright 2019 by STMicroelectronics | ||
6 | # Licensed under GPLv2, see file LICENSE in this source tree. | ||
7 | |||
8 | . ./testing.sh | ||
9 | |||
10 | test -f "$bindir/.config" && . "$bindir/.config" | ||
11 | |||
12 | # testing "test name" "options" "expected result" "file input" "stdin" | ||
13 | |||
14 | optional PLATFORM_MINGW32 | ||
15 | # Test case | ||
16 | testing "shebang" \ | ||
17 | "uudecode; sh -c './shebang.sh'; echo \$?" \ | ||
18 | "Hello world | ||
19 | 0 | ||
20 | " \ | ||
21 | "" "\ | ||
22 | begin-base64 755 shebang.sh | ||
23 | IyEvYmluL3NoCmVjaG8gIkhlbGxvIHdvcmxkIgo= | ||
24 | ==== | ||
25 | " | ||
26 | rm -f shebang.sh | ||
27 | |||
28 | # Test case | ||
29 | testing "shebang with whitespace" \ | ||
30 | "uudecode; sh -c './shebang_trailing_space.sh'; echo \$?" \ | ||
31 | "Hello world | ||
32 | 0 | ||
33 | " \ | ||
34 | "" "\ | ||
35 | begin-base64 755 shebang_trailing_space.sh | ||
36 | IyEvYmluL3NoIAplY2hvICJIZWxsbyB3b3JsZCIK | ||
37 | ==== | ||
38 | " | ||
39 | rm -f shebang_trailing_space.sh | ||
40 | |||
41 | # Test case | ||
42 | testing "shebang with argument" \ | ||
43 | "uudecode; sh -c './shebang_argument.sh'; echo \$?" \ | ||
44 | "Hello world | ||
45 | 0 | ||
46 | " \ | ||
47 | "" "\ | ||
48 | begin-base64 755 shebang_argument.sh | ||
49 | IyEvYmluL3NoIC0KZWNobyAiSGVsbG8gd29ybGQiCg== | ||
50 | ==== | ||
51 | " | ||
52 | rm -f shebang_argument.sh | ||
53 | |||
54 | # Test case | ||
55 | testing "shebang with leading whitespace and argument" \ | ||
56 | "uudecode; sh -c './shebang_leading_space_argument.sh'; echo \$?" \ | ||
57 | "Hello world | ||
58 | 0 | ||
59 | " \ | ||
60 | "" "\ | ||
61 | begin-base64 755 shebang_leading_space_argument.sh | ||
62 | IyEvYmluL3NoICAtCmVjaG8gIkhlbGxvIHdvcmxkIgo= | ||
63 | ==== | ||
64 | " | ||
65 | rm -f shebang_leading_space_argument.sh | ||
66 | |||
67 | # Test case | ||
68 | testing "shebang with argument and trailing whitespace" \ | ||
69 | "uudecode; sh -c './shebang_argument_trailing_space.sh'; echo \$?" \ | ||
70 | "Hello world | ||
71 | 0 | ||
72 | " \ | ||
73 | "" "\ | ||
74 | begin-base64 755 shebang_argument_trailing_space.sh | ||
75 | IyEvYmluL3NoIC0gCmVjaG8gIkhlbGxvIHdvcmxkIgo= | ||
76 | ==== | ||
77 | " | ||
78 | rm -f shebang_argument_trailing_space.sh | ||
79 | |||
80 | # Test case | ||
81 | testing "shebang with leading whitespace, argument and trailing whitespace" \ | ||
82 | "uudecode; sh -c './shebang_leading_argument_trailing_space.sh'; echo \$?" \ | ||
83 | "Hello world | ||
84 | 0 | ||
85 | " \ | ||
86 | "" "\ | ||
87 | begin-base64 755 shebang_leading_argument_trailing_space.sh | ||
88 | IyEvYmluL3NoICAtIAplY2hvICJIZWxsbyB3b3JsZCIK | ||
89 | ==== | ||
90 | " | ||
91 | rm -f shebang_leading_argument_trailing_space.sh | ||
92 | |||
93 | testing "sh remove CRs from string being evaluated" \ | ||
94 | "sh -c \"$(printf 'set -e\r\necho Hello world\r\n')\"" \ | ||
95 | "Hello world\n" "" "" | ||
96 | |||
97 | testing "sh preserve lone CRs during field splitting" \ | ||
98 | "sh input" \ | ||
99 | "Hello\r world\n" "echo \$(printf \"Hello\\\\r\\\\r\\\\nworld\\\\r\\\\n\")" "" | ||
100 | |||
101 | testing "sh read with CRLF" \ | ||
102 | "printf '1 2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \ | ||
103 | "1 2\n" "" "" | ||
104 | |||
105 | testing "sh read with CR" \ | ||
106 | "printf '1\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \ | ||
107 | "1\r2\n" "" "" | ||
108 | |||
109 | testing "sh read with \\CRLF" \ | ||
110 | "printf '1\\\\\r\\n2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \ | ||
111 | "12\n" "" "" | ||
112 | |||
113 | testing "sh read with \\CR" \ | ||
114 | "printf '1\\\\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \ | ||
115 | "1\r2\n" "" "" | ||
116 | SKIP= | ||
117 | |||
118 | exit $FAILCOUNT | ||