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
|
10 | echo
|
11 |
|
12 | #### Command with args
|
13 | echo word word
|
14 |
|
15 | #### Command with trailer
|
16 | echo word word &
|
17 |
|
18 | #### a & b
|
19 | echo word_a & echo word_b
|
20 |
|
21 | #### a & b &
|
22 | echo word_a & echo word_b &
|
23 |
|
24 | #### a && b
|
25 | echo word_a && echo word_b
|
26 |
|
27 | #### a || b
|
28 | echo word_a || echo word_b
|
29 |
|
30 | #### a && b || c
|
31 | echo word_a && echo word_b || echo
|
32 |
|
33 | #### Invalid token
|
34 | invalid
|
35 | # TODO: change these to qualifiers!
|
36 | ## status: 99
|
37 |
|
38 | #### Filename Redirect
|
39 | echo 2>filename
|
40 |
|
41 | #### Append redirect
|
42 | echo >>filename
|
43 |
|
44 | #### Prefix redirect
|
45 | <filename echo
|
46 |
|
47 | #### Var assignment
|
48 | NAME=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;)
|
63 | echo
|
64 |
|
65 | #### Subshell on multiple lines
|
66 | (echo
|
67 | echo
|
68 | echo
|
69 | )
|
70 |
|
71 | #### For loop
|
72 | # TODO: need to add variables
|
73 | for name in word_a word_b word_c
|
74 | do
|
75 | echo word_x
|
76 | echo word_y
|
77 | done
|
78 |
|
79 | #### While loop with empty lines
|
80 | while ! echo word_a
|
81 | do
|
82 |
|
83 | echo word_b
|
84 |
|
85 | echo word_c
|
86 |
|
87 | done
|
88 |
|
89 | #### Until loop
|
90 | until echo word_a
|
91 | do
|
92 | echo word_b
|
93 | echo word_c
|
94 | done
|
95 |
|
96 | #### If
|
97 | if echo
|
98 | then
|
99 | echo
|
100 | else
|
101 | echo
|
102 | fi
|
103 |
|
104 | #### If with then on same line
|
105 | if echo; then
|
106 | echo
|
107 | else
|
108 | echo
|
109 | fi
|
110 |
|
111 | #### If with then on same line missing semicolon
|
112 | # My ANTLR parsers fail to flag this. The 'else' keyword should be unexpected.
|
113 | if echo then
|
114 | echo
|
115 | else
|
116 | echo
|
117 | fi
|
118 | ## status: 2
|
119 |
|
120 | #### If on one line
|
121 | if echo; then echo; else echo; fi
|
122 |
|
123 | #### If pipe
|
124 | if echo | echo word_b; then
|
125 | echo
|
126 | else
|
127 | echo
|
128 | fi
|
129 |
|
130 |
|
131 | #### Empty case
|
132 | case word_a in
|
133 | esac
|
134 |
|
135 | #### Case without last dsemi
|
136 | case word_a in
|
137 | word_b) echo
|
138 | esac
|
139 |
|
140 | #### Case with last dsemi
|
141 | case word_a in
|
142 | word_b) echo
|
143 | ;;
|
144 | esac
|
145 |
|
146 | #### Case with empty clauses
|
147 | case word_a in
|
148 | word_b)
|
149 | ;;
|
150 | word_c)
|
151 | esac
|
152 |
|
153 | #### case item without ;; is not allowed
|
154 | case word_a in
|
155 | word_a)
|
156 | word_b)
|
157 | echo
|
158 | ;;
|
159 | esac
|
160 | ## status: 99
|
161 |
|
162 |
|
163 | #### Case with last dsemi on same line
|
164 | case word_a in
|
165 | word_b) echo ;;
|
166 | esac
|
167 |
|
168 | #### Case with 2 options
|
169 | case 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 | ;;
|
177 | esac
|
178 |
|
179 | #### Case all on one line
|
180 | case word_a in word_b) echo ;; word_c) echo ;; esac
|
181 |
|
182 | #### Case all on one line without trailing ;;
|
183 | case 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.
|
187 | case word_a in word_b) echo word_b;; word_c) echo word_c esac
|
188 | ## status: 99
|
189 |
|
190 | #### case: Using ; instead of ;;
|
191 | case word_a in
|
192 | word_a)
|
193 | ;
|
194 | word_b)
|
195 | echo
|
196 | ;;
|
197 | esac
|
198 | ## status: 99
|
199 |
|
200 |
|
201 | #### Function def
|
202 | name_a() {
|
203 | echo word_a
|
204 | echo word_b
|
205 | }
|
206 |
|