Debian Codegraph @

debian/tests/run-unit-test

raw
1 #!/bin/bash
2
3 set -e
4 exec 2>&1
5
6 oneTimeSetUp() {
7 # very basic lexer
8 # see https://fbb-git.gitlab.io/flexcpp/manual/flexc++01.html#l4
9 cat > ${SHUNIT_TMPDIR}/lexer <<EOF1
10 %%
11 [_a-zA-Z][_a-zA-Z0-9]* return 1;
12 .|\n // ignore
13 EOF1
14
15 # driver for our lexer
16 cat > ${SHUNIT_TMPDIR}/testflex.cc <<EOF2
17 #include <iostream>
18 #include "Scanner.h"
19
20 using namespace std;
21
22 int main()
23 {
24 Scanner scanner;
25 while (scanner.lex()) {
26 cout << scanner.matched() << " ";
27 }
28 cout << "\n";
29 return 0;
30 }
31 EOF2
32
33 # some input for our lexer
34 cat > ${SHUNIT_TMPDIR}/input <<EOF3
35 a b c
36 //
37 01 2 3.14159
38 #
39 X YY ZZZ
40 EOF3
41 }
42
43 #
44 # test steps must run in order
45 #
46
47 test01GenerateScanner() {
48 cd ${SHUNIT_TMPDIR}
49 flexc++ ${SHUNIT_TMPDIR}/lexer
50
51 for f in lex.cc Scannerbase.h Scanner.h Scanner.ih
52 do
53 if [ ! -f "${SHUNIT_TMPDIR}/${f}" ]; then
54 fail "flexc++ output file missing: ${f}"
55 fi
56 done
57 }
58
59 test02Compilation() {
60 cd ${SHUNIT_TMPDIR}
61 g++ *.cc -lbobcat -o testflex
62
63 if [ ! -f "${SHUNIT_TMPDIR}/testflex" ]; then
64 fail "compilation of textflex failed"
65 fi
66 }
67
68 test03RunScanner() {
69 local OUT=$(${SHUNIT_TMPDIR}/testflex < ${SHUNIT_TMPDIR}/input)
70 assertNotSame "no output from scanner" "" "${OUT}"
71 assertSame "unexpected output from scanner" "a b c X YY ZZZ " "${OUT}"
72 }
73
74 . shunit2