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

151 lines, 68 significant
1## our_shell: ysh
2## oils_failures_allowed: 1
3
4#### fastlex: NUL byte not allowed inside char literal #' '
5
6echo $'var x = #\'\x00\'; echo x=$x' > tmp.oil
7$SH tmp.oil
8
9echo $'var x = #\' ' > incomplete.oil
10$SH incomplete.oil
11
12## status: 2
13## STDOUT:
14## END
15
16#### fastlex: NUL byte inside shebang line
17
18# Hm this test doesn't really tickle the bug
19
20echo $'#! /usr/bin/env \x00 sh \necho hi' > tmp.oil
21env OILS_HIJACK_SHEBANG=1 $SH tmp.oil
22
23## STDOUT:
24hi
25## END
26
27#### Tea keywords don't interfere with YSH expressions
28
29var d = {data: 'foo'}
30
31echo $[d.data]
32
33var e = {enum: 1, class: 2, import: 3, const: 4, var: 5, set: 6}
34echo $[len(e)]
35
36## STDOUT:
37foo
386
39## END
40
41#### Catch AttributeError
42
43var s = 'foo'
44echo s=$s
45var t = s.bad()
46echo 'should not get here'
47
48## status: 3
49## STDOUT:
50s=foo
51## END
52
53
54#### Command sub paren parsing bug (#1387)
55
56write $(if (true) { write true })
57
58const a = $(write $[len('foo')])
59echo $a
60
61const b = $(write $[5 ** 3])
62echo $b
63
64const c = $(
65 write $[6 + 7]
66)
67echo $c
68
69## STDOUT:
70true
713
72125
7313
74## END
75
76
77#### More Command sub paren parsing
78
79write $( var mylist = ['for']; for x in (mylist) { echo $x } )
80
81write $( echo while; while (false) { write hi } )
82
83write $( if (true) { write 'if' } )
84
85write $( if (false) { write 'if' } elif (true) { write 'elif' } )
86
87## STDOUT:
88for
89while
90if
91elif
92## END
93
94#### don't execute empty command
95
96shopt --set ysh:all
97
98set -x
99
100try {
101 type -a ''
102}
103echo "type -a returned $_status"
104
105$(true)
106echo nope
107
108## status: 127
109## STDOUT:
110type -a returned 1
111## END
112
113
114#### && || with YSH constructs ?
115
116
117var x = []
118true && call x->append(42)
119false && call x->append(43)
120pp line (x)
121
122
123func amp() {
124 true && return (42)
125}
126
127func pipe() {
128 false || return (42)
129}
130
131pp line (amp())
132pp line (pipe())
133
134## STDOUT:
135## END
136
137
138#### shvar then replace - bug #1986 context manager crash
139
140shvar FOO=bar {
141 for x in (1 .. 500) {
142 var Q = "hello"
143 setvar Q = Q=>replace("hello","world")
144 }
145}
146echo $Q
147
148## STDOUT:
149world
150## END
151