aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtestsuite/awk.tests14
-rwxr-xr-xtestsuite/busybox.tests19
-rwxr-xr-xtestsuite/cpio.tests23
-rwxr-xr-xtestsuite/cryptpw.tests98
-rwxr-xr-xtestsuite/diff.tests63
-rwxr-xr-xtestsuite/env.tests71
-rwxr-xr-xtestsuite/hexdump.tests91
-rwxr-xr-xtestsuite/make.tests805
-rwxr-xr-xtestsuite/od.tests13
-rwxr-xr-xtestsuite/runtest18
-rwxr-xr-xtestsuite/sh.tests118
-rw-r--r--testsuite/wget/wget-handles-https4
12 files changed, 1295 insertions, 42 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
483optional PLATFORM_MINGW32
484testing 'awk match line ending' \
485 "awk '/world$/'" \
486 "world\n" \
487 "" \
488 "hello\r\nworld\r\n"
489
490testing 'awk backslash+CRLF eaten with no trace' \
491 "awk -f -" \
492 "Hello world\n" \
493 '' \
494 'BEGIN { printf "Hello\\\r\n world\\n" }\n'
495SKIP=
496
483# User-supplied bug (SEGV) example, was causing use-after-realloc 497# User-supplied bug (SEGV) example, was causing use-after-realloc
484testing 'awk assign while assign' \ 498testing '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
8test -f "$bindir/.config" && . "$bindir/.config" 8test -f "$bindir/.config" && . "$bindir/.config"
9 9
10ln -s `which busybox` unknown 10if [ -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"
16else
17 suffix=""
18 lncmd="ln -s"
19fi
20
21$lncmd "$(which busybox)" unknown$suffix
11 22
12testing "busybox as unknown name" "./unknown 2>&1" \ 23testing "busybox as unknown name" "./unknown 2>&1" \
13 "unknown: applet not found\n" "" "" 24 "unknown: applet not found\n" "" ""
14rm unknown 25rm 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
17test x"$CONFIG_BUSYBOX" = x"y" \ 28test x"$CONFIG_BUSYBOX" = x"y" \
@@ -23,7 +34,7 @@ optional FEATURE_VERBOSE_USAGE
23testing "busybox --help busybox" "true | busybox --help busybox 2>&1 | cat" "$HELPDUMP\n" "" "" 34testing "busybox --help busybox" "true | busybox --help busybox 2>&1 | cat" "$HELPDUMP\n" "" ""
24SKIP= 35SKIP=
25 36
26ln -s `which busybox` busybox-suffix 37$lncmd "$(which busybox)" busybox-suffix$suffix
27for i in busybox ./busybox-suffix 38for i in busybox ./busybox-suffix
28do 39do
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" "" ""
44done 55done
45rm busybox-suffix 56rm busybox-suffix$suffix
46 57
47exit $FAILCOUNT 58exit $FAILCOUNT
diff --git a/testsuite/cpio.tests b/testsuite/cpio.tests
index 85e746589..a4462c53e 100755
--- a/testsuite/cpio.tests
+++ b/testsuite/cpio.tests
@@ -154,6 +154,29 @@ testing "cpio -R with extract" \
154" "" "" 154" "" ""
155SKIP= 155SKIP=
156 156
157# Create an archive containing a file with "../dont_write" filename.
158# See that it will not be allowed to unpack.
159# NB: GNU cpio 2.15 DOES NOT do such checks.
160optional FEATURE_PATH_TRAVERSAL_PROTECTION
161rm -rf cpio.testdir
162mkdir -p cpio.testdir/prepare/inner
163echo "file outside of destination was written" > cpio.testdir/prepare/dont_write
164echo "data" > cpio.testdir/prepare/inner/to_extract
165mkdir -p cpio.testdir/extract
166testing "cpio extract file outside of destination" "\
167(cd cpio.testdir/prepare/inner && echo -e '../dont_write\nto_extract' | cpio -o -H newc) | (cd cpio.testdir/extract && cpio -vi 2>&1)
168echo \$?
169ls cpio.testdir/dont_write 2>&1" \
170"\
171cpio: removing leading '../' from member names
172../dont_write
173to_extract
1741 blocks
1750
176ls: cpio.testdir/dont_write: No such file or directory
177" "" ""
178SKIP=
179
157# Clean up 180# Clean up
158rm -rf cpio.testdir cpio.testdir2 2>/dev/null 181rm -rf cpio.testdir cpio.testdir2 2>/dev/null
159 182
diff --git a/testsuite/cryptpw.tests b/testsuite/cryptpw.tests
index 0dd91fe15..83bfde521 100755
--- a/testsuite/cryptpw.tests
+++ b/testsuite/cryptpw.tests
@@ -22,21 +22,93 @@ testing "cryptpw des zz" \
22#SKIP= 22#SKIP=
23 23
24optional USE_BB_CRYPT_SHA 24optional USE_BB_CRYPT_SHA
25testing "cryptpw sha256" \ 25# Note: mkpasswd-5.6.2 won't accept "-m sha256", wants "-m sha256crypt"
26 "cryptpw -m sha256 QWErty '123456789012345678901234567890'" \ 26testing 'cryptpw sha256' \
27 '$5$1234567890123456$5DxfOCmU4vRhtzfsbdK.6wSGMwwVbac7ZkWwusb8Si7\n' "" "" 27 'cryptpw -m sha256 QWErty 1234567890123456' \
28 '$5$1234567890123456$5DxfOCmU4vRhtzfsbdK.6wSGMwwVbac7ZkWwusb8Si7\n' \
29 '' ''
30# mkpasswd-5.6.2 does not allow overlong salts, we truncate (at 16 chars for sha256)
31testing 'cryptpw sha256 overlong' \
32 'cryptpw -m sha256 QWErty 123456789012345678901234567890' \
33 '$5$1234567890123456$5DxfOCmU4vRhtzfsbdK.6wSGMwwVbac7ZkWwusb8Si7\n' \
34 '' ''
35testing 'cryptpw sha256 implicit' \
36 'cryptpw QWErty \$5\$1234567890123456' \
37 '$5$1234567890123456$5DxfOCmU4vRhtzfsbdK.6wSGMwwVbac7ZkWwusb8Si7\n' \
38 '' ''
39testing 'cryptpw sha256 rounds=99999' \
40 'cryptpw -m sha256 QWErty rounds=99999\$123456789012345678901234567890' \
41 '$5$rounds=99999$1234567890123456$aYellycJGZM6AKyVzaQsSrDBdTixubtMnM6J.MN0xM8\n' \
42 '' ''
43testing 'cryptpw sha256 rounds=99999 implicit' \
44 'cryptpw QWErty \$5\$rounds=99999\$123456789012345678901234567890' \
45 '$5$rounds=99999$1234567890123456$aYellycJGZM6AKyVzaQsSrDBdTixubtMnM6J.MN0xM8\n' \
46 '' ''
28 47
29testing "cryptpw sha256 rounds=99999" \ 48testing 'cryptpw sha512' \
30 "cryptpw -m sha256 QWErty 'rounds=99999\$123456789012345678901234567890'" \ 49 'cryptpw -m sha512 QWErty 123456789012345678901234567890' \
31 '$5$rounds=99999$1234567890123456$aYellycJGZM6AKyVzaQsSrDBdTixubtMnM6J.MN0xM8\n' "" "" 50 '$6$1234567890123456$KB7QqxFyqmJSWyQYcCuGeFukgz1bPQoipWZf7.9L7z3k8UNTXa6UikbKcUGDc2ANn7DOGmDaroxDgpK16w/RE0\n' \
32 51 '' ''
33testing "cryptpw sha512" \ 52testing 'cryptpw sha512crypt' \
34 "cryptpw -m sha512 QWErty '123456789012345678901234567890'" \ 53 'cryptpw -m sha512crypt QWErty 123456789012345678901234567890' \
35 '$6$1234567890123456$KB7QqxFyqmJSWyQYcCuGeFukgz1bPQoipWZf7.9L7z3k8UNTXa6UikbKcUGDc2ANn7DOGmDaroxDgpK16w/RE0\n' "" "" 54 '$6$1234567890123456$KB7QqxFyqmJSWyQYcCuGeFukgz1bPQoipWZf7.9L7z3k8UNTXa6UikbKcUGDc2ANn7DOGmDaroxDgpK16w/RE0\n' \
55 '' ''
56testing 'cryptpw sha512 rounds=99999' \
57 'cryptpw -m sha512 QWErty rounds=99999\$123456789012345678901234567890' \
58 '$6$rounds=99999$1234567890123456$BfF6gD6ZjUmwawH5QaAglYAxtU./yvsz0fcQ464l49aMI2DZW3j5ri28CrxK7riPWNpLuUpfaIdY751SBYKUH.\n' \
59 '' ''
60SKIP=
36 61
37testing "cryptpw sha512 rounds=99999" \ 62optional USE_BB_CRYPT_YES
38 "cryptpw -m sha512 QWErty 'rounds=99999\$123456789012345678901234567890'" \ 63testing 'cryptpw yescrypt' \
39 '$6$rounds=99999$1234567890123456$BfF6gD6ZjUmwawH5QaAglYAxtU./yvsz0fcQ464l49aMI2DZW3j5ri28CrxK7riPWNpLuUpfaIdY751SBYKUH.\n' "" "" 64 'cryptpw -m yescrypt qweRTY123@-+ j9T\$123456789012345678901234' \
65 '$y$j9T$123456789012345678901234$AKxw5OX/T4jD.v./IW.5tE/j7izNjw06fg3OvH1LsN9\n' \
66 '' ''
67testing 'cryptpw yescrypt with non-standard N=2048 instead of 4096 (j8T instead of j9T)' \
68 'cryptpw -m yescrypt qweRTY123@-+ j8T\$123456789012345678901234' \
69 '$y$j8T$123456789012345678901234$JQUUfopCxlfZNE8f.THJwbOkhy.XtB3GIjo9HUVioWB\n' \
70 '' ''
71# mkpasswd-5.6.2 allows short salts for yescrypt
72# ...but there is a catch. Not all of them.
73# The "partial" (not fitting in whole bytes) ascii64-encoded salt
74# is a special case. For example, "$zzz" would not even work in upstream.
75testing 'cryptpw yescrypt with empty salt' \
76 'cryptpw -m yescrypt qweRTY123@-+ j9T\$' \
77 '$y$j9T$$hpeksL94GXNRwnA00L3c8WFy0khFAUbCpBSak.N3Bp.\n' \
78 '' ''
79testing 'cryptpw yescrypt with 3-char salt' \
80 'cryptpw -m yescrypt qweRTY123@-+ j9T\$123' \
81 '$y$j9T$123$A34DMIGUbUIo3bjx66Wtk2IFoREMIw6d49it25KQh2D\n' \
82 '' ''
83# "." is not allowed in mkpasswd-5.6.2
84# ....................................
85# ".." is decoded into one zero byte (not two)
86testing 'cryptpw yescrypt with 2-char salt ".."' \
87 'cryptpw -m yescrypt qweRTY123@-+ j9T\$..' \
88 '$y$j9T$..$yVHeOayxOGg6cHL3.dg10u7T.qSgySfLN3uhSVSLNn/\n' \
89 '' ''
90# "..." is decoded into two zero bytes (not three, not one)
91testing 'cryptpw yescrypt with 3-char salt "..."' \
92 'cryptpw -m yescrypt qweRTY123@-+ j9T\$...' \
93 '$y$j9T$...$xHvJ5USZ7hFyXYbOijtEOMfZRS23cWIxu2eIBXRymA5\n' \
94 '' ''
95# "...." is decoded into three zero bytes (no surprises here)
96testing 'cryptpw yescrypt with 4-char salt "...."' \
97 'cryptpw -m yescrypt qweRTY123@-+ j9T\$....' \
98 '$y$j9T$....$wOnauYL2/NEtr6YQi9pi8AtV7L57sEbVOAnWJIcP9q2\n' \
99 '' ''
100# 84 chars = 21 4-char blocks which decode into 21*3 = 63 bytes.
101# The last byte of the maximum allowed salt size has to come from an incomplete
102# char block. E.g. "z/" encodes byte 0x7f. "z1" is 0xff.
103# Anything larger (e.g. "z2") is an error (it encodes 0x13f).
104testing 'cryptpw yescrypt with 86-char salt (max size)' \
105 'cryptpw -m yescrypt qweRTY123@-+ j9T\$123456789012345678901234567890123456789012345678901234567890123456789012345678901234z/' \
106 '$y$j9T$123456789012345678901234567890123456789012345678901234567890123456789012345678901234z/$Exxe8IoPXiddFsqj7iqCanRf8FyquAoB0/uceLmLjG.\n' \
107 '' ''
108testing 'cryptpw yescrypt implicit' \
109 'cryptpw qweRTY123@-+ \$y\$j9T\$123456789012345678901234' \
110 '$y$j9T$123456789012345678901234$AKxw5OX/T4jD.v./IW.5tE/j7izNjw06fg3OvH1LsN9\n' \
111 '' ''
40SKIP= 112SKIP=
41 113
42exit $FAILCOUNT 114exit $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
126optional PLATFORM_MINGW32 LONG_OPTS
127testing "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
142testing "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
157testing "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
172testing "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
187SKIP=
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
9optional 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.
12testing "environment variables 1a" \
13 "V=set env sh -c 'env | grep ^V='" \
14 "V=set
15" "" ""
16
17testing "environment variables 1b" \
18 "V= env sh -c 'env | grep ^V='" \
19 "V=
20" "" ""
21
22testing "environment variables 1c" \
23 "env sh -c 'env | grep ^V='" \
24 "" "" ""
25
26testing "environment variables 2a" \
27 "V=set sh -c 'env | grep ^V='" \
28 "V=set
29" "" ""
30
31testing "environment variables 2b" \
32 "V= sh -c 'env | grep ^V='" \
33 "V=
34" "" ""
35
36testing "environment variables 2c" \
37 "sh -c 'env | grep ^V='" \
38 "" "" ""
39
40testing "environment variables 3a" \
41 "V=set env sh -c 'echo \${V-unset}'" \
42 "set
43" "" ""
44
45testing "environment variables 3b" \
46 "V= env sh -c 'echo \${V-unset}'" \
47 "
48" "" ""
49
50testing "environment variables 3c" \
51 "env sh -c 'echo \${V-unset}'" \
52 "unset
53" "" ""
54
55testing "environment variables 4a" \
56 "V=set sh -c 'echo \${V-unset}'" \
57 "set
58" "" ""
59
60testing "environment variables 4b" \
61 "V= sh -c 'echo \${V-unset}'" \
62 "
63" "" ""
64
65testing "environment variables 4c" \
66 "sh -c 'echo \${V-unset}'" \
67 "unset
68" "" ""
69SKIP=
70
71exit $FAILCOUNT
diff --git a/testsuite/hexdump.tests b/testsuite/hexdump.tests
index 517ec508b..b2f6a2201 100755
--- a/testsuite/hexdump.tests
+++ b/testsuite/hexdump.tests
@@ -5,6 +5,17 @@
5 5
6. ./testing.sh 6. ./testing.sh
7 7
8input=\
9"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
10"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\
11"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\
12"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
13"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
14
15little_endian=false
16{ printf '\0\1' | hexdump -d | grep -q 256; } && little_endian=true
17readonly little_endian
18
8# testing "description" "command" "result" "infile" "stdin" 19# testing "description" "command" "result" "infile" "stdin"
9testing 'hexdump -C with four NULs' \ 20testing 'hexdump -C with four NULs' \
10 'hexdump -C' \ 21 'hexdump -C' \
@@ -43,12 +54,7 @@ testing "hexdump -e %3_u" \
43 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 54 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f
44 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 55 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
45" \ 56" \
46 "" \ 57 "" "$input"
47"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
48"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\
49"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\
50"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
51"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\
52 58
53testing "hexdump -e /1 %d" \ 59testing "hexdump -e /1 %d" \
54 "hexdump -e '16/1 \" %4d\" \"\n\"'" \ 60 "hexdump -e '16/1 \" %4d\" \"\n\"'" \
@@ -59,33 +65,74 @@ testing "hexdump -e /1 %d" \
59 -128 -127 -126 -125 -124 -123 -122 -121 -120 -119 -118 -117 -116 -115 -114 -113 65 -128 -127 -126 -125 -124 -123 -122 -121 -120 -119 -118 -117 -116 -115 -114 -113
60 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 66 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
61" \ 67" \
62 "" \ 68 "" "$input"
63"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
64"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\
65"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\
66"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
67"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\
68 69
69testing "hexdump -e /2 %d" \ 70$little_endian || SKIP=1
70 "hexdump -e '8/2 \" %6d\" \"\n\"'" \ 71testing "hexdump -e /2 %d (little endian)" \
71 "\ 72 "hexdump -e '8/2 \" %6d\" \"\n\"'" \
73 "\
72 256 770 1284 1798 2312 2826 3340 3854 74 256 770 1284 1798 2312 2826 3340 3854
73 4368 4882 5396 5910 6424 6938 7452 7966 75 4368 4882 5396 5910 6424 6938 7452 7966
74 29040 29554 30068 30582 31096 31610 32124 32638 76 29040 29554 30068 30582 31096 31610 32124 32638
75 -32384 -31870 -31356 -30842 -30328 -29814 -29300 -28786 77 -32384 -31870 -31356 -30842 -30328 -29814 -29300 -28786
76 -3600 -3086 -2572 -2058 -1544 -1030 -516 -2 78 -3600 -3086 -2572 -2058 -1544 -1030 -516 -2
77" \ 79" \
78 "" \ 80 "" "$input"
79"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\ 81SKIP=
80"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\ 82
81"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\ 83$little_endian && SKIP=1
82"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ 84testing "hexdump -e /2 %d (big endian)" \
83"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ 85 "hexdump -e '8/2 \" %6d\" \"\n\"'" \
86 "\
87 1 515 1029 1543 2057 2571 3085 3599
88 4113 4627 5141 5655 6169 6683 7197 7711
89 28785 29299 29813 30327 30841 31355 31869 32383
90 -32639 -32125 -31611 -31097 -30583 -30069 -29555 -29041
91 -3855 -3341 -2827 -2313 -1799 -1285 -771 -257
92" \
93 "" "$input"
94SKIP=
84 95
85testing "hexdump -n4 -e '\"%u\"'" \ 96$little_endian || SKIP=1
97testing "hexdump -e /2 %x (little endian)" \
98 "hexdump -e '8/2 \" %6x\" \"\n\"'" \
99 "\
100 100 302 504 706 908 b0a d0c f0e
101 1110 1312 1514 1716 1918 1b1a 1d1c 1f1e
102 7170 7372 7574 7776 7978 7b7a 7d7c 7f7e
103 8180 8382 8584 8786 8988 8b8a 8d8c 8f8e
104 f1f0 f3f2 f5f4 f7f6 f9f8 fbfa fdfc fffe
105" \
106 "" "$input"
107SKIP=
108
109$little_endian && SKIP=1
110testing "hexdump -e /2 %x (big endian)" \
111 "hexdump -e '8/2 \" %6x\" \"\n\"'" \
112 "\
113 1 203 405 607 809 a0b c0d e0f
114 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f
115 7071 7273 7475 7677 7879 7a7b 7c7d 7e7f
116 8081 8283 8485 8687 8889 8a8b 8c8d 8e8f
117 f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff
118" \
119 "" "$input"
120SKIP=
121
122$little_endian || SKIP=1
123testing "hexdump -n4 -e '\"%u\"' (little endian)" \
86 "hexdump -n4 -e '\"%u\"'" \ 124 "hexdump -n4 -e '\"%u\"'" \
87 "12345678" \ 125 "12345678" \
88 "" \ 126 "" \
89 "\x4e\x61\xbc\x00AAAA" 127 "\x4e\x61\xbc\x00AAAA"
128SKIP=
129
130$little_endian && SKIP=1
131testing "hexdump -n4 -e '\"%u\"' (big endian)" \
132 "hexdump -n4 -e '\"%u\"'" \
133 "1315027968" \
134 "" \
135 "\x4e\x61\xbc\x00AAAA"
136SKIP=
90 137
91exit $FAILCOUNT 138exit $FAILCOUNT
diff --git a/testsuite/make.tests b/testsuite/make.tests
new file mode 100755
index 000000000..fabdbe45c
--- /dev/null
+++ b/testsuite/make.tests
@@ -0,0 +1,805 @@
1#!/bin/sh
2
3. ./testing.sh
4unset MAKEFLAGS
5rm -rf make.tempdir
6
7# testing "test name" "command" "expected result" "file input" "stdin"
8
9testing "make basic makefile" \
10 "make -f -" "target\n" "" '
11target:
12 @echo target
13'
14
15testing "make .DEFAULT rule for prerequisite" \
16 "make -f - 2>/dev/null" "source\n" "" '
17.DEFAULT:
18 @echo $@
19target: source
20'
21
22mkdir make.tempdir && cd make.tempdir || exit 1
23touch target.xyz
24testing "make empty command overrides inference rule" \
25 "make -f - target 2>/dev/null" "" "" '
26.SUFFIXES: .xyz
27.xyz:
28 @echo xyz
29target: ;
30'
31cd .. || 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.
35testing "make macro expansion and suffix substitution" \
36 "make -f -" "src1.o src2.o\n" "" '
37DOTC = .c
38DOTO = .o
39SRC1 = src1.c
40SRCS = $(SRC1) src2.c
41target:
42 @echo $(SRCS:$(DOTC)=$(DOTO))
43'
44
45# Indeed, everything after the <colon> can be obtained by macro
46# macro expansion.
47testing "make macro expansion and suffix substitution 2" \
48 "make -f -" "src1.o src2.o\n" "" '
49DOTS = .c=.o
50SRC1 = src1.c
51SRCS = $(SRC1) src2.c
52target:
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.
58mkdir make.tempdir && cd make.tempdir || exit 1
59testing "make inference rule with explicit rule for prerequisite" \
60 "make -f -" "touch x.p\ncat x.p >x.q\n" "" '
61.SUFFIXES: .p .q
62x.q:
63x.p:
64 touch $@
65.p.q:
66 cat $< >$@
67'
68cd .. || 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.
73mkdir make.tempdir && cd make.tempdir || exit 1
74touch test.j test.k
75testing "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
83test.l: test.k
84test.j:
85test.k:
86'
87cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
88
89# Check that single-suffix inference rules work.
90mkdir make.tempdir && cd make.tempdir || exit 1
91touch test.sh
92testing "make single-suffix inference rule works" \
93 "make -f - -s; echo $?" \
94 "0\n" "" '
95test:
96'
97cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
98
99# There was a bug where the failure of a build command didn't result
100# in make returning a non-zero exit status.
101testing "make return error if command fails" \
102 "make -f - >/dev/null 2>&1; test \$? -gt 0 && echo OK" "OK\n" "" '
103target:
104 @exit 42
105'
106
107# An equal sign in a command on a target rule was detected as a
108# macro assignment.
109testing "make equal sign in inline command" \
110 "make -f -" "a = a\n" "" '
111a = a
112target:;@echo a = $(a)
113'
114
115# Ensure an inline command on a target rule can be detected even if
116# the semicolon is obfuscated.
117testing "make equal sign in obfuscated inline command" \
118 "make -f -" "a = a\n" "" '
119a = a
120semi = ;
121target:$(semi)@echo a = $(a)
122'
123
124# When a build command fails and the '-k' option has been provided
125# (continue execution on error) no further commands should be executed
126# for the current target.
127testing "make failure of build command with -k" \
128 "make -k -f - 2>/dev/null" "OK\n" "" '
129all: bar baz
130bar:
131 @echo OK
132 @false
133 @echo Not reached
134baz:
135 @:
136'
137# Build commands with a '+' prefix are executed even with the -q option.
138testing "make execute build command with + prefix and -q" \
139 "make -q -f - 2>/dev/null" "OK\n" "" '
140all: bar
141bar:
142 @+echo OK
143'
144
145# The -t option touches files that are out-of-date unless the target
146# has no commands or they're already up-to-date.
147mkdir make.tempdir && cd make.tempdir || exit 1
148touch baz
149testing "make check -t option" \
150 "make -t -f - 2>/dev/null" "touch bar\n" "" '
151all: foo bar baz
152foo:
153bar:
154 @echo bar
155baz:
156 @echo baz
157'
158cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
159
160# Build commands with a '+' prefix are executed even with the -t option.
161mkdir make.tempdir && cd make.tempdir || exit 1
162testing "make execute build command with + prefix and -t" \
163 "make -t -f - 2>/dev/null" "OK\n" "" '
164all: bar
165bar:
166 @+echo OK
167'
168cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
169
170# A macro created using ::= remembers it's of type immediate-expansion.
171# Immediate expansion also occurs when += is used to append to such a macro.
172testing "make appending to immediate-expansion macro" \
173 "make -f -" \
174 "hello 1 2 3\nhello 4 4\n" "" '
175world = 1
176hello ::= hello $(world)
177world = 2
178hello += $(world)
179world = 3
180hello += $(world)
181world = 4
182
183world = 1
184reset ::= hello $(world)
185world = 2
186# No longer immediate-expansion
187reset = hello $(world)
188world = 3
189reset += $(world)
190world = 4
191
192target:
193 @echo $(hello)
194 @echo $(reset)
195'
196
197# Since GNU make and bmake interpret := macro assignments differently,
198# POSIX has ::= for the GNU variant and :::= for BSD.
199testing "make different styles of := macro assignment" \
200 "make -f -" \
201 '65 a a $A\n' "" '
202A = a
203GNU ::= $A
204BSD1 :::= $A
205BSD2 :::= $$A
206A = 65
207
208target:
209 @echo '\''$(A) $(GNU) $(BSD1) $(BSD2)'\''
210'
211
212# Similar to the above but for macro assignments on the command line.
213# POSIX has ::= for the GNU variant and :::= for BSD.
214testing "make := macro assignment on command line" \
215 "make -f - A=a 'GNU::=\$A' 'BSD1:::=\$A' 'BSD2:::=\$\$A' A=65" \
216 '65 a a $A\n' "" '
217target:
218 @echo '\''$(A) $(GNU) $(BSD1) $(BSD2)'\''
219'
220
221# basic pattern macro expansion
222testing "make basic pattern macro expansion" \
223 "make -f -" \
224 "obj/util.o obj/main.o\n" "" '
225SRC = src/util.c src/main.c
226OBJ = $(SRC:src/%.c=obj/%.o)
227
228target:
229 @echo $(OBJ)
230'
231
232# pattern macro expansion; match any value
233testing "make pattern macro expansion; match any value" \
234 "make -f -" \
235 "any_value.o\n" "" '
236SRC = any_value
237OBJ = $(SRC:%=%.o)
238
239target:
240 @echo $(OBJ)
241'
242
243# pattern macro expansion with empty rvalue
244testing "make pattern macro expansion with empty rvalue" \
245 "make -f -" \
246 "\n" "" '
247SRC = util.c main.c
248OBJ = $(SRC:%.c=)
249
250target:
251 @echo $(OBJ)
252'
253
254# pattern macro expansion with multiple <percent> in rvalue
255# POSIX requires the first <percent> to be expanded, others
256# may or may not be expanded. Permit either case.
257testing "make pattern macro expansion with multiple <percent> in rvalue" \
258 "make -f - | sed 's/mainmainmain/main%%/'" \
259 "main%%\n" "" '
260SRC = main.c
261OBJ = $(SRC:%.c=%%%)
262
263target:
264 @echo $(OBJ)
265'
266
267# pattern macro expansion; zero match
268testing "make pattern macro expansion; zero match" \
269 "make -f -" \
270 "nsnp\n" "" '
271WORD = osop
272REPL = $(WORD:os%op=ns%np)
273
274target:
275 @echo $(REPL)
276'
277
278# Check that MAKE will contain argv[0], e.g make in this case
279testing "make basic MAKE macro expansion" \
280 "make -f -" \
281 "make\n" "" '
282target:
283 @echo $(MAKE)
284'
285
286# Check that MAKE defined as environment variable will overwrite default MAKE
287testing "make MAKE macro expansion; overwrite with env macro" \
288 "MAKE=hello make -f -" \
289 "hello\n" "" '
290target:
291 @echo $(MAKE)
292'
293
294# Check that MAKE defined on the command-line will overwrite MAKE defined in
295# Makefile
296testing "make MAKE macro expansion; overwrite with command-line macro" \
297 "make -f - MAKE=hello" \
298 "hello\n" "" '
299MAKE = test
300
301target:
302 @echo $(MAKE)
303'
304
305# POSIX draft states that if make was invoked using relative path, MAKE must
306# contain absolute path, not just argv[0]
307testing "make MAKE macro expansion; turn relative path into absolute" \
308 "../runtest-tempdir-links/make -f -" \
309 "ok\n" "" '
310target:
311 @test -e "$(MAKE)" && test "$(MAKE)" = "$$(env which make)" && echo ok
312'
313
314# $? contains prerequisites newer than target, file2 in this case
315# $^ has all prerequisites, file1 and file2
316touch -t 202206171200 file1
317touch -t 202206171201 target
318touch -t 202206171202 file2
319testing "make compare \$? and \$^ internal macros" \
320 "make -f -" \
321 "file2\nfile1 file2\n" "" '
322target: file1 file2
323 @echo $?
324 @echo $^
325'
326rm -f target file1 file2
327
328# Phony targets are executed (once) even if a matching file exists.
329# A .PHONY target with no prerequisites is ignored.
330touch -t 202206171201 target
331testing "make phony target" \
332 "make -f -" \
333 "phony\n" "" '
334.PHONY: target
335.PHONY:
336target:
337 @echo phony
338'
339rm -f target
340
341# Phony targets aren't touched with -t
342testing "make phony target not touched" \
343 "make -t -f - >/dev/null && test -f target && echo target" \
344 "" "" '
345.PHONY: target
346target:
347 @:
348'
349rm -f target
350
351# Include files are created or brought up-to-date
352mkdir make.tempdir && cd make.tempdir || exit 1
353testing "make create include file" \
354 "make -f -" \
355 "made\n" "" '
356target:
357 @echo $(VAR)
358mk:
359 @echo "VAR = made" >mk
360include mk
361'
362cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
363
364# Include files are created or brought up-to-date even when the -n
365# option is given.
366mkdir make.tempdir && cd make.tempdir || exit 1
367testing "make create include file even with -n" \
368 "make -n -f -" \
369 "echo made\n" "" '
370target:
371 @echo $(VAR)
372mk:
373 @echo "VAR = made" >mk
374include mk
375'
376cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
377
378# Failure to create an include file isn't an error. (Provided the
379# include line is ignoring non-existent files.)
380testing "make failure to create include file is OK" \
381 "make -f -" \
382 "OK\n" "" '
383target:
384 @echo OK
385mk:
386 @:
387-include mk
388'
389
390# $^ skips duplicate prerequisites, $+ doesn't
391mkdir make.tempdir && cd make.tempdir || exit 1
392touch file1 file2 file3
393testing "make skip duplicate entries in \$^ but not \$+" \
394 "make -f -" \
395 "file1 file2 file3\nfile1 file2 file2 file3 file3\n" "" '
396target: file1 file2 file2 file3 file3
397 @echo $^
398 @echo $+
399'
400cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
401
402# Assign the output of a shell command to a macro.
403testing "make shell assignment" \
404 "make -f -" \
405 "1 2 3 4\n" "" '
406hello != echo 1; echo 2; echo 3; echo; echo
407
408target:
409 @echo "$(hello) 4"
410'
411
412# Nested macro expansion is allowed. This should be compatible
413# with other implementations.
414testing "make nested macro expansion" \
415 "make -f -" "0 bc\n1 d\n2\n3\n4 bcd\n5 bcd\n" "" '
416a = b
417b = c
418c = d
419$(a:.q=.v)$(b:.z=.v) = bc
420bcd = bcd
421target:
422 @echo 0 $(bc)
423 @echo 1 $($($(a)))
424 @echo 2 $($(a) $(b) $(c))
425 @echo 3 $($a $b $c)
426 @echo 4 $($(a)$(b)$(c))
427 @echo 5 $($a$b$c)
428'
429
430# .WAIT is allowed as a prerequisite. Since parallel builds aren't
431# implemented it doesn't have any effect.
432mkdir make.tempdir && cd make.tempdir || exit 1
433touch file1 file2
434testing "make .WAIT is allowed as a prerequisite" \
435 "make -f -" \
436 "file1 file2\n" "" '
437target: file1 .WAIT file2
438 @echo $?
439'
440cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
441
442# Escaped newlines inside macro expansions in commands get different
443# treatment than those outside. In POSIX 2017 the output is 'a b ab'.
444testing "make replace escaped NL in macro in command with space" \
445 "make -f -" \
446 "a b a b\n" "" '
447M=word
448N=${M:word=a\\
449b}
450target:
451 @echo ${N} ${M:word=a\\
452b}
453'
454
455# The CURDIR macro is supported in POSIX 2024.
456testing "make CURDIR macro" \
457 "make -f -" \
458 "OK\n" "" '
459target:
460 @test "$(CURDIR)" = "$$(pwd -P)" && echo OK
461'
462# The CURDIR environment variable doesn't affect the macro
463export CURDIR=/you/are/here
464testing "make CURDIR macro not affected by environment" \
465 "make -f -" \
466 "OK\n" "" '
467target:
468 @test "$(CURDIR)" != "/you/are/here" && echo OK
469'
470
471# The -e option makes the CURDIR macro match the environment
472testing "make with -e CURDIR macro is affected by the environment" \
473 "make -e -f -" \
474 "/you/are/here\n" "" '
475target:
476 @echo $(CURDIR)
477'
478unset CURDIR
479
480# The fix for an equal sign in an inline command on a target rule broke
481# a complex chain of macro assignments generated by autotools.
482testing "make complex chain of macro assignments" \
483 "make -f -" "flag 1\n" "" '
484FLAG_ = $(FLAG_$(VALUE))
485FLAG_0 = flag 0
486FLAG_1 = flag 1
487MYFLAG = $(FLAG_$(VALUE))
488VALUE = 1
489
490target:
491 @echo $(MYFLAG)
492'
493
494# POSIX 2024 permits additional characters in macro and target names
495testing "make allow - and / in target names, - in macro names" \
496 "make -f -" \
497 "/hello\nhel-lo\nmac-ro\n" "" '
498target: ./hello hel-lo
499 @echo $(mac-ro)
500./hello:
501 @echo /hello
502hel-lo:
503 @echo hel-lo
504mac-ro = mac-ro
505'
506
507testing "make double-colon rule" \
508 "make -f -" "target1\ntarget2\n" "" '
509target::
510 @echo target1
511target::
512 @echo target2
513'
514
515# There was a bug whereby the modification time of a file created by
516# double-colon rules wasn't correctly updated. This test checks that
517# the bug is now fixed.
518mkdir make.tempdir && cd make.tempdir || exit 1
519touch -t 202206171200 file1
520touch -t 202206171201 intermediate
521touch -t 202206171202 target
522touch -t 202206171203 file2
523testing "make target depends on prerequisite updated by double-colon rule" \
524 "make -f -" \
525 "file2\n" "" '
526target: intermediate
527 @cat intermediate
528intermediate:: file1
529 @echo file1 >>intermediate
530intermediate:: file2
531 @echo file2 >>intermediate
532'
533cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
534
535# Use chained inference rules to determine prerequisites.
536mkdir make.tempdir && cd make.tempdir || exit 1
537touch target.p
538testing "make chained inference rules" \
539 "make -s -f - target.s" \
540 "target.q\ntarget.r\ntarget.s\n" "" '
541.SUFFIXES: .p .q .r .s
542.p.q:
543 @cp $< $*.q
544 @echo $*.q
545.q.r:
546 @cp $< $*.r
547 @echo $*.r
548.r.s:
549 @cp $< $*.s
550 @echo $*.s
551'
552cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
553
554# Suffixes with multiple periods are supported
555mkdir make.tempdir && cd make.tempdir || exit 1
556touch x.c.c
557testing "make support multi-period suffixes" \
558 "make -f -" "cat x.c.c >x.o.o\nx\n" "" '
559.SUFFIXES: .c.c .o.o
560x.o.o:
561.c.c.o.o:
562 cat $< >$@
563 @echo $*
564'
565cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
566
567# Suffixes with no periods are supported
568mkdir make.tempdir && cd make.tempdir || exit 1
569touch filex
570testing "make support suffixes without any periods" \
571 "make -f -" "cp filex fileh\nfile\ncp filex filez\nfile\n" "" '
572.SUFFIXES: x h z
573all: fileh filez
574fileh:
575filez: filex
576 cp filex filez
577 @echo $*
578xh:
579 cp $< $@
580 @echo $*
581'
582cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
583
584# make supports *, ? and [] wildcards in targets and prerequisites
585mkdir make.tempdir && cd make.tempdir || exit 1
586touch -t 202206171201 t1a t2aa t3b
587touch s1a s2aa s3b
588testing "make expand wildcards in filenames" \
589 "make -f - t1a t2aa t3b" \
590 "t1a s1a s2aa s3b\nt2aa s1a s2aa s3b\nt3b s1a s2aa s3b\n" "" '
591t1? t2* t3[abc]: s1? s2* s3[abc]
592 @echo $@ $?
593'
594cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
595
596# A '#' character in a macro expansion doesn't start a comment
597testing "make hash in macro expansion isn't a comment" \
598 "make -f -" \
599 ": hash # hash\n" "" '
600HASH = hash
601hash = $(HASH:hash=#)
602target:
603 : hash $(hash) hash
604'
605
606# A '#' character can be escaped with a backslash
607testing "make backslash-escaped hash isn't a comment" \
608 "make -f -" \
609 ": hash # hash\n" "" '
610hash = \\#
611target:
612 : hash $(hash) hash
613'
614
615# A '#' character in a command line doesn't start a comment
616testing "make hash in command line isn't a comment" \
617 "make -f -" \
618 ": hash # hash\n" "" '
619target:
620 : hash # hash
621'
622
623# Austin Group defect report 875 (mentioned above) actually used
624# suffixes '.a .b .c'. This doesn't matter in POSIX mode but it
625# caused a failure (now fixed) when chained inference rules were
626# allowed. The '.a.c' and the built-in '.c.a' inference rules
627# resulted in a loop.
628mkdir make.tempdir && cd make.tempdir || exit 1
629touch test.a test.b
630testing "make proper handling of inference rules 2" \
631 "make -f -" \
632 ".a.c\n" "" '
633.SUFFIXES: .a .b .c
634.a.c:
635 @echo .a.c
636.b.c:
637 @echo .b.c
638test.c: test.b
639test.a:
640test.b:
641'
642cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
643
644# Don't use the shell -e option when running commands.
645testing "make no shell -e option when running commands" \
646 "make -f -" "OK\n" "" '
647target:
648 @false; echo OK
649'
650
651# Macros and targets may be mixed on the command line
652testing "make allow mixed macros and targets" \
653 "make -f - FOO=foo foo BAR=bar bar" "foo\nbar\nfoo\nbar\n" "" '
654foo:
655 @echo $(FOO)
656 @echo $(BAR)
657bar:
658 @echo $(FOO)
659 @echo $(BAR)
660'
661
662# $* and $< are supported for target rules
663mkdir make.tempdir && cd make.tempdir || exit 1
664touch src.c src.h
665testing 'make support $* and $< for target rules' \
666 "make -f -" "src.c src.h\nsrc.o\nsrc\nsrc.c\n" "" '
667src.o: src.c src.h
668 @echo "$?"
669 @echo "$@"
670 @echo "$*"
671 @echo "$<"
672'
673cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
674
675# ifeq/ifneq conditionals are supported
676testing 'make support ifeq and ifneq conditionals' \
677 "make -f -" "A OK\nB OK\n" "" '
678A = a
679B = b
680target:
681ifeq ($(A),a)
682 @echo A OK
683else
684 @echo A not OK
685endif
686ifneq "a" "$B"
687 @echo B OK
688endif
689'
690
691# An empty original suffix indicates that every word should have
692# the new suffix added. If neither suffix is provided the words
693# remain unchanged.
694testing "make macro expansion and suffix substitution 3" \
695 "make -f -" "src1.c src2.c\nsrc1 src2\n" "" '
696SRCS = src1 src2
697target:
698 @echo $(SRCS:=.c)
699 @echo $(SRCS:=)
700'
701
702# Skip duplicate entries in $? and $^
703mkdir make.tempdir && cd make.tempdir || exit 1
704touch -t 202206171200 file1 file3
705touch -t 202206171201 target
706touch -t 202206171202 file2
707testing "make skip duplicate entries in \$? and \$^" \
708 "make -f -" \
709 "file2\nfile1 file2 file3\n" "" '
710target: file1 file2 file2 file3 file3
711 @echo $?
712 @echo $^
713'
714cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
715
716# Skip duplicate entries in $? and $^, with each double-colon rule
717# handled separately
718mkdir make.tempdir && cd make.tempdir || exit 1
719touch -t 202206171200 file1 file3
720touch -t 202206171201 target
721touch -t 202206171202 file2
722testing "make skip duplicate entries: double-colon rules" \
723 "make -f -" \
724 "file2\nfile1 file3 file2\nfile2\nfile2 file3\n" "" '
725target:: file1 file3 file1 file2 file3
726 @echo $?
727 @echo $^
728target:: file2 file3 file3
729 @echo $?
730 @echo $^
731'
732cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
733
734# Skip duplicate entries in $? and $^, with each double-colon rule
735# handled separately. No prerequisites out-of-date in the first.
736mkdir make.tempdir && cd make.tempdir || exit 1
737touch -t 202206171200 file1 file3
738touch -t 202206171201 target
739touch -t 202206171202 file2
740testing "make skip duplicate entries: double-colon rules, only second invoked" \
741 "make -f -" \
742 "file2\nfile2 file3\n" "" '
743target:: file1 file3 file1 file3
744 @echo $?
745 @echo $^
746target:: file2 file3 file3
747 @echo $?
748 @echo $^
749'
750cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
751
752# .DEFAULT rules with no commands or some prerequisites are ignored.
753# .DEFAULT rules with commands can be redefined.
754testing "make: .DEFAULT rule" \
755 "make -f - default" "default2\n" "" '
756.DEFAULT: ignored
757.DEFAULT:
758 @echo default1
759.DEFAULT:
760 @echo default2
761target:
762'
763
764testing "make: double-colon rule" \
765 "make -f -" "target1\ntarget2\n" "" '
766target::
767 @echo target1
768target::
769 @echo target2
770'
771
772# Double-colon rules didn't work properly if their target was phony:
773# - they didn't ignore the presence of a file matching the target name;
774# - they were also invoked as if they were a single-colon rule.
775mkdir make.tempdir && cd make.tempdir || exit 1
776touch -t 202206171200 file1
777touch -t 202206171201 target
778testing "make phony target of double-colon rule" \
779 "make -f - 2>&1" \
780 "unconditional\nconditional\n" "" '
781.PHONY: target
782target::
783 @echo unconditional
784target:: file1
785 @echo conditional
786file1:
787 @touch file1
788'
789cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
790
791# GNU make and BSD make don't allow the use of inference rules
792# for phony targets. In POSIX mode the output is "phony.xyz\n".
793mkdir make.tempdir && cd make.tempdir || exit 1
794touch phony.xyz
795testing "make don't use inference rule for phony target" \
796 "make -f -" "make: nothing to be done for phony\n" "" '
797.PHONY: phony
798.SUFFIXES: .xyz
799.xyz:
800 @echo $<
801phony:
802'
803cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
804
805exit $FAILCOUNT
diff --git a/testsuite/od.tests b/testsuite/od.tests
index 4f245a7e8..c863bf2e8 100755
--- a/testsuite/od.tests
+++ b/testsuite/od.tests
@@ -61,7 +61,8 @@ testing "od -a (DESKTOP)" \
61"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" 61"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
62SKIP= 62SKIP=
63 63
64testing "od -B" \ 64$little_endian || SKIP=1
65testing "od -B (little-endian)" \
65 "od -B" \ 66 "od -B" \
66"\ 67"\
670000000 001001 005003 041101 177103 680000000 001001 005003 041101 177103
@@ -70,6 +71,16 @@ testing "od -B" \
70 "" "$input" 71 "" "$input"
71SKIP= 72SKIP=
72 73
74$little_endian && SKIP=1
75testing "od -B (big-endian)" \
76 "od -B" \
77"\
780000000 000402 001412 040502 041776
790000010
80" \
81 "" "$input"
82SKIP=
83
73$little_endian || SKIP=1 84$little_endian || SKIP=1
74testing "od -o (little-endian)" \ 85testing "od -o (little-endian)" \
75 "od -o" \ 86 "od -o" \
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
100fi 100fi
101 101
102if [ -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
111else
112 suffix=""
113 lnflag="-s"
114fi
115
102implemented=$( 116implemented=$(
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
132done 146done
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
10test -f "$bindir/.config" && . "$bindir/.config"
11
12# testing "test name" "options" "expected result" "file input" "stdin"
13
14optional PLATFORM_MINGW32
15# Test case
16testing "shebang" \
17 "uudecode; sh -c './shebang.sh'; echo \$?" \
18 "Hello world
190
20" \
21"" "\
22begin-base64 755 shebang.sh
23IyEvYmluL3NoCmVjaG8gIkhlbGxvIHdvcmxkIgo=
24====
25"
26rm -f shebang.sh
27
28# Test case
29testing "shebang with whitespace" \
30 "uudecode; sh -c './shebang_trailing_space.sh'; echo \$?" \
31 "Hello world
320
33" \
34"" "\
35begin-base64 755 shebang_trailing_space.sh
36IyEvYmluL3NoIAplY2hvICJIZWxsbyB3b3JsZCIK
37====
38"
39rm -f shebang_trailing_space.sh
40
41# Test case
42testing "shebang with argument" \
43 "uudecode; sh -c './shebang_argument.sh'; echo \$?" \
44 "Hello world
450
46" \
47"" "\
48begin-base64 755 shebang_argument.sh
49IyEvYmluL3NoIC0KZWNobyAiSGVsbG8gd29ybGQiCg==
50====
51"
52rm -f shebang_argument.sh
53
54# Test case
55testing "shebang with leading whitespace and argument" \
56 "uudecode; sh -c './shebang_leading_space_argument.sh'; echo \$?" \
57 "Hello world
580
59" \
60"" "\
61begin-base64 755 shebang_leading_space_argument.sh
62IyEvYmluL3NoICAtCmVjaG8gIkhlbGxvIHdvcmxkIgo=
63====
64"
65rm -f shebang_leading_space_argument.sh
66
67# Test case
68testing "shebang with argument and trailing whitespace" \
69 "uudecode; sh -c './shebang_argument_trailing_space.sh'; echo \$?" \
70 "Hello world
710
72" \
73"" "\
74begin-base64 755 shebang_argument_trailing_space.sh
75IyEvYmluL3NoIC0gCmVjaG8gIkhlbGxvIHdvcmxkIgo=
76====
77"
78rm -f shebang_argument_trailing_space.sh
79
80# Test case
81testing "shebang with leading whitespace, argument and trailing whitespace" \
82 "uudecode; sh -c './shebang_leading_argument_trailing_space.sh'; echo \$?" \
83 "Hello world
840
85" \
86"" "\
87begin-base64 755 shebang_leading_argument_trailing_space.sh
88IyEvYmluL3NoICAtIAplY2hvICJIZWxsbyB3b3JsZCIK
89====
90"
91rm -f shebang_leading_argument_trailing_space.sh
92
93testing "sh remove CRs from string being evaluated" \
94 "sh -c \"$(printf 'set -e\r\necho Hello world\r\n')\"" \
95 "Hello world\n" "" ""
96
97testing "sh preserve lone CRs during field splitting" \
98 "sh input" \
99 "Hello\r world\n" "echo \$(printf \"Hello\\\\r\\\\r\\\\nworld\\\\r\\\\n\")" ""
100
101testing "sh read with CRLF" \
102 "printf '1 2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
103 "1 2\n" "" ""
104
105testing "sh read with CR" \
106 "printf '1\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
107 "1\r2\n" "" ""
108
109testing "sh read with \\CRLF" \
110 "printf '1\\\\\r\\n2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
111 "12\n" "" ""
112
113testing "sh read with \\CR" \
114 "printf '1\\\\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
115 "1\r2\n" "" ""
116SKIP=
117
118exit $FAILCOUNT
diff --git a/testsuite/wget/wget-handles-https b/testsuite/wget/wget-handles-https
new file mode 100644
index 000000000..11915f42f
--- /dev/null
+++ b/testsuite/wget/wget-handles-https
@@ -0,0 +1,4 @@
1test x"$SKIP_INTERNET_TESTS" != x"" && exit
2
3busybox wget -q -O foo https://www.google.com/
4test -s foo