OILS / spec / shell-grammar.test.sh View on Github | oilshell.org

206 lines, 106 significant
1# Test cases for the grammar. It uses pidgin shell because we don't have a
2# proper lexer in ANTLR (ANTLR's lexers don't have states anyway.)
3#
4# These tests should run under the normal shell. But REAL shel tests won't run
5# under the fake shells grammar/shell*.sh
6
7## suite: disabled
8
9#### Simple command
10echo
11
12#### Command with args
13echo word word
14
15#### Command with trailer
16echo word word &
17
18#### a & b
19echo word_a & echo word_b
20
21#### a & b &
22echo word_a & echo word_b &
23
24#### a && b
25echo word_a && echo word_b
26
27#### a || b
28echo word_a || echo word_b
29
30#### a && b || c
31echo word_a && echo word_b || echo
32
33#### Invalid token
34invalid
35# TODO: change these to qualifiers!
36## status: 99
37
38#### Filename Redirect
39echo 2>filename
40
41#### Append redirect
42echo >>filename
43
44#### Prefix redirect
45<filename echo
46
47#### Var assignment
48NAME=foo echo >>filename
49
50#### Brace group
51{ echo
52 echo
53}
54
55#### Brace group on oneline
56{ echo word_a; echo word_b; }
57
58#### Subshell
59(echo word_a; echo word_b;)
60
61#### Command sub
62#echo $(echo word_a; echo word_b;)
63echo
64
65#### Subshell on multiple lines
66(echo
67echo
68echo
69)
70
71#### For loop
72# TODO: need to add variables
73for name in word_a word_b word_c
74do
75 echo word_x
76 echo word_y
77done
78
79#### While loop with empty lines
80while ! echo word_a
81do
82
83 echo word_b
84
85 echo word_c
86
87done
88
89#### Until loop
90until echo word_a
91do
92 echo word_b
93 echo word_c
94done
95
96#### If
97if echo
98then
99 echo
100else
101 echo
102fi
103
104#### If with then on same line
105if echo; then
106 echo
107else
108 echo
109fi
110
111#### If with then on same line missing semicolon
112# My ANTLR parsers fail to flag this. The 'else' keyword should be unexpected.
113if echo then
114 echo
115else
116 echo
117fi
118## status: 2
119
120#### If on one line
121if echo; then echo; else echo; fi
122
123#### If pipe
124if echo | echo word_b; then
125 echo
126else
127 echo
128fi
129
130
131#### Empty case
132case word_a in
133esac
134
135#### Case without last dsemi
136case word_a in
137 word_b) echo
138esac
139
140#### Case with last dsemi
141case word_a in
142 word_b) echo
143 ;;
144esac
145
146#### Case with empty clauses
147case word_a in
148 word_b)
149 ;;
150 word_c)
151esac
152
153#### case item without ;; is not allowed
154case word_a in
155 word_a)
156 word_b)
157 echo
158 ;;
159esac
160## status: 99
161
162
163#### Case with last dsemi on same line
164case word_a in
165 word_b) echo ;;
166esac
167
168#### Case with 2 options
169case word_a in
170 word_b|word_c)
171 echo word_d
172 echo word_e
173 ;;
174 word_e)
175 echo word_f
176 ;;
177esac
178
179#### Case all on one line
180case word_a in word_b) echo ;; word_c) echo ;; esac
181
182#### Case all on one line without trailing ;;
183case word_a in word_b) echo word_b;; word_c) echo word_c; esac
184
185#### Case all on one line without trailing ;; or ;
186# My ANTLR parsers don't fail here and they should.
187case word_a in word_b) echo word_b;; word_c) echo word_c esac
188## status: 99
189
190#### case: Using ; instead of ;;
191case word_a in
192 word_a)
193 ;
194 word_b)
195 echo
196 ;;
197esac
198## status: 99
199
200
201#### Function def
202name_a() {
203 echo word_a
204 echo word_b
205}
206