aboutsummaryrefslogtreecommitdiff
path: root/testsuite/sh.tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtestsuite/sh.tests118
1 files changed, 118 insertions, 0 deletions
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