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
50 Some simple tests... maybe all tests are simple.
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,+,-,/"
78 1234, 1.234 -123.456e45
80 "This is a string" &"so is this"a
86 I think # some comments are like this
87 and // some are like this
93 ###### output: test1,if,then,+,-
145 18:0 number(1234) 1234
147 18:7 number(1.234 ) 617/500
149 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
151 19:0 number(0x1234 ) 4660
153 19:10 number(0x543p+3) 10776
155 20:0 string("This is a string") This is a string
157 20:20 string("so is this"a) a so is this
161 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
165 26:8 lcomment(# some comments ar..)
168 27:4 lcomment(// some are like t..)
172 28:9 bcomment(/* can go\x0aover mul..)
180 ###### output: test1,if,then,+,-,/
232 18:0 number(1234) 1234
234 18:7 number(1.234 ) 617/500
236 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
238 19:0 number(0x1234 ) 4660
240 19:10 number(0x543p+3) 10776
242 20:0 string("This is a string") This is a string
244 20:20 string("so is this"a) a so is this
248 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
252 26:8 lcomment(# some comments ar..)
255 27:4 lcomment(// some are like t..)
259 28:9 bcomment(/* can go\x0aover mul..)
268 ###### output: test1,--ignore-indent,if,then,+,-,/
308 18:0 number(1234) 1234
310 18:7 number(1.234 ) 617/500
312 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
314 19:0 number(0x1234 ) 4660
316 19:10 number(0x543p+3) 10776
318 20:0 string("This is a string") This is a string
320 20:20 string("so is this"a) a so is this
324 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
328 26:8 lcomment(# some comments ar..)
331 27:4 lcomment(// some are like t..)
335 28:9 bcomment(/* can go\x0aover mul..)
344 ###### output: test1,--ignore-indent,--ignore-newline,if,then,+,-,/
368 18:0 number(1234) 1234
370 18:7 number(1.234 ) 617/500
372 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
373 19:0 number(0x1234 ) 4660
375 19:10 number(0x543p+3) 10776
376 20:0 string("This is a string") This is a string
378 20:20 string("so is this"a) a so is this
381 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
384 26:8 lcomment(# some comments ar..)
386 27:4 lcomment(// some are like t..)
389 28:9 bcomment(/* can go\x0aover mul..)
396 ###### output: test1,-Cc,--ignore-indent,--ignore-newline,if,then,+,-,/
420 18:0 number(1234) 1234
422 18:7 number(1.234 ) 617/500
424 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
425 19:0 number(0x1234 ) 4660
427 19:10 number(0x543p+3) 10776
428 20:0 string("This is a string") This is a string
430 20:20 string("so is this"a) a so is this
433 21:4 mstring("""\x0a This is a m..) bb This is a multi-\x0al..
445 ###### output: test1,-CcSz,--ignore-indent,--ignore-newline,if,then,+,-,/
469 18:0 number(1234) 1234
471 18:7 number(1.234 ) 617/500
473 18:14 number(123.456e45) 123456000000000000000000000000000000000000000000
474 19:0 number(0x1234 ) 4660
476 19:10 number(0x543p+3) 10776
518 Now to test for some errors ... though things I thought would be errors
522 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-"
523 scanner_tests += "errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-"
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
531 "or after close" + """
535 /* No embedded /* comments */ in comments */
537 * a multiline comment */ Error
539 " \\ \t \n special chars in strings"
541 ###### output: errtest,--ignore-ident,--ignore-mark,-W_,-w_,if,then,+,-
547 2:25 number(3.141) 3141/1000
551 3:0 string("Check for decimal..) Check for decimal ..
552 3:27 number(3,14159) 314159/100000
554 3:37 number(3,141) 3141/1000
559 4:2 ERROR("A multi-string mu..)
561 5:0 ERROR("""\x0a"or after clos..)
565 10:0 ERROR(/* No embedded /*)
566 10:15 bcomment(/* comments */)
568 10:33 ERROR(comments)
571 11:0 ERROR(/* or content afte..)
575 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..
579 ###### output: errtest,--ignore-ident,--ignore-mark,-N,if,then,+,-
593 3:0 string("Check for decimal..) Check for decimal ..
612 4:2 ERROR("A multi-string mu..)
614 5:0 ERROR("""\x0a"or after clos..)
618 10:0 ERROR(/* No embedded /*)
619 10:15 bcomment(/* comments */)
621 10:33 ERROR(comments)
624 11:0 ERROR(/* or content afte..)
628 14:0 string(" \\\\ \\t \\n specia..) \\ \x09 \x0a special ch..