tests:: oceani_test_suite
oceani_test_suite: oceani coverage_oceani
+ @./parsergen --report --LR1 --tag Parser oceani.mdc | grep " - no conflicts" > /dev/null || \
+ { echo "Grammar container conflicts, please review" ; exit 1; }
@rm -rf coverage; mkdir -p coverage
@cp *.gcno coverage
@for T in $(oceani_tests); do \
- echo -n "Test $$T ... "; \
+ echo -n "Test $$T.. "; \
i="$$IFS"; IFS=,; set $$T; IFS="$$i"; t=$$1; shift; \
./md2c oceani-tests.mdc "output: $$T" | grep -v '^#' > .tmp.want; \
./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} > .tmp.have; \
if ! cmp -s .tmp.want .tmp.have; then \
echo "FAILED"; diff -u .tmp.want .tmp.have ; exit 1; fi ;\
- echo -n "passed ... "; \
- if ! valgrind ./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} \
- > /dev/null 2> .tmp.valg; then \
- echo "valgrind FAILED"; cat .tmp.valg; exit 1; fi ; \
- echo -n "valgrind passed ... "; \
+ echo -n "valgrind.. "; \
+ if ! valgrind --error-exitcode=1 --log-file=.tmp.valg ./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} \
+ > /dev/null 2>&1 ; then \
+ echo "FAILED"; cat .tmp.valg; exit 1; fi ; \
+ if grep 'LEAK SUMMARY' .tmp.valg > /dev/null; then \
+ echo "valgrind found LEAKS"; cat .tmp.valg ; exit 1 ; fi; \
+ if grep 'in use at exit [1-9]' .tmp.valg > /dev/null; then \
+ echo "valgrind found memory in use at exit"; cat .tmp.valg ; exit 1 ; fi; \
+ echo -n "printing.. "; \
echo '``````' > .tmp.code1; echo '``````' > .tmp.code2 ;\
./oceani --noexec --print --section "test: $$t" oceani-tests.mdc >> .tmp.code1; \
./oceani --noexec --print .tmp.code1 >> .tmp.code2 ;\
if ! cmp -s .tmp.code1 .tmp.code2; then \
- echo "Printing Failed"; diff -u .tmp.code1 .tmp.code2; exit1 ; fi ; \
- echo "Printing passed"; \
+ echo " Failed"; diff -u .tmp.code1 .tmp.code2; exit 1 ; fi ; \
+ echo -n "exec-after-print.. "; \
+ ./oceani .tmp.code1 $${1+"$$@"} > .tmp.have ; \
+ if ! cmp -s .tmp.want .tmp.have; then \
+ echo " FAILED"; diff -u .tmp.want .tmp.have; exit 1;fi; \
+ echo " all passed"; \
./coverage_oceani --print --section "test: $$t" oceani-tests.mdc $${1+"$$@"} > /dev/null ; \
./coverage_oceani -tpbn --section "test: $$t" oceani-tests.mdc > /dev/null 2>&1; \
done
@gcov -o coverage oceani.mdc > /dev/null 2> /dev/null
@mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage
- @ awk '/^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
+ @ awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
- if (ran < (ran + skip) *0.85) exit(1) }' \
+ if (ran < (ran + skip) *0.93) exit(1) }' \
coverage/oceani.mdc.gcov
@rm -f .tmp*
###### test: valvar
program:
- a := 23; b:=12
+ a := 23; b:=12 ; b1 := -b
print a, b, a+b, a-b, a*b, a/b, a%b
print a<b, a<=b, a>b, a>=b, a<a, a==b, a==a
+ print +a, +b, +b1, -a, -b, -b1
+ x := True; y := False
+ print x and y, x or y, x and x, y or y, x and not x, x < y
c ::= "This is a string"
d ::= " field theory"
print c, d, c++d
+ aconst :: string = "unchanging"
+
###### output: valvar
23 12 35 11 276 1.91667 11
False False True True False False True
+ 23 12 12 -23 -12 12
+ False True True False False False
This is a string field theory This is a string field theory
Next we change the value of variables
###### output: setvar
1.07374e+09 1
+Now some contants
+
+###### test list
+ oceani_tests += "consts"
+
+###### test: consts
+ const:
+ pi ::= 3.1415926
+ four ::= 2 + 2 ; five ::= 10/2
+ const pie ::= "I like Pie";
+ cake ::= "The cake is"
+ ++ " a lie"
+
+ program:
+ print "Hello World, what lovely oceans you have!"
+ print "are there", five, "?"
+ print pi, pie, "but", cake
+
+###### output: consts
+ Hello World, what lovely oceans you have!
+ are there 5 ?
+ 3.14159 I like Pie but The cake is a lie
+
## Conditions and Loops
Now we need to test if/else and some different loops
count = count + 1
print "error is ", target - guess * guess
+ for j:=0; then j = j+3 ; while j < 10:
+ if j != 0 and then 20 / j > 3:
+ print "20 /", j," =", 20 / j
+ else:
+ print "I won't calculate 20 /", j
+ pi ::= 3.1415926535897
+ if 355/113 == pi or else +(pi - 355/113) < 0.001:
+ print "Close enough"
+ print "lower" if 355/113 < pi else "higher"
+
###### output: cond_loop
Success
1 2 4 8 16 32 64
2 1.41422
3 1.41421
error is -4.51095e-12
+ I won't calculate 20 / 0
+ 20 / 3 = 6.66667
+ 20 / 6 = 3.33333
+ I won't calculate 20 / 9
+ Close enough
+ higher
## Say Hello
list[ 53 ]= 9040
list[ 54 ]= 9768
+## Arrays
+
+We already have some array tests, but this is where we put other
+ad-hoc things array related.
+
+###### test list
+ oceani_tests += arrays
+
+###### test: arrays
+
+ program:
+ bools:[5]Boolean
+ strings:[4]string
+
+ bools[3] = strings[1] == "Hello"
+ bools[1] = strings[2] <= "there"
+
+ for i:=0; then i=i+1; while i<5:
+ print '', bools[i],
+ print
+
+###### output: arrays
+ False True False False False
+
## Test code with syntax errors
Syntax errors aren't handled well yet - the result is almost always a
###### output: syn1
.tmp.code:3:11: error: unhandled parse error: then
+ oceani: no program found.
###### test: tokerr
program:
various places that `type_err()` are called.
###### test list
- oceani_failing_tests += type_err1 type_err2 type_err3
+ oceani_failing_tests += type_err1 type_err2 type_err3 type_err4
###### test: type_err1
.tmp.code:3:8: info: variable 'c' was set as string here.
oceani: type error in program - not running.
+###### test: type_err4
+ program:
+ a:=1; b=2; c::=3
+ print a, b, c
+
+###### output: type_err4
+ .tmp.code:3:14: error: expected *unknown*type* (labels not permitted) but variable 'b' is label
+ .tmp.code:3:14: info: this is where 'b' was set to label
+ .tmp.code:3:16: error: expected label found number
+ .tmp.code:3:14: info: variable 'b' was set as label here.
+ .tmp.code:4:17: error: expected *unknown*type* (labels not permitted) but variable 'b' is label
+ .tmp.code:3:14: info: this is where 'b' was set to label
+ oceani: type error in program - not running.
+
+###### test list
+ oceani_failing_tests += type_err_const type_err_const1
+
+###### test: type_err_const
+ const:
+ foo :: number = 45
+ bar ::= "string" + 56
+ const:
+ bar ::= "baz"
+ program:
+ foo := 4
+ print foo, bar
+
+###### output: type_err_const
+ .tmp.code:4:16: error: expected number found string
+ .tmp.code:6:8: error: name already declared: bar
+ .tmp.code:4:8: info: this is where 'bar' was first declared
+ .tmp.code:8:8: error: variable 'foo' redeclared
+ .tmp.code:3:8: info: this is where 'foo' was first declared
+
+###### test: type_err_const1
+ const:
+ foo : number = 45
+ bar := "string"
+ program:
+ foo := 4
+ print foo, bar
+
+###### output: type_err_const1
+ .tmp.code:3:12: error: unhandled parse error: :
+ oceani: no program found.
+
## Test erroneous command line args