OILS / spec / command-parsing.test.sh View on Github | oils.pub

65 lines, 30 significant
1## compare_shells: dash bash mksh
2## legacy_tmp_dir: yes
3
4# Some nonsensical combinations which can all be detected at PARSE TIME.
5# All shells allow these, but right now OSH disallowed.
6# TODO: Run the parser on your whole corpus, and then if there are no errors,
7# you should make OSH the OK behavior, and others are OK.
8
9#### Prefix env on assignment
10f() {
11 # NOTE: local treated like a special builtin!
12 E=env local v=var
13 echo $E $v
14}
15f
16## status: 0
17## stdout: env var
18## OK bash stdout: var
19
20#### Redirect on assignment (enabled 7/2019)
21f() {
22 # NOTE: local treated like a special builtin!
23 local E=env > _tmp/r.txt
24}
25rm -f _tmp/r.txt
26f
27test -f _tmp/r.txt && echo REDIRECTED
28## status: 0
29## stdout: REDIRECTED
30
31#### Prefix env on control flow
32for x in a b c; do
33 echo $x
34 E=env break
35done
36## status: 0
37## stdout: a
38## OK osh status: 2
39## OK osh stdout-json: ""
40
41#### Redirect on control flow (ignored in OSH)
42rm -f _tmp/r.txt
43for x in a b c; do
44 break > _tmp/r.txt
45done
46if test -f _tmp/r.txt; then
47 echo REDIRECTED
48else
49 echo NO
50fi
51## status: 0
52## stdout: REDIRECTED
53## OK osh stdout: NO
54
55#### Redirect on control flow with oil:all (parse_ignored)
56shopt -s oil:all
57rm -f _tmp/r.txt
58for x in a b c; do
59 break > _tmp/r.txt
60done
61test -f _tmp/r.txt && echo REDIRECTED
62## status: 0
63## stdout: REDIRECTED
64## OK osh status: 2
65## OK osh stdout-json: ""