]> ocean-lang.org Git - ocean/commitdiff
oceani-tests: assorted more tests.
authorNeilBrown <neil@brown.name>
Wed, 8 May 2019 07:22:53 +0000 (17:22 +1000)
committerNeilBrown <neil@brown.name>
Wed, 8 May 2019 07:22:53 +0000 (17:22 +1000)
Assorted tests chosen after examining lines of
code that were not being run.
This pushes the coverage over 90% !!!

Also a bugfix - test suites are good !!!

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index bd40b2de3685e36c2bb8988801bc58cec61e4967..f5f097a1b4ac0a77c648552fb0f00658fa710084 100644 (file)
@@ -68,7 +68,7 @@ arguments separated from the name by commas.  For each test, there is a section
                @mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage
                @ awk '/^ *[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.90) exit(1) }' \
                        coverage/oceani.mdc.gcov
                @rm -f .tmp*
 
@@ -87,18 +87,25 @@ calculations on them.
 ###### 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
@@ -393,6 +400,30 @@ Here I break it into two parts, keeping the array code separate.
        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
@@ -482,7 +513,7 @@ These programs were generated by looking for the
 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
 
@@ -578,6 +609,19 @@ various places that `type_err()` are called.
        .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 erroneous command line args
 
index 27c0c32493ecba0ee96916ae13135e2f69558790..dd02e81ab89e7b01855e145973bf0def5252b6d3 100644 (file)
@@ -1316,6 +1316,8 @@ subclasses, and to access these we need to be able to `cast` the
 
        static int __fput_loc(struct exec *loc, FILE *f)
        {
+               if (!loc)
+                       return 0;
                if (loc->line >= 0) {
                        fprintf(f, "%d:%d: ", loc->line, loc->column);
                        return 1;