OILS / spec / ysh-options-assign.test.sh View on Github | oilshell.org

106 lines, 58 significant
1#### OSH behavior
2x=1
3echo status=$?
4echo x=$x
5
6y = 2
7echo status=$?
8echo y=$y
9## STDOUT:
10status=0
11x=1
12status=127
13y=
14## END
15
16#### ysh:upgrade behavior
17shopt --set ysh:upgrade
18
19# allow errors
20set +o errexit +o nounset
21
22x=1
23echo status=$?
24echo x=$x
25
26y = 2
27echo status=$?
28echo y=$y
29## status: 2
30## STDOUT:
31status=0
32x=1
33## END
34
35#### x=y is allowed at the top level
36shopt --set ysh:all
37
38# allow errors
39set +o errexit +o nounset
40
41x=42
42echo status=$?
43echo x=$x
44
45y = 2 # fails because = is ambiguous
46echo status=$?
47echo y=$y
48
49## status: 2
50## STDOUT:
51status=0
52x=42
53## END
54
55
56#### parse_equals: allows bare assignment in Caps blocks
57shopt --set parse_proc parse_brace parse_equals
58
59proc Rule {
60 true
61}
62
63Rule {
64 x = 1 + 2*3
65}
66echo x=$x
67
68# still allowed since we didn't unset parse_sh_assign
69y=foo
70echo y=$y
71
72## STDOUT:
73x=
74y=foo
75## END
76
77#### bare assignment inside Hay blocks
78
79shopt --set ysh:all
80
81hay define Package
82
83# problem: we would allow it here, which is weird
84
85proc p {
86 var x = 42
87}
88
89cd /tmp {
90 var x = 'hi'
91}
92
93hay eval :result {
94 Package {
95 version = 1
96 }
97}
98
99var x = 1
100echo "x is $x"
101
102## STDOUT:
103x is 1
104## END
105
106