-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_test.sh
More file actions
executable file
·354 lines (292 loc) · 12.5 KB
/
unit_test.sh
File metadata and controls
executable file
·354 lines (292 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
EXE='FJ_Interpreter.exe' #executable of the interpreter of FJ
PARSER_ERR='### Parser Error ! ###'
##################
### CHECK TEST ###
##################
@test 'test for tests: quis custodiet ipsos custodies ?' { }
#####################
### PARSER ERRORS ###
#####################
@test 'parser error: "extend" instead of "extends" in class declaration' {
value=$(./$EXE <<< $'tests/parser_test1.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: parenthesis after class declaration (mistaken for a method)' {
value=$(./$EXE <<< $'tests/parser_test2.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: no comma between two parameters in a method' {
value=$(./$EXE <<< $'tests/parser_test3.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: no semicolon after field declaration' {
value=$(./$EXE <<< $'tests/parser_test4.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: double quotes after extends in class declaration' {
value=$(./$EXE <<< $'tests/parser_test5.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: class declaration without extends' {
value=$(./$EXE <<< $'tests/parser_test6.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: class mispelled in class declaration' {
value=$(./$EXE <<< $'tests/parser_test7.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: no class after extends in class declaration' {
value=$(./$EXE <<< $'tests/parser_test8.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: no curly bracket in class declaration' {
value=$(./$EXE <<< $'tests/parser_test9.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: no curly bracket in method declaration' {
value=$(./$EXE <<< $'tests/parser_test10.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: field name starts with a number' {
value=$(./$EXE <<< $'tests/parser_test11.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: class name starts with a number' {
value=$(./$EXE <<< $'tests/parser_test12.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: method body does not terminate with semicolon' {
value=$(./$EXE <<< $'tests/parser_test13.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: method does not contain keyword "return" in his body' {
value=$(./$EXE <<< $'tests/parser_test14.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: method with empty body' {
value=$(./$EXE <<< $'tests/parser_test15.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: class declaration without keyword class' {
value=$(./$EXE <<< $'tests/parser_test16.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: semicolon after class declaration' {
value=$(./$EXE <<< $'tests/parser_test17.txt' | tail -3 | head -1)
expected='### Parser Error ==> ;'
[ "$value" == "$expected" ]
}
@test 'parser error: new in field declaration' {
value=$(./$EXE <<< $'tests/parser_test18.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
@test 'parser error: method before fields' {
value=$(./$EXE <<< $'tests/parser_test19.txt' | tail -1)
expected=$PARSER_ERR
[ "$value" == "$expected" ]
}
##########################
### TYPECHECKER ERRORS ###
##########################
@test 'typechecker error: cyclic dependencies 4 classes' {
value=$(./$EXE <<< $'tests/typechecker_test1.txt' | tail -1)
expected='*** TypeException ==> Cyclic dependency between two types! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: mutual dependent classes' {
value=$(./$EXE <<< $'tests/typechecker_test2.txt' | tail -1)
expected='*** TypeException ==> Cyclic dependency between two types! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: two fields with the same name in class declaration' {
value=$(./$EXE <<< $'tests/typechecker_test3.txt' | tail -1)
expected='*** DuplicateFieldException ==> There are two fields with the same name in class A! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: two class with the same name in the program' {
value=$(./$EXE <<< $'tests/typechecker_test4.txt' | tail -1)
expected='*** DuplicateClassException ==> There are two classes with the same name: A! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: two variables with same identifier in a method' {
value=$(./$EXE <<< $'tests/typechecker_test5.txt' | tail -1)
expected='*** DuplicateVariableException ==> There are two params with the same name in method foo! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: type of a field does not exist' {
value=$(./$EXE <<< $'tests/typechecker_test6.txt' | tail -1)
expected='*** ClassNotFoundException ==> Type X does not exists! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: return type of a method does not exist' {
value=$(./$EXE <<< $'tests/typechecker_test7.txt' | tail -1)
expected='*** ClassNotFoundException ==> Type X not found! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: trying to redefine Object' {
value=$(./$EXE <<< $'tests/typechecker_test8.txt' | tail -1)
expected='*** DuplicateClassException ==> There are two classes with the same name: Object! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: return type does not match what declared' {
value=$(./$EXE <<< $'tests/typechecker_test9.txt' | tail -1)
expected='*** TypeException ==> Effective and declared return types are not compatible! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: two methods with the same name in the same class' {
value=$(./$EXE <<< $'tests/typechecker_test10.txt' | tail -1)
expected='*** DuplicateMethodException ==> There are two methods with the same name in class C! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: in class declaration extension of unknown class' {
value=$(./$EXE <<< $'tests/typechecker_test11.txt' | tail -1)
expected='*** ClassNotFoundException ==> Class X does not exist! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: variable not existent in method declaration' {
value=$(./$EXE <<< $'tests/typechecker_test12.txt' | tail -1)
expected='*** VariableNotFoundException ==> Variable y not found! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: overriding error, a parameter more in subclass method m' {
value=$(./$EXE <<< $'tests/typechecker_test13.txt' | tail -1)
expected='*** OverrideException ==> Methods with same name do not share same signature! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: overriding error, a parameter more in superclass method m' {
value=$(./$EXE <<< $'tests/typechecker_test14.txt' | tail -1)
expected='*** OverrideException ==> Methods with same name do not share same signature! ***'
[ "$value" == "$expected" ]
}
@test 'typechecker error: overriding error, different return type' {
value=$(./$EXE <<< $'tests/typechecker_test15.txt' | tail -1)
expected='*** OverrideException ==> Methods with same name do not share same signature! ***'
[ "$value" == "$expected" ]
}
##########################
### INTERPRETER ERRORS ###
##########################
@test 'runtime error: runtime exception of type ClassCastException' {
value=$(./$EXE <<< $'tests/interp_test.txt\n(F)(Object)new G()' | tail -1)
expected='*** ClassCastException ==> Cast not valid! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: method not found exception' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew F().foo()' | tail -1)
expected='*** MethodNotFoundException ==> Method foo not found! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: field not found exception' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew F().f' | tail -1)
expected='*** FieldNotFoundException ==> Field f not found! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: wrong type of a parameter' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew C(new B(new F(), new F())).changeB(new G())' | tail -1)
expected='*** MismatchParamsException ==> Type of params does not match! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: contructor with no parameter, pass a parameter' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew F(new Object())' | tail -1)
expected='*** MismatchParamsException ==> Params does not match! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: wrong number of parameters in contructor' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew B(new Object())' | tail -1)
expected='*** MismatchParamsException ==> Params does not match! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: creating an object of an unknown class' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew H()' | tail -1)
expected='*** ClassNotFoundException ==> Class H not found! ***'
[ "$value" == "$expected" ]
}
@test 'runtime error: overriding method with wrong number of parameters' {
value=$(./$EXE <<< $'tests/interp_test3.txt\nnew CPair(new D(), new D()).first.m(new Object())' | tail -1)
expected='*** MismatchParamsException ==> Params does not match! ***'
[ "$value" == "$expected" ]
}
##########################
### CORRECT EXECUTIONS ###
##########################
@test 'correct: sanity check, value = new F()' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew B(new F(), new G()).first()\n0' | tail -5 | head -1)
expected='new F([])'
[ "$value" == "$expected" ]
}
@test 'correct: field access, value = new G()' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew B(new F(), new G()).second()\n0' | tail -5 | head -1)
expected='new G([])'
[ "$value" == "$expected" ]
}
@test 'correct: method invocation, value = new B(new Object(), new Object())' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew B(new F(), new G()).freshB(new Object(), new Object())\n0' | tail -5 | head -1)
expected='new B([new Object([]),new Object([])])'
[ "$value" == "$expected" ]
}
@test 'correct: object creation, value = new A(new F(), new F(), new G())' {
value=$(./$EXE <<< $'tests/interp_test.txt\n(B)new A(new F(), new F(), new G())\n0' | tail -5 | head -1)
expected='new A([new F([]),new F([]),new G([])])'
[ "$value" == "$expected" ]
}
@test 'correct: field access, value = new G()' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew D(new G()).x\n0' | tail -5 | head -1)
expected='new G([])'
[ "$value" == "$expected" ]
}
@test 'correct: invoke method of superclass, value = new F()' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew A(new F(), new G(), new G()).first()\n0' | tail -5 | head -1)
expected='new F([])'
[ "$value" == "$expected" ]
}
@test 'correct: access field of the superclass, value = new G()' {
value=$(./$EXE <<< $'tests/interp_test.txt\nnew E(new G()).x\n0' | tail -5 | head -1)
expected='new G([])'
[ "$value" == "$expected" ]
}
@test 'correct: quite complex program, value = new F()' {
value=$(./$EXE <<< $'tests/interp_test.txt\n(F)new C(new B(new F(), new F())).changeB(new B(new F(), new F())).b.o1\n0' | tail -5 | head -1)
expected='new F([])'
[ "$value" == "$expected" ]
}
@test 'correct: importance of downcast, value = new B()' {
value=$(./$EXE <<< $'tests/interp_test2.txt\n((Pair)new Pair(new Pair(new A(), new B()), new A()).first).second\n0' | tail -5 | head -1)
expected='new B([])'
[ "$value" == "$expected" ]
}
@test 'correct: dynamic binding 1, value = new D()' {
value=$(./$EXE <<< $'tests/interp_test3.txt\nnew CPair(new D(), new C()).first.m()\n0' | tail -5 | head -1)
expected='new D([])'
[ "$value" == "$expected" ]
}
@test 'correct: dynamic binding 2, value = new C()' {
value=$(./$EXE <<< $'tests/interp_test3.txt\nnew CPair(new D(), new C()).second.m()\n0' | tail -5 | head -1)
expected='new C([])'
[ "$value" == "$expected" ]
}
#################
### MAIN TEST ###
#################
@test 'main error: input file not found' {
value=$(./$EXE <<< $'X' | tail -3 | head -1)
expected='ERROR ==> File X does not exist!'
[ "$value" == "$expected" ]
}