1 |
# |
2 |
|
3 |
#### 'exit' in oshrc (regression) |
4 |
cat >$TMP/oshrc <<EOF |
5 |
echo one |
6 |
exit 42 |
7 |
echo two |
8 |
EOF |
9 |
$SH --rcfile $TMP/oshrc -i -c 'echo hello' |
10 |
## status: 42 |
11 |
## STDOUT: |
12 |
one |
13 |
## END |
14 |
|
15 |
#### fatal errors continue |
16 |
# NOTE: tried here doc, but sys.stdin.isatty() fails. Could we fake it? |
17 |
$SH --rcfile /dev/null -i -c ' |
18 |
echo $(( 1 / 0 )) |
19 |
echo one |
20 |
exit 42 |
21 |
' |
22 |
## status: 42 |
23 |
## STDOUT: |
24 |
one |
25 |
## END |
26 |
|
27 |
#### interactive shell loads rcfile (when combined with -c) |
28 |
$SH -c 'echo 1' |
29 |
cat >$TMP/rcfile <<EOF |
30 |
echo RCFILE |
31 |
EOF |
32 |
$SH --rcfile $TMP/rcfile -i -c 'echo 2' |
33 |
## STDOUT: |
34 |
1 |
35 |
RCFILE |
36 |
2 |
37 |
## END |
38 |
|
39 |
#### interactive shell loads files in rcdir (when combined with -c) |
40 |
|
41 |
$SH -c 'echo A' |
42 |
|
43 |
cat >$TMP/rcfile <<EOF |
44 |
echo 'rcfile first' |
45 |
EOF |
46 |
|
47 |
mkdir -p $TMP/rcdir |
48 |
|
49 |
cat >$TMP/rcdir/file1 <<EOF |
50 |
echo rcdir 1 |
51 |
EOF |
52 |
|
53 |
cat >$TMP/rcdir/file2 <<EOF |
54 |
echo rcdir 2 |
55 |
EOF |
56 |
|
57 |
# --rcdir only |
58 |
$SH --rcdir $TMP/rcdir -i -c 'echo B' |
59 |
|
60 |
$SH --rcfile $TMP/rcfile --rcdir $TMP/rcdir -i -c 'echo C' |
61 |
|
62 |
## STDOUT: |
63 |
A |
64 |
rcdir 1 |
65 |
rcdir 2 |
66 |
B |
67 |
rcfile first |
68 |
rcdir 1 |
69 |
rcdir 2 |
70 |
C |
71 |
## END |
72 |
|
73 |
## N-I bash status: 2 |
74 |
## N-I bash STDOUT: |
75 |
A |
76 |
## END |
77 |
|
78 |
#### nonexistent --rcdir is ignored |
79 |
case $SH in bash) exit ;; esac |
80 |
|
81 |
$SH --rcdir $TMP/__does-not-exist -i -c 'echo hi' |
82 |
echo status=$? |
83 |
|
84 |
## STDOUT: |
85 |
hi |
86 |
status=0 |
87 |
## END |
88 |
## N-I bash STDOUT: |
89 |
## END |
90 |
|
91 |
#### shell doesn't load rcfile/rcdir if --norc is given |
92 |
|
93 |
$SH -c 'echo A' |
94 |
|
95 |
cat >$TMP/rcfile <<EOF |
96 |
echo rcfile |
97 |
EOF |
98 |
|
99 |
mkdir -p $TMP/rcdir |
100 |
cat >$TMP/rcdir/file1 <<EOF |
101 |
echo rcdir 1 |
102 |
EOF |
103 |
|
104 |
cat >$TMP/rcdir/file2 <<EOF |
105 |
echo rcdir 2 |
106 |
EOF |
107 |
|
108 |
$SH --norc --rcfile $TMP/rcfile -c 'echo C' |
109 |
case $SH in bash) exit ;; esac |
110 |
|
111 |
$SH --norc --rcfile $TMP/rcfile --rcdir $TMP/rcdir -c 'echo D' |
112 |
|
113 |
## STDOUT: |
114 |
A |
115 |
C |
116 |
D |
117 |
## END |
118 |
## OK bash STDOUT: |
119 |
A |
120 |
C |
121 |
## END |
122 |
|
123 |
|
124 |
#### interactive shell runs PROMPT_COMMAND after each command |
125 |
export PS1='' # OSH prints prompt to stdout |
126 |
|
127 |
case $SH in |
128 |
*bash|*osh) |
129 |
$SH --rcfile /dev/null -i << EOF |
130 |
PROMPT_COMMAND='echo PROMPT' |
131 |
echo one |
132 |
echo two |
133 |
EOF |
134 |
;; |
135 |
esac |
136 |
|
137 |
# Paper over difference with OSH |
138 |
case $SH in *bash) echo '^D';; esac |
139 |
|
140 |
## STDOUT: |
141 |
PROMPT |
142 |
one |
143 |
PROMPT |
144 |
two |
145 |
PROMPT |
146 |
^D |
147 |
## END |
148 |
|
149 |
|
150 |
#### parse error in PROMPT_COMMAND |
151 |
export PS1='' # OSH prints prompt to stdout |
152 |
|
153 |
case $SH in |
154 |
*bash|*osh) |
155 |
$SH --rcfile /dev/null -i << EOF |
156 |
PROMPT_COMMAND=';' |
157 |
echo one |
158 |
echo two |
159 |
EOF |
160 |
;; |
161 |
esac |
162 |
|
163 |
# Paper over difference with OSH |
164 |
case $SH in *bash) echo '^D';; esac |
165 |
|
166 |
## STDOUT: |
167 |
one |
168 |
two |
169 |
^D |
170 |
## END |
171 |
|
172 |
#### runtime error in PROMPT_COMMAND |
173 |
export PS1='' # OSH prints prompt to stdout |
174 |
|
175 |
case $SH in |
176 |
*bash|*osh) |
177 |
$SH --rcfile /dev/null -i << 'EOF' |
178 |
PROMPT_COMMAND='echo PROMPT $(( 1 / 0 ))' |
179 |
echo one |
180 |
echo two |
181 |
EOF |
182 |
;; |
183 |
esac |
184 |
|
185 |
# Paper over difference with OSH |
186 |
case $SH in *bash) echo '^D';; esac |
187 |
|
188 |
## STDOUT: |
189 |
one |
190 |
two |
191 |
^D |
192 |
## END |
193 |
|
194 |
#### Error message with bad oshrc file (currently ignored) |
195 |
cd $TMP |
196 |
echo 'foo >' > bad_oshrc |
197 |
|
198 |
$SH --rcfile bad_oshrc -i -c 'echo hi' 2>stderr.txt |
199 |
echo status=$? |
200 |
|
201 |
# bash prints two lines |
202 |
grep --max-count 1 -o 'bad_oshrc:' stderr.txt |
203 |
|
204 |
## STDOUT: |
205 |
hi |
206 |
status=0 |
207 |
bad_oshrc: |
208 |
## END |
209 |
|
210 |
|
211 |
#### PROMPT_COMMAND can see $?, like bash |
212 |
|
213 |
# bug fix #853 |
214 |
|
215 |
export PS1='' # OSH prints prompt to stdout |
216 |
|
217 |
case $SH in |
218 |
*bash|*osh) |
219 |
$SH --rcfile /dev/null -i << 'EOF' |
220 |
myfunc() { echo last_status=$?; } |
221 |
PROMPT_COMMAND='myfunc' |
222 |
( exit 42 ) |
223 |
( exit 43 ) |
224 |
echo ok |
225 |
EOF |
226 |
;; |
227 |
esac |
228 |
|
229 |
# Paper over difference with OSH |
230 |
case $SH in *bash) echo '^D';; esac |
231 |
## STDOUT: |
232 |
last_status=0 |
233 |
last_status=42 |
234 |
last_status=43 |
235 |
ok |
236 |
last_status=0 |
237 |
^D |
238 |
## END |
239 |
|
240 |
#### PROMPT_COMMAND that writes to BASH_REMATCH |
241 |
export PS1='' |
242 |
|
243 |
case $SH in |
244 |
*bash|*osh) |
245 |
$SH --rcfile /dev/null -i << 'EOF' |
246 |
PROMPT_COMMAND='[[ clobber =~ (.)(.)(.) ]]; echo ---' |
247 |
echo one |
248 |
[[ bar =~ (.)(.)(.) ]] |
249 |
echo ${BASH_REMATCH[@]} |
250 |
EOF |
251 |
;; |
252 |
esac |
253 |
|
254 |
# Paper over difference with OSH |
255 |
case $SH in *bash) echo '^D';; esac |
256 |
|
257 |
## STDOUT: |
258 |
--- |
259 |
one |
260 |
--- |
261 |
--- |
262 |
bar b a r |
263 |
--- |
264 |
^D |
265 |
## END |
266 |
## OK bash STDOUT: |
267 |
--- |
268 |
one |
269 |
--- |
270 |
--- |
271 |
clo c l o |
272 |
--- |
273 |
^D |
274 |
## END |
275 |
|
276 |
|
277 |
#### NO ASSERTIONS: Are startup files sourced before or after job control? |
278 |
|
279 |
cat >myrc <<'EOF' |
280 |
|
281 |
# from test/process-table-portable.sh |
282 |
PS_COLS='pid,ppid,pgid,sid,tpgid,comm' |
283 |
|
284 |
show-shell-state() { |
285 |
local prefix=$1 |
286 |
|
287 |
echo -n "$prefix: " |
288 |
|
289 |
echo "pid = $$" |
290 |
|
291 |
# Hm TPGID has changed in both OSH and bash |
292 |
# I guess that's because because ps itself becomes the leader of the process |
293 |
# group |
294 |
|
295 |
ps -o $PS_COLS $$ |
296 |
} |
297 |
|
298 |
show-shell-state myrc |
299 |
|
300 |
|
301 |
EOF |
302 |
|
303 |
$SH --rcfile myrc -i -c 'show-shell-state main' |
304 |
|
305 |
## status: 0 |
306 |
|
307 |
# No assertions |
308 |
# TODO: spec test framework should be expanded to properly support these |
309 |
# comparisons. |
310 |
# The --details flag is useful |
311 |
|