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

160 lines, 73 significant
1## compare_shells: bash dash mksh zsh ash
2## oils_failures_allowed: 5
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#### builtin cat crashes a subshell (#2530)
108
109((/usr/bin/cat </dev/zero; echo $? >&7) | true) 7>&1
110
111((cat </dev/zero; echo $? >&7) | true) 7>&1
112
113## STDOUT:
114141
115141
116## END
117
118#### test builtin: ( = ) is confusing: equality test or non-empty string test
119
120# here it's equality
121test '(' = ')'
122echo status=$?
123
124# here it's like -n =
125test 0 -eq 0 -a '(' = ')'
126echo status=$?
127
128## STDOUT:
129status=1
130status=0
131## END
132
133## BUG zsh STDOUT:
134status=0
135status=1
136## END
137
138#### test builtin: ( == ) is confusing: equality test or non-empty string test
139
140# here it's equality
141test '(' == ')'
142echo status=$?
143
144# here it's like -n ==
145test 0 -eq 0 -a '(' == ')'
146echo status=$?
147
148## STDOUT:
149status=1
150status=0
151## END
152
153## BUG dash STDOUT:
154status=0
155status=0
156## END
157
158## BUG-2 zsh status: 1
159## BUG-2 zsh STDOUT:
160## END