aboutsummaryrefslogtreecommitdiff
path: root/testsuite/sh.tests
blob: 0eccf20bcdc2d232d81ddece8736cd26593850e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
#
# Test sh scripts
#
# Copyright 2019 by STMicroelectronics
# Licensed under GPLv2, see file LICENSE in this source tree.

. ./testing.sh

test -f "$bindir/.config" && . "$bindir/.config"

# testing "test name" "options" "expected result" "file input" "stdin"

optional PLATFORM_MINGW32
# Test case
testing "shebang" \
	"uudecode; sh -c './shebang.sh'; echo \$?" \
	"Hello world
0
" \
"" "\
begin-base64 755 shebang.sh
IyEvYmluL3NoCmVjaG8gIkhlbGxvIHdvcmxkIgo=
====
"
rm -f shebang.sh

# Test case
testing "shebang with whitespace" \
	"uudecode; sh -c './shebang_trailing_space.sh'; echo \$?" \
	"Hello world
0
" \
"" "\
begin-base64 755 shebang_trailing_space.sh
IyEvYmluL3NoIAplY2hvICJIZWxsbyB3b3JsZCIK
====
"
rm -f shebang_trailing_space.sh

# Test case
testing "shebang with argument" \
	"uudecode; sh -c './shebang_argument.sh'; echo \$?" \
	"Hello world
0
" \
"" "\
begin-base64 755 shebang_argument.sh
IyEvYmluL3NoIC0KZWNobyAiSGVsbG8gd29ybGQiCg==
====
"
rm -f shebang_argument.sh

# Test case
testing "shebang with leading whitespace and argument" \
       "uudecode; sh -c './shebang_leading_space_argument.sh'; echo \$?" \
       "Hello world
0
" \
"" "\
begin-base64 755 shebang_leading_space_argument.sh
IyEvYmluL3NoICAtCmVjaG8gIkhlbGxvIHdvcmxkIgo=
====
"
rm -f shebang_leading_space_argument.sh

# Test case
testing "shebang with argument and trailing whitespace" \
	"uudecode; sh -c './shebang_argument_trailing_space.sh'; echo \$?" \
	"Hello world
0
" \
"" "\
begin-base64 755 shebang_argument_trailing_space.sh
IyEvYmluL3NoIC0gCmVjaG8gIkhlbGxvIHdvcmxkIgo=
====
"
rm -f shebang_argument_trailing_space.sh

# Test case
testing "shebang with leading whitespace, argument and trailing whitespace" \
       "uudecode; sh -c './shebang_leading_argument_trailing_space.sh'; echo \$?" \
       "Hello world
0
" \
"" "\
begin-base64 755 shebang_leading_argument_trailing_space.sh
IyEvYmluL3NoICAtIAplY2hvICJIZWxsbyB3b3JsZCIK
====
"
rm -f shebang_leading_argument_trailing_space.sh

testing "sh remove CRs from string being evaluated" \
	"sh -c \"$(printf 'set -e\r\necho Hello world\r\n')\"" \
	"Hello world\n" "" ""

testing "sh preserve lone CRs during field splitting" \
	"sh input" \
	"Hello\r world\n" "echo \$(printf \"Hello\\\\r\\\\r\\\\nworld\\\\r\\\\n\")" ""

testing "sh read with CRLF" \
	"printf '1 2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
	"1 2\n" "" ""

testing "sh read with CR" \
	"printf '1\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
	"1\r2\n" "" ""

testing "sh read with \\CRLF" \
	"printf '1\\\\\r\\n2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
	"12\n" "" ""

testing "sh read with \\CR" \
	"printf '1\\\\\r2\\r\\n' | { read var; printf \"\${var}\\\\n\"; }" \
	"1\r2\n" "" ""
SKIP=

exit $FAILCOUNT