1#! /bin/sh
2#
3# @(#)bugs.sh	1.4 19/02/18 2017 J. Schilling
4#
5
6# Read test core functions
7. ../../common/test-common
8
9echo is_bosh: $is_bosh is_osh: $is_osh is_bourne: $is_bourne
10
11#
12# Basic tests to check for regression bugs
13#
14
15#
16# A bug from March 2017 caused the shell to clobber the strings "/dev/null"
17# when in -x mode. The reason was: _macro() does not reset staktop and thus
18# the next _macro() call will includ ethe previous expansion that was $PS4.
19#
20cat > x <<"XEOF"
21: ${ECHO=/usr/bin/does-not-exist}
22$ECHO 'bla' < /dev/null > /dev/null 2> /dev/null || ECHO=/bin/does-not-exist
23$ECHO 'bla' < /dev/null > /dev/null 2> /dev/null || ECHO=echo
24XEOF
25
26docommand -noremove bug01 "LC_ALL=C PS4=\"+ \" $SHELL -x ./x" 0 IGNORE NONEMPTY
27
28#
29# Bash adds stray spaces in the output :-(
30# We need to check with diff -w
31#
32if $is_bourne || $is_osh; then
33cat > expected <<"XEOF"
34+ : /usr/bin/does-not-exist
35+ /usr/bin/does-not-exist bla
36ECHO=/bin/does-not-exist
37+ /bin/does-not-exist bla
38ECHO=echo
39XEOF
40else
41cat > expected <<"XEOF"
42+ : /usr/bin/does-not-exist
43+ /usr/bin/does-not-exist bla
44+ ECHO=/bin/does-not-exist
45+ /bin/does-not-exist bla
46+ ECHO=echo
47XEOF
48fi
49diff -w expected got.stderr
50if [ $? != 0 ]; then
51	fail "Test $cmd_label failed: wrong error message"
52fi
53remove x expected
54do_remove
55
56#
57# A bug from June 2017 was triggered on Haiku because Haiku does not support
58# hard links. As a result, the mamagement of the shell /tmp/ files failed.
59# Bosh now copies the /tmp/ files in case that link() failes with other
60# than EEXIST
61#
62cat > x <<"XEOF"
63echo `(cat | cat) << EOF
641
652
663
67EOF
68`
69XEOF
70docommand bug02 "$SHELL ./x" 0 "1 2 3\n" ""
71
72remove x
73
74#
75# The next 8 tests check whether $? is affected by shared memory from vfork()
76# that has no workaround. The problem and the tests have been reported by
77# Martijn Dekker for MacOS and FreeBSD. The way we test here also hits the
78# related problem on Solaris.
79#
80docommand bug03 "$SHELL -c 'expr a \">\" b >/dev/null; echo \$?'" 0 "1\n" ""
81if $is_bourne || $is_osh; then
82	echo skipping bug04
83else
84docommand bug04 "$SHELL -c 'command expr a \">\" b >/dev/null; echo \$?'" 0 "1\n" ""
85fi
86
87docommand bug05 "$SHELL -c 'PATH=\"\$PATH:/usr/bin:/bin\" expr a \">\" b >/dev/null; echo \$?'" 0 "1\n" ""
88if $is_bourne || $is_osh; then
89	echo skipping bug06
90else
91docommand bug06 "$SHELL -c 'PATH=\"\$PATH:/usr/bin:/bin\" command expr a \">\" b >/dev/null; echo \$?'" 0 "1\n" ""
92fi
93
94remove b
95
96docommand -noremove bug07 "$SHELL -c 'expr  2>/dev/null; echo \$?'" 0 NONEMPTY ""
97expr `cat got.stdout` ">=" 2 > /dev/null
98if [ $? -ne 0 ]; then
99	fail "Test $cmd_label failed: wrong exit code"
100fi
101if $is_bourne || $is_osh; then
102	echo skipping bug08
103else
104docommand -noremove bug08 "$SHELL -c 'command expr  2>/dev/null; echo \$?'" 0 NONEMPTY ""
105expr `cat got.stdout` ">=" 2 > /dev/null
106if [ $? -ne 0 ]; then
107	fail "Test $cmd_label failed: wrong exit code"
108fi
109fi
110
111docommand -noremove bug09 "$SHELL -c 'PATH=\"\$PATH:/usr/bin:/bin\" expr  2>/dev/null; echo \$?'" 0 NONEMPTY ""
112expr `cat got.stdout` ">=" 2 > /dev/null
113if [ $? -ne 0 ]; then
114	fail "Test $cmd_label failed: wrong exit code"
115fi
116if $is_bourne || $is_osh; then
117	echo skipping bug10
118else
119docommand -noremove bug10 "$SHELL -c 'PATH=\"\$PATH:/usr/bin:/bin\" command expr  2>/dev/null; echo \$?'" 0 NONEMPTY ""
120expr `cat got.stdout` ">=" 2 > /dev/null
121if [ $? -ne 0 ]; then
122	fail "Test $cmd_label failed: wrong exit code"
123fi
124fi
125
126
127success
128