aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rwxr-xr-xtestsuite/cpio.tests23
-rwxr-xr-xtestsuite/cut.tests140
-rwxr-xr-xtestsuite/hexdump.tests6
-rwxr-xr-xtestsuite/make.tests40
4 files changed, 197 insertions, 12 deletions
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/cut.tests b/testsuite/cut.tests
index a31f41f7f..21cfea809 100755
--- a/testsuite/cut.tests
+++ b/testsuite/cut.tests
@@ -23,14 +23,30 @@ the quick brown fox jumps over the lazy dog
23 23
24testing "cut -b a,a,a" "cut -b 3,3,3 input" "e\np\ne\n" "$abc" "" 24testing "cut -b a,a,a" "cut -b 3,3,3 input" "e\np\ne\n" "$abc" ""
25 25
26testing "cut -b overlaps" "cut -b 1-3,2-5,7-9,9-10 input" \ 26testing "cut -b overlaps" \
27 "one:to:th\nalphabeta\nthe qick \n" "$abc" "" 27 "cut -b 1-3,2-5,7-9,9-10 input" \
28testing "-b encapsulated" "cut -b 3-8,4-6 input" "e:two:\npha:be\ne quic\n" \ 28 "\
29 "$abc" "" 29one:to:th
30# --output-delimiter not implemnted (yet?) 30alphabeta
31#testing "cut -bO overlaps" \ 31the qick \n" \
32# "cut --output-delimiter ' ' -b 1-3,2-5,7-9,9-10 input" \ 32 "$abc" ""
33# "one:t o:th\nalpha beta\nthe q ick \n" "$abc" "" 33testing "-b encapsulated" \
34 "cut -b 3-8,4-6 input" \
35 "\
36e:two:
37pha:be
38e quic\n" \
39 "$abc" ""
40optional LONG_OPTS
41testing "cut -b --output-delimiter overlaps" \
42 "cut --output-delimiter='^' -b 1-3,2-5,7-9,9-10 input" \
43 "\
44one:t^o:th
45alpha^beta
46the q^ick \n" \
47 "$abc" ""
48SKIP=
49
34testing "cut high-low error" "cut -b 8-3 input 2>/dev/null || echo err" "err\n" \ 50testing "cut high-low error" "cut -b 8-3 input 2>/dev/null || echo err" "err\n" \
35 "$abc" "" 51 "$abc" ""
36 52
@@ -68,10 +84,27 @@ testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s input && echo yes" "yes\n" "$in
68testing "cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" 84testing "cut with -d -f(a) -s" "cut -da -f3 -s input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
69testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" "" 85testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n input" "n\nsium:Jim\n\ncion:Ed\n" "$input" ""
70 86
87input="\
88
89foo bar baz
90
91bing bong boop
92
93"
94testing "cut with -d -s omits blank lines" "cut -d' ' -f2 -s input" "bar\nbong\n" "$input" ""
95
71# substitute for awk 96# substitute for awk
72optional FEATURE_CUT_REGEX 97optional FEATURE_CUT_REGEX
73testing "cut -DF" "cut -DF 2,7,5" \ 98testing "cut -DF unordered" "cut -DF 2,7,5" \
74 "said and your\nare\nis demand. supply\nforecast :\nyou you better,\n\nEm: Took hate\n" "" \ 99 "\
100said and your
101are
102is demand. supply
103forecast :
104you you better,
105
106Em: Took hate
107" "" \
75"Bother, said Pooh. It's your husband, and he has a gun. 108"Bother, said Pooh. It's your husband, and he has a gun.
76Cheerios are donut seeds. 109Cheerios are donut seeds.
77Talk is cheap because supply exceeds demand. 110Talk is cheap because supply exceeds demand.
@@ -79,9 +112,92 @@ Weather forecast for tonight : dark.
79Apple: you can buy better, but you can't pay more. 112Apple: you can buy better, but you can't pay more.
80Subcalifragilisticexpialidocious. 113Subcalifragilisticexpialidocious.
81Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy." 114Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
115
116# No delimiter found: print entire line regardless of -F RANGES
117testing "cut -F1" "cut -d: -F1" \
118 "the_only_field\n" "" \
119 "the_only_field\n"
120testing "cut -F2" "cut -d: -F2" \
121 "the_only_field\n" "" \
122 "the_only_field\n"
123# No delimiter found and -s: skip entire line
124testing "cut -sF1" "cut -d: -sF1" \
125 "" "" \
126 "the_only_field\n"
127#^^^ the above is probably mishandled by toybox, it prints the line
128testing "cut -sF2" "cut -d: -sF2" \
129 "" "" \
130 "the_only_field\n"
131# -D disables special handling of lines with no delimiters, the line is treated as the 1st field
132testing "cut -DF1" "cut -d: -DF1" \
133 "the_only_field\n" "" \
134 "the_only_field\n"
135testing "cut -DF2" "cut -d: -DF2" \
136 "\n" "" \
137 "the_only_field\n"
138
139optional FEATURE_CUT_REGEX LONG_OPTS
140testing "cut -F preserves intermediate delimiters" \
141 "cut --output-delimiter=: -F2,4-6,7" \
142 "2:4 5 6:7\n" \
143 "" "1 2 3 4\t\t5 6 7 8\n"
144SKIP=
145
146optional LONG_OPTS
147testing "cut -f does not preserve intermediate delimiters" \
148 "cut --output-delimiter=: -d' ' -f2,4-6,7" \
149 "2:4:5:6:7\n" \
150 "" "1 2 3 4 5 6 7 8\n"
151SKIP=
152
153testing "cut empty field" "cut -d ':' -f 1-3" \
154 "a::b\n" \
155 "" "a::b\n"
156testing "cut empty field 2" "cut -d ':' -f 3-5" \
157 "b::c\n" \
158 "" "a::b::c:d\n"
159testing "cut non-existing field" "cut -d ':' -f1,3" \
160 "1\n" \
161 "" "1:\n"
162
163# cut -d$'\n' has a special meaning: "select input lines".
164# I didn't find any documentation for this feature.
165testing "cut -dNEWLINE" \
166 "cut -d'
167' -f4,2,6-8" \
168 "2\n4\n6\n7\n" \
169 "" "1\n2\n3\n4\n5\n6\n7"
170
171optional LONG_OPTS
172testing "cut -dNEWLINE --output-delimiter" \
173 "cut -d'
174' --output-delimiter=@@ -f4,2,6-8" \
175 "2@@4@@6@@7\n" \
176 "" "1\n2\n3\n4\n5\n6\n7"
177
178testing "cut -dNEWLINE --output-delimiter 2" \
179 "cut -d'
180' --output-delimiter=@@ -f4,2,6-8" \
181 "2@@4@@6@@7\n" \
182 "" "1\n2\n3\n4\n5\n6\n7\n"
183
184testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \
185 "cut -d'
186' --output-delimiter=@@ -f4,2,6-8" \
187 "" \
188 "" ""
82SKIP= 189SKIP=
83 190
84testing "cut empty field" "cut -d ':' -f 1-3" "a::b\n" "" "a::b\n" 191# This seems to work as if delimiter is never found.
85testing "cut empty field 2" "cut -d ':' -f 3-5" "b::c\n" "" "a::b::c:d\n" 192# We test here that -d '' does *not* operate as if there was no -d
193# and delimiter has defaulted to TAB:
194testing "cut -d EMPTY" \
195 "cut -d '' -f2-" \
196 "1 2\t3 4 5\n" \
197 "" "1 2\t3 4 5\n"
198testing "cut -d EMPTY -s" \
199 "cut -d '' -f2- -s" \
200 "" \
201 "" "1 2\t3 4 5\n"
86 202
87exit $FAILCOUNT 203exit $FAILCOUNT
diff --git a/testsuite/hexdump.tests b/testsuite/hexdump.tests
index be0379cfc..517ec508b 100755
--- a/testsuite/hexdump.tests
+++ b/testsuite/hexdump.tests
@@ -82,4 +82,10 @@ testing "hexdump -e /2 %d" \
82"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\ 82"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
83"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\ 83"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\
84 84
85testing "hexdump -n4 -e '\"%u\"'" \
86 "hexdump -n4 -e '\"%u\"'" \
87 "12345678" \
88 "" \
89 "\x4e\x61\xbc\x00AAAA"
90
85exit $FAILCOUNT 91exit $FAILCOUNT
diff --git a/testsuite/make.tests b/testsuite/make.tests
index 376bdcc15..fabdbe45c 100755
--- a/testsuite/make.tests
+++ b/testsuite/make.tests
@@ -86,6 +86,16 @@ test.k:
86' 86'
87cd .. || exit 1; rm -rf make.tempdir 2>/dev/null 87cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
88 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
89# There was a bug where the failure of a build command didn't result 99# There was a bug where the failure of a build command didn't result
90# in make returning a non-zero exit status. 100# in make returning a non-zero exit status.
91testing "make return error if command fails" \ 101testing "make return error if command fails" \
@@ -541,6 +551,36 @@ testing "make chained inference rules" \
541' 551'
542cd .. || exit 1; rm -rf make.tempdir 2>/dev/null 552cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
543 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
544# make supports *, ? and [] wildcards in targets and prerequisites 584# make supports *, ? and [] wildcards in targets and prerequisites
545mkdir make.tempdir && cd make.tempdir || exit 1 585mkdir make.tempdir && cd make.tempdir || exit 1
546touch -t 202206171201 t1a t2aa t3b 586touch -t 202206171201 t1a t2aa t3b