diff options
Diffstat (limited to '')
-rwxr-xr-x | testsuite/sh.tests | 118 |
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 | |||
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 | ||