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

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