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.85) 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(0x543p3) 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(0x543p3) 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(0x543p3) 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(0x543p3) 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(0x543p3) 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(0x543p3) 10776