OILS / spec / command-parsing.test.sh View on Github | oilshell.org

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