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
44 $(CC) $(CFLAGS) --coverage -fprofile-dir=coverage -o coverage_scanner \
45 scanner.c libscanner.c \
46 libmdcode.o libnumber.o libstring.o -licuuc -lgmp
51 Some simple tests... maybe all tests are simple.
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
519 Now to test for some errors ... though things I thought would be errors
523 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-"
524 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-"
528 multiple decimal pointer 3.141.59
529 "Check for decimal commas" 3,14159 = 3,141,59
530 """A multi-string must not have text here
532 "or after close" + """
536 /* No embedded /* comments */ in comments */
538 * a multiline comment */ Error
540 " \\ \t \n special chars in strings"
542 ###### output: errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-
548 2:25 number(3.141) 3141/1000
552 3:0 string("Check for decimal..) Check for decimal ..
553 3:27 number(3,14159) 314159/100000
555 3:37 number(3,141) 3141/1000
560 4:2 ERROR("A multi-string mu..)
562 5:0 ERROR("""\x0a"or after clos..)
566 10:0 ERROR(/* No embedded /*)
567 10:15 bcomment(/* comments */)
569 10:33 ERROR(comments)
572 11:0 ERROR(/* or content afte..)
576 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..
580 ###### output: errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-
594 3:0 string("Check for decimal..) Check for decimal ..
613 4:2 ERROR("A multi-string mu..)
615 5:0 ERROR("""\x0a"or after clos..)
619 10:0 ERROR(/* No embedded /*)
620 10:15 bcomment(/* comments */)
622 10:33 ERROR(comments)
625 11:0 ERROR(/* or content afte..)
629 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..