OILS / spec / divergence.test.sh View on Github | oils.pub

204 lines, 100 significant
1## compare_shells: bash dash mksh zsh ash
2## oils_failures_allowed: 4
3
4# This file relates to:
5#
6# - doc/known-differences.md
7# - "divergence" tag on github:
8# https://github.com/oils-for-unix/oils/issues?q=is%3Aissue%20state%3Aopen%20label%3Adivergence
9
10#### xz package: dirprefix="${line##*([}"
11
12# https://oilshell.zulipchat.com/#narrow/channel/502349-osh/topic/alpine.20xz.20-.20.22.24.7Bline.23.23*.28.5B.7D.22.20interpreted.20as.20extended.20glob/with/519718284
13
14# NOTE: spec/extglob-match shows that bash respects it
15#
16# echo 'strip ##' ${x##@(foo)}
17
18shopt -s extglob
19
20
21dirprefix="${line##*([}"
22echo "-$dirprefix-"
23
24# Now try with real data
25line='*([foo'
26dirprefix="${line##*([}"
27echo "-$dirprefix-"
28
29## STDOUT:
30--
31-foo-
32## END
33
34## N-I mksh/zsh status: 1
35## N-I mksh/zsh STDOUT:
36## END
37
38#### !( as negation and subshell versus extended glob - #2463
39
40have_icu_uc=false
41have_icu_i18n=false
42
43if !($have_icu_uc && $have_icu_i18n); then
44 echo one
45fi
46echo two
47
48## STDOUT:
49one
50two
51## END
52
53## BUG mksh STDOUT:
54two
55## END
56
57#### Changing PATH will invalidate PATH cache
58
59mkdir -p _tmp/bin
60mkdir -p _tmp/bin2
61printf '#!/usr/bin/env sh\necho hi\n' >_tmp/bin/hello
62printf '#!/usr/bin/env sh\necho hey\n' >_tmp/bin2/hello
63chmod +x _tmp/bin/hello
64chmod +x _tmp/bin2/hello
65
66BIN=$PWD/_tmp/bin
67BIN2=$PWD/_tmp/bin2
68
69# Will find _tmp/bin/hello
70PATH="$BIN:$PATH" hello
71echo status=$?
72
73# Should invalidate cache and then find _tmp/bin2/hello
74PATH="$BIN2:$PATH" hello
75echo status=$?
76
77# Same when PATH= and export PATH=
78PATH="$BIN:$PATH"
79hello
80echo status=$?
81PATH="$BIN2:$PATH"
82hello
83echo status=$?
84
85export PATH="$BIN:$PATH"
86hello
87echo status=$?
88export PATH="$BIN2:$PATH"
89hello
90echo status=$?
91
92## STDOUT:
93hi
94status=0
95hey
96status=0
97hi
98status=0
99hey
100status=0
101hi
102status=0
103hey
104status=0
105## END
106
107#### test builtin - Unexpected trailing word '--' (#2409)
108
109# Minimal repro of sqsh build error
110set -- -o; test $# -ne 0 -a "$1" != "--"
111echo status=$?
112
113# Now hardcode $1
114test $# -ne 0 -a "-o" != "--"
115echo status=$?
116
117# Remove quotes around -o
118test $# -ne 0 -a -o != "--"
119echo status=$?
120
121# How about a different flag?
122set -- -z; test $# -ne 0 -a "$1" != "--"
123echo status=$?
124
125# A non-flag?
126set -- z; test $# -ne 0 -a "$1" != "--"
127echo status=$?
128
129## STDOUT:
130status=0
131status=0
132status=0
133status=0
134status=0
135## END
136
137#### set -u failure in eval doesn't exit the parent process
138set -u
139test_function() {
140 x=$1
141}
142
143echo "before"
144eval test_function
145# bash spec says that set -u failures should exit the shell
146# posix spec says that eval shall read and execute a command by the current shell, so the
147# running shell should exit too
148echo "after"
149## status: 1
150## OK ash/dash status: 2
151## BUG mksh/zsh status: 0
152## STDOUT:
153before
154## END
155## BUG zsh/mksh STDOUT:
156before
157after
158## END
159
160#### set -u nested evals
161set -u
162test_function_2() {
163 x=$blarg
164}
165test_function() {
166 eval "test_function_2"
167}
168
169echo "before"
170eval test_function
171echo "after"
172## status: 1
173## OK ash/dash status: 2
174## BUG mksh/zsh status: 0
175## STDOUT:
176before
177## END
178## BUG zsh/mksh STDOUT:
179before
180after
181## END
182
183#### set -u no eval
184set -u
185
186echo "before"
187x=$blarg
188echo "after"
189## status: 1
190## OK ash/dash status: 2
191## STDOUT:
192before
193## END
194
195#### builtin cat crashes a subshell (#2530)
196
197((/usr/bin/cat </dev/zero; echo $? >&7) | true) 7>&1
198
199((cat </dev/zero; echo $? >&7) | true) 7>&1
200
201## STDOUT:
202141
203141
204## END