3 The focus of these tests is coverage of the code in scanner.mdc
4 with the aim of being able to detect regressions.
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.
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
14 ###### File: scanner-tests.mk
19 tests:: scanner_test_suite
20 scanner_test_suite : md2c coverage_scanner
21 @rm -rf coverage; mkdir -p 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 ; \
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
43 coverage_scanner: scanner.c libscanner.c libmdcode.o libnumber.o libstring.o
44 $(CC) $(CFLAGS) --coverage -fprofile-dir=coverage -o coverage_scanner \
45 scanner.c libscanner.c \
46 libmdcode.o libnumber.o libstring.o -licuuc -lgmp
50 Some simple tests... maybe all tests are simple.
51 Include a special test for numbers, as they are interesting.
54 scanner_tests += "test1,if,then,+,-"
55 scanner_tests += "test1,if,then,+,-,/"
56 scanner_tests += "test1,--ignore-indent,if,then,+,-,/"
57 scanner_tests += "test1,--ignore-indent,--ignore-newline,if,then,+,-,/"
58 scanner_tests += "test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/"
59 scanner_tests += "test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/"
79 1234, 1.234 -123.456e45
81 "This is a string" &"so is this"a
87 I think # some comments are like this
88 and // some are like this
94 ###### output: test1,if,then,+,-
146 18:0 number(1234) 1234
148 18:7 number(1.234) 617/500
150 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
152 19:0 number(0x1234) 4660
154 19:10 number(0x543p+3) 10776
156 20:0 string("This is a string") This is a string
158 20:20 string("so is this"a) a so is this
162 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
166 26:8 lcomment(# some comments ar..)
169 27:4 lcomment(// some are like t..)
173 28:9 bcomment(/* can go\x0aover mul..)
181 ###### output: test1,if,then,+,-,/
233 18:0 number(1234) 1234
235 18:7 number(1.234) 617/500
237 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
239 19:0 number(0x1234) 4660
241 19:10 number(0x543p+3) 10776
243 20:0 string("This is a string") This is a string
245 20:20 string("so is this"a) a so is this
249 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
253 26:8 lcomment(# some comments ar..)
256 27:4 lcomment(// some are like t..)
260 28:9 bcomment(/* can go\x0aover mul..)
269 ###### output: test1,--ignore-indent,if,then,+,-,/
309 18:0 number(1234) 1234
311 18:7 number(1.234) 617/500
313 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
315 19:0 number(0x1234) 4660
317 19:10 number(0x543p+3) 10776
319 20:0 string("This is a string") This is a string
321 20:20 string("so is this"a) a so is this
325 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
329 26:8 lcomment(# some comments ar..)
332 27:4 lcomment(// some are like t..)
336 28:9 bcomment(/* can go\x0aover mul..)
345 ###### output: test1,--ignore-indent,--ignore-newline,if,then,+,-,/
369 18:0 number(1234) 1234
371 18:7 number(1.234) 617/500
373 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
374 19:0 number(0x1234) 4660
376 19:10 number(0x543p+3) 10776
377 20:0 string("This is a string") This is a string
379 20:20 string("so is this"a) a so is this
382 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
385 26:8 lcomment(# some comments ar..)
387 27:4 lcomment(// some are like t..)
390 28:9 bcomment(/* can go\x0aover mul..)
397 ###### output: test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/
421 18:0 number(1234) 1234
423 18:7 number(1.234) 617/500
425 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
426 19:0 number(0x1234) 4660
428 19:10 number(0x543p+3) 10776
429 20:0 string("This is a string") This is a string
431 20:20 string("so is this"a) a so is this
434 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
446 ###### output: test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/
470 18:0 number(1234) 1234
472 18:7 number(1.234) 617/500
474 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
475 19:0 number(0x1234) 4660
477 19:10 number(0x543p+3) 10776
518 scanner_tests += "testnum"
534 "Now for some non-number"
546 ###### output: testnum
548 2:0 number(12345) 12345
550 3:0 number(1234.56) 30864/25
552 4:0 number(1234.56e7) 12345600000
554 5:0 number(1234.56e-7) 1929/15625000
556 6:0 number(0x1234) 4660
558 7:0 number(0x123,456) 596523/2048
560 8:0 number(0o777) 511
562 9:0 number(0o111.111p4) 37449/32
564 10:0 number(0b11011110p3) 1776
567 12:0 number(123 456 789) 123456789
569 13:0 number(0x1234_5678_9abc) 20015998343868
572 15:0 string("Now for some non-..) Now for some non-n..
574 16:0 number(1234p4) BAD NUMBER
580 18:0 number(01234) BAD NUMBER
582 19:0 number(0c1234) BAD NUMBER
584 20:0 number(123.456e1a) a 30864/25
586 21:0 number(123.e4) 1230000
588 22:0 number(0x123 456) BAD NUMBER
590 23:0 number(0b1234) BAD NUMBER
592 24:0 number(123_345) 123345
604 Now to test for some errors ... though things I thought would be errors
608 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-"
609 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-"
613 multiple decimal pointer 3.141.59
614 "Check for decimal commas" 3,14159 = 3,141,59
615 """A multi-string must not have text here
617 "or after close" + """
621 /* No embedded /* comments */ in comments */
623 * a multiline comment */ Error
625 " \\ \t \n special chars in strings"
627 ###### output: errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-
633 2:25 number(3.141) 3141/1000
637 3:0 string("Check for decimal..) Check for decimal ..
638 3:27 number(3,14159) 314159/100000
640 3:37 number(3,141) 3141/1000
645 4:2 ERROR("A multi-string mu..)
647 5:0 ERROR("""\x0a"or after clos..)
651 10:0 ERROR(/* No embedded /*)
652 10:15 bcomment(/* comments */)
654 10:33 ERROR(comments)
657 11:0 ERROR(/* or content afte..)
661 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..
665 ###### output: errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-
679 3:0 string("Check for decimal..) Check for decimal ..
698 4:2 ERROR("A multi-string mu..)
700 5:0 ERROR("""\x0a"or after clos..)
704 10:0 ERROR(/* No embedded /*)
705 10:15 bcomment(/* comments */)
707 10:33 ERROR(comments)
710 11:0 ERROR(/* or content afte..)
714 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..
720 These tests test bugs that were found in practice, and so prevent them recuring.
722 The "bad_indent" test was written because I was seeing a TK_in before the
723 "program" instead of TK_newline
726 scanner_tests += "bad_indent"
728 ###### test: bad_indent
737 ###### output: bad_indent
751 4:23 string("string") string