]> ocean-lang.org Git - ocean/blob - csrc/scanner-tests.mdc
Remove excess blank lines
[ocean] / csrc / scanner-tests.mdc
1 # Scanner test code
2
3 The focus of these tests is coverage of the code in scanner.mdc
4 with the aim of being able to detect regressions.
5
6 We have a few different input files, and scan each with a variety
7 of different setting and ensure the output is as expected.
8
9 The inputs are in sectoins called "test: name" and the expected
10 outputs are in "test: name,arg,arg,arg".  As we cannot (yet)
11 extract a list of section names, we need to tell the make script
12 about each test.
13
14 ###### File: scanner-tests.mk
15
16         scanner_tests :=
17         ## test list
18
19         tests:: scanner_test_suite
20         scanner_test_suite : md2c coverage_scanner
21                 @rm -rf coverage; mkdir -p coverage
22                 @cp *.gcno coverage
23                 @for T in $(scanner_tests); do \
24                     echo -n "Tests $$T ... ";  \
25                     i="$IFS"; IFS=,; set $$T; IFS="$$i"; t=$$1; shift; \
26                     ./md2c scanner-tests.mdc "output: $$T" | grep -v '^#' > .tmp.want; \
27                     echo '~~~~~~~' > .tmp.code ;\
28                     ./md2c scanner-tests.mdc "test: $$t" | grep -v '^#' >> .tmp.code; \
29                     ./coverage_scanner --file .tmp.code $${1+"$$@"} > .tmp.have; \
30                     if ! cmp -s .tmp.want .tmp.have; then \
31                         echo "FAILED"; diff -u .tmp.want .tmp.have; exit 1; fi ; \
32                     echo "PASSED"; \
33                 done
34
35                 @gcov -o coverage scanner.c libscanner.c > /dev/null 2> /dev/null
36                 @mv *.gcov coverage; [ -f .gcov ] && mv .gcov coverage || true
37                 @awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
38                     END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
39                          if (ran < (ran + skip) *0.90) exit(1) }' \
40                         coverage/scanner.mdc.gcov
41                 @rm -f .tmp*
42
43         coverage_scanner: scanner.c libscanner.c
44                 $(CC) $(CFLAGS) --coverage -fprofile-dir=coverage -o coverage_scanner \
45                         scanner.c libscanner.c \
46                         libmdcode.o libnumber.o libstring.o -licuuc -lgmp
47
48 ## Basic tests
49
50 Some simple tests... maybe all tests are simple.
51
52 ###### test list
53         scanner_tests += "test1,if,then,+,-"
54         scanner_tests += "test1,if,then,+,-,/"
55         scanner_tests += "test1,--ignore-indent,if,then,+,-,/"
56         scanner_tests += "test1,--ignore-indent,--ignore-newline,if,then,+,-,/"
57         scanner_tests += "test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/"
58         scanner_tests += "test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/"
59
60 ###### test: test1
61
62         A B C
63           D E
64            F G
65          H
66         I
67
68         A
69           B
70             C
71             D
72           E
73         F
74           G
75         H
76
77         if else then fi while
78         1234,  1.234 -123.456e45
79         0x1234 +  0x543p+3
80         "This is a string" &"so is this"a
81         a = """
82            This is a multi-
83            line string that
84            has three lines
85            """bb
86         I think # some comments are like this
87         and // some are like this
88         and some /* can go
89         over multiplt
90         lines */
91         divident /+ divisor
92
93 ###### output: test1,if,then,+,-
94         Tokenizing: 
95         2:0 ident(A)
96         2:2 ident(B)
97         2:4 ident(C)
98         3:2 in()
99         3:2 ident(D)
100         3:4 ident(E)
101         4:3 in()
102         4:3 ident(F)
103         4:5 ident(G)
104         5:1 newline()
105         5:1 out()
106         5:1 newline()
107         5:1 out()
108         5:1 in()
109         5:1 ident(H)
110         6:0 newline()
111         6:0 out()
112         6:0 newline()
113         6:0 ident(I)
114         8:0 newline()
115         8:0 newline()
116         8:0 ident(A)
117         9:2 in()
118         9:2 ident(B)
119         10:4 in()
120         10:4 ident(C)
121         11:4 newline()
122         11:4 ident(D)
123         12:2 newline()
124         12:2 out()
125         12:2 newline()
126         12:2 ident(E)
127         13:0 newline()
128         13:0 out()
129         13:0 newline()
130         13:0 ident(F)
131         14:2 in()
132         14:2 ident(G)
133         15:0 newline()
134         15:0 out()
135         15:0 newline()
136         15:0 ident(H)
137         17:0 newline()
138         17:0 newline()
139         17:0 if
140         17:3 ident(else)
141         17:8 then
142         17:13 ident(fi)
143         17:16 ident(while)
144         18:0 newline()
145         18:0 number(1234)  1234
146         18:4 mark(,)
147         18:7 number(1.234 )  617/500
148         18:13 -
149         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
150         19:0 newline()
151         19:0 number(0x1234 )  4660
152         19:7 +
153         19:10 number(0x543p+3)  10776
154         20:0 newline()
155         20:0 string("This is a string")  This is a string
156         20:19 mark(&)
157         20:20 string("so is this"a) a so is this
158         21:0 newline()
159         21:0 ident(a)
160         21:2 mark(=)
161         21:4 mstring("""\x0a   This is a m..) bb This is a multi-\x0al..
162         26:0 newline()
163         26:0 ident(I)
164         26:2 ident(think)
165         26:8 lcomment(# some comments ar..)
166         27:0 newline()
167         27:0 ident(and)
168         27:4 lcomment(// some are like t..)
169         28:0 newline()
170         28:0 ident(and)
171         28:4 ident(some)
172         28:9 bcomment(/* can go\x0aover mul..)
173         31:0 newline()
174         31:0 ident(divident)
175         31:9 mark(/+)
176         31:12 ident(divisor)
177         32:0 newline()
178         32:0 eof()
179
180 ###### output: test1,if,then,+,-,/
181         Tokenizing: 
182         2:0 ident(A)
183         2:2 ident(B)
184         2:4 ident(C)
185         3:2 in()
186         3:2 ident(D)
187         3:4 ident(E)
188         4:3 in()
189         4:3 ident(F)
190         4:5 ident(G)
191         5:1 newline()
192         5:1 out()
193         5:1 newline()
194         5:1 out()
195         5:1 in()
196         5:1 ident(H)
197         6:0 newline()
198         6:0 out()
199         6:0 newline()
200         6:0 ident(I)
201         8:0 newline()
202         8:0 newline()
203         8:0 ident(A)
204         9:2 in()
205         9:2 ident(B)
206         10:4 in()
207         10:4 ident(C)
208         11:4 newline()
209         11:4 ident(D)
210         12:2 newline()
211         12:2 out()
212         12:2 newline()
213         12:2 ident(E)
214         13:0 newline()
215         13:0 out()
216         13:0 newline()
217         13:0 ident(F)
218         14:2 in()
219         14:2 ident(G)
220         15:0 newline()
221         15:0 out()
222         15:0 newline()
223         15:0 ident(H)
224         17:0 newline()
225         17:0 newline()
226         17:0 if
227         17:3 ident(else)
228         17:8 then
229         17:13 ident(fi)
230         17:16 ident(while)
231         18:0 newline()
232         18:0 number(1234)  1234
233         18:4 mark(,)
234         18:7 number(1.234 )  617/500
235         18:13 -
236         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
237         19:0 newline()
238         19:0 number(0x1234 )  4660
239         19:7 +
240         19:10 number(0x543p+3)  10776
241         20:0 newline()
242         20:0 string("This is a string")  This is a string
243         20:19 mark(&)
244         20:20 string("so is this"a) a so is this
245         21:0 newline()
246         21:0 ident(a)
247         21:2 mark(=)
248         21:4 mstring("""\x0a   This is a m..) bb This is a multi-\x0al..
249         26:0 newline()
250         26:0 ident(I)
251         26:2 ident(think)
252         26:8 lcomment(# some comments ar..)
253         27:0 newline()
254         27:0 ident(and)
255         27:4 lcomment(// some are like t..)
256         28:0 newline()
257         28:0 ident(and)
258         28:4 ident(some)
259         28:9 bcomment(/* can go\x0aover mul..)
260         31:0 newline()
261         31:0 ident(divident)
262         31:9 /
263         31:10 +
264         31:12 ident(divisor)
265         32:0 newline()
266         32:0 eof()
267
268 ###### output: test1,--ignore-indent,if,then,+,-,/
269         Tokenizing: 
270         2:0 ident(A)
271         2:2 ident(B)
272         2:4 ident(C)
273         2:5 newline()
274         3:2 ident(D)
275         3:4 ident(E)
276         3:5 newline()
277         4:3 ident(F)
278         4:5 ident(G)
279         4:6 newline()
280         5:1 ident(H)
281         5:2 newline()
282         6:0 ident(I)
283         6:1 newline()
284         7:0 newline()
285         8:0 ident(A)
286         8:1 newline()
287         9:2 ident(B)
288         9:3 newline()
289         10:4 ident(C)
290         10:5 newline()
291         11:4 ident(D)
292         11:5 newline()
293         12:2 ident(E)
294         12:3 newline()
295         13:0 ident(F)
296         13:1 newline()
297         14:2 ident(G)
298         14:3 newline()
299         15:0 ident(H)
300         15:1 newline()
301         16:0 newline()
302         17:0 if
303         17:3 ident(else)
304         17:8 then
305         17:13 ident(fi)
306         17:16 ident(while)
307         17:21 newline()
308         18:0 number(1234)  1234
309         18:4 mark(,)
310         18:7 number(1.234 )  617/500
311         18:13 -
312         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
313         18:24 newline()
314         19:0 number(0x1234 )  4660
315         19:7 +
316         19:10 number(0x543p+3)  10776
317         19:18 newline()
318         20:0 string("This is a string")  This is a string
319         20:19 mark(&)
320         20:20 string("so is this"a) a so is this
321         20:33 newline()
322         21:0 ident(a)
323         21:2 mark(=)
324         21:4 mstring("""\x0a   This is a m..) bb This is a multi-\x0al..
325         25:8 newline()
326         26:0 ident(I)
327         26:2 ident(think)
328         26:8 lcomment(# some comments ar..)
329         26:37 newline()
330         27:0 ident(and)
331         27:4 lcomment(// some are like t..)
332         27:25 newline()
333         28:0 ident(and)
334         28:4 ident(some)
335         28:9 bcomment(/* can go\x0aover mul..)
336         30:8 newline()
337         31:0 ident(divident)
338         31:9 /
339         31:10 +
340         31:12 ident(divisor)
341         31:19 newline()
342         32:0 eof()
343
344 ###### output: test1,--ignore-indent,--ignore-newline,if,then,+,-,/
345         Tokenizing: 
346         2:0 ident(A)
347         2:2 ident(B)
348         2:4 ident(C)
349         3:2 ident(D)
350         3:4 ident(E)
351         4:3 ident(F)
352         4:5 ident(G)
353         5:1 ident(H)
354         6:0 ident(I)
355         8:0 ident(A)
356         9:2 ident(B)
357         10:4 ident(C)
358         11:4 ident(D)
359         12:2 ident(E)
360         13:0 ident(F)
361         14:2 ident(G)
362         15:0 ident(H)
363         17:0 if
364         17:3 ident(else)
365         17:8 then
366         17:13 ident(fi)
367         17:16 ident(while)
368         18:0 number(1234)  1234
369         18:4 mark(,)
370         18:7 number(1.234 )  617/500
371         18:13 -
372         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
373         19:0 number(0x1234 )  4660
374         19:7 +
375         19:10 number(0x543p+3)  10776
376         20:0 string("This is a string")  This is a string
377         20:19 mark(&)
378         20:20 string("so is this"a) a so is this
379         21:0 ident(a)
380         21:2 mark(=)
381         21:4 mstring("""\x0a   This is a m..) bb This is a multi-\x0al..
382         26:0 ident(I)
383         26:2 ident(think)
384         26:8 lcomment(# some comments ar..)
385         27:0 ident(and)
386         27:4 lcomment(// some are like t..)
387         28:0 ident(and)
388         28:4 ident(some)
389         28:9 bcomment(/* can go\x0aover mul..)
390         31:0 ident(divident)
391         31:9 /
392         31:10 +
393         31:12 ident(divisor)
394         32:0 eof()
395
396 ###### output: test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/
397         Tokenizing: 
398         2:0 ident(A)
399         2:2 ident(B)
400         2:4 ident(C)
401         3:2 ident(D)
402         3:4 ident(E)
403         4:3 ident(F)
404         4:5 ident(G)
405         5:1 ident(H)
406         6:0 ident(I)
407         8:0 ident(A)
408         9:2 ident(B)
409         10:4 ident(C)
410         11:4 ident(D)
411         12:2 ident(E)
412         13:0 ident(F)
413         14:2 ident(G)
414         15:0 ident(H)
415         17:0 if
416         17:3 ident(else)
417         17:8 then
418         17:13 ident(fi)
419         17:16 ident(while)
420         18:0 number(1234)  1234
421         18:4 mark(,)
422         18:7 number(1.234 )  617/500
423         18:13 -
424         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
425         19:0 number(0x1234 )  4660
426         19:7 +
427         19:10 number(0x543p+3)  10776
428         20:0 string("This is a string")  This is a string
429         20:19 mark(&)
430         20:20 string("so is this"a) a so is this
431         21:0 ident(a)
432         21:2 mark(=)
433         21:4 mstring("""\x0a   This is a m..) bb This is a multi-\x0al..
434         26:0 ident(I)
435         26:2 ident(think)
436         27:0 ident(and)
437         28:0 ident(and)
438         28:4 ident(some)
439         31:0 ident(divident)
440         31:9 /
441         31:10 +
442         31:12 ident(divisor)
443         32:0 eof()
444
445 ###### output: test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/
446         Tokenizing: 
447         2:0 ident(A)
448         2:2 ident(B)
449         2:4 ident(C)
450         3:2 ident(D)
451         3:4 ident(E)
452         4:3 ident(F)
453         4:5 ident(G)
454         5:1 ident(H)
455         6:0 ident(I)
456         8:0 ident(A)
457         9:2 ident(B)
458         10:4 ident(C)
459         11:4 ident(D)
460         12:2 ident(E)
461         13:0 ident(F)
462         14:2 ident(G)
463         15:0 ident(H)
464         17:0 if
465         17:3 ident(else)
466         17:8 then
467         17:13 ident(fi)
468         17:16 ident(while)
469         18:0 number(1234)  1234
470         18:4 mark(,)
471         18:7 number(1.234 )  617/500
472         18:13 -
473         18:14 number(123.456e45)  123456000000000000000000000000000000000000000000
474         19:0 number(0x1234 )  4660
475         19:7 +
476         19:10 number(0x543p+3)  10776
477         20:0 mark(")
478         20:1 ident(This)
479         20:6 ident(is)
480         20:9 ident(a)
481         20:11 ident(string)
482         20:17 mark(")
483         20:19 mark(&")
484         20:21 ident(so)
485         20:24 ident(is)
486         20:27 ident(this)
487         20:31 mark(")
488         20:32 ident(a)
489         21:0 ident(a)
490         21:2 mark(=)
491         21:4 mark(""")
492         22:3 ident(This)
493         22:8 ident(is)
494         22:11 ident(a)
495         22:13 ident(multi)
496         22:18 -
497         23:3 ident(line)
498         23:8 ident(string)
499         23:15 ident(that)
500         24:3 ident(has)
501         24:7 ident(three)
502         24:13 ident(lines)
503         25:3 mark(""")
504         25:6 ident(bb)
505         26:0 ident(I)
506         26:2 ident(think)
507         27:0 ident(and)
508         28:0 ident(and)
509         28:4 ident(some)
510         31:0 ident(divident)
511         31:9 /
512         31:10 +
513         31:12 ident(divisor)
514         32:0 eof()
515
516 ## Error tests
517
518 Now to test for some errors ... though things I thought would be errors
519 sometimes aren't.
520
521 ###### test list
522         scanner_tests += "errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-"
523         scanner_tests += "errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-"
524
525 ###### test: errtest
526
527         multiple decimal pointer 3.141.59
528         "Check for decimal commas" 3,14159 = 3,141,59
529         """A multi-string must not have text here
530         """
531         "or after close" + """
532                 no text ..
533                 """ here
534
535         /* No embedded /* comments */ in comments */
536         /* or content after
537          * a multiline comment */ Error
538
539         "  \\ \t \n special chars in strings"
540
541 ###### output: errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-
542
543         Tokenizing: 
544         2:0 ERROR(multiple)
545         2:9 ERROR(decimal)
546         2:17 ERROR(pointer)
547         2:25 number(3.141)  3141/1000
548         2:30 ERROR(.)
549         2:31 number(59)  59
550         3:0 newline()
551         3:0 string("Check for decimal..)  Check for decimal ..
552         3:27 number(3,14159)  314159/100000
553         3:35 ERROR(=)
554         3:37 number(3,141)  3141/1000
555         3:42 ERROR(,)
556         3:43 number(59)  59
557         4:0 newline()
558         4:0 string("")  
559         4:2 ERROR("A multi-string mu..)
560         5:0 newline()
561         5:0 ERROR("""\x0a"or after clos..)
562         8:12 ERROR(here)
563         10:0 newline()
564         10:0 newline()
565         10:0 ERROR(/* No embedded /*)
566         10:15 bcomment(/* comments */)
567         10:30 ERROR(in)
568         10:33 ERROR(comments)
569         10:42 ERROR(*/)
570         11:0 newline()
571         11:0 ERROR(/* or content afte..)
572         12:26 ERROR(Error)
573         14:0 newline()
574         14:0 newline()
575         14:0 string("  \\\\ \\t \\n specia..)    \\ \x09 \x0a special ch..
576         15:0 newline()
577         15:0 eof()
578
579 ###### output: errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-
580         Tokenizing: 
581         2:0 ERROR(multiple)
582         2:9 ERROR(decimal)
583         2:17 ERROR(pointer)
584         2:25 ERROR(3)
585         2:26 ERROR(.)
586         2:27 ERROR(1)
587         2:28 ERROR(4)
588         2:29 ERROR(1)
589         2:30 ERROR(.)
590         2:31 ERROR(5)
591         2:32 ERROR(9)
592         3:0 newline()
593         3:0 string("Check for decimal..)  Check for decimal ..
594         3:27 ERROR(3)
595         3:28 ERROR(,)
596         3:29 ERROR(1)
597         3:30 ERROR(4)
598         3:31 ERROR(1)
599         3:32 ERROR(5)
600         3:33 ERROR(9)
601         3:35 ERROR(=)
602         3:37 ERROR(3)
603         3:38 ERROR(,)
604         3:39 ERROR(1)
605         3:40 ERROR(4)
606         3:41 ERROR(1)
607         3:42 ERROR(,)
608         3:43 ERROR(5)
609         3:44 ERROR(9)
610         4:0 newline()
611         4:0 string("")  
612         4:2 ERROR("A multi-string mu..)
613         5:0 newline()
614         5:0 ERROR("""\x0a"or after clos..)
615         8:12 ERROR(here)
616         10:0 newline()
617         10:0 newline()
618         10:0 ERROR(/* No embedded /*)
619         10:15 bcomment(/* comments */)
620         10:30 ERROR(in)
621         10:33 ERROR(comments)
622         10:42 ERROR(*/)
623         11:0 newline()
624         11:0 ERROR(/* or content afte..)
625         12:26 ERROR(Error)
626         14:0 newline()
627         14:0 newline()
628         14:0 string("  \\\\ \\t \\n specia..)    \\ \x09 \x0a special ch..
629         15:0 newline()
630         15:0 eof()