]> ocean-lang.org Git - ocean/commitdiff
oceani: improve test coverage
authorNeilBrown <neil@brown.name>
Sat, 18 Dec 2021 07:10:34 +0000 (18:10 +1100)
committerNeilBrown <neil@brown.name>
Sat, 18 Dec 2021 07:37:01 +0000 (18:37 +1100)
Various little changes to reduce number of lines that aren't tested.

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

index 9db8e9363a469d66beb43cdceae215136542a862..6d513487e619bc695ed3b25fd6048c789971a745 100644 (file)
@@ -97,7 +97,7 @@ arguments separated from the name by commas.  For each test, there is a section
                ## valgrind test code
                @[ -n "$$SKIP_COVERAGE_CHECK" ] || awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
                    END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
-                        if (ran < (ran + skip) *0.972) exit(1) }' \
+                        if (ran < (ran + skip) *0.98) exit(1) }' \
                        coverage/oceani.mdc.gcov
 
        coverage_oceani: oceani.c
@@ -142,6 +142,9 @@ calculations on them.
                        print "z??False", z??False, "w??False", w??False
                if ?w:
                        print "Weird?"
+               print $"-34.56", $"not-a-number"
+               print $"4i"
+               if True { pass; pass }
 
 ###### output: valvar
 
@@ -154,6 +157,9 @@ calculations on them.
        w??z True
        z??w True
        z??False True w??False False
+       -34.56 0
+       Unsupported suffix: 4i
+       4
 
 Next we change the value of variables
 
@@ -271,6 +277,7 @@ Now we need to test if/else and some different loops
                if 355/113 == pi or else +(pi - 355/113) < 0.001:
                        print "Close enough"
                print "lower" if 355/113 < pi else "higher"
+               print "higher" if 355/113 > pi else "lower"
 
                if pi > 3 then print "pi exceeds three"; else print "need more pie"
                if (pi < 3) { print "not enough pi" } else { print "pi sufficient" }
@@ -303,6 +310,7 @@ Now we need to test if/else and some different loops
        I won't calculate 20 / 9
        Close enough
        higher
+       higher
        pi exceeds three
        pi sufficient
        sum 1..10 is 55
@@ -597,7 +605,7 @@ Time to test if structure declarations and accesses work correctly.
        const three ::= 3
        struct foo
                size:[three]number
-               name:string
+               name:string = "Hello"
                thing:baz
                active:Boolean = True
 
@@ -951,6 +959,8 @@ various places that `type_err()` are called.
                case 2: print "two"
                print "one" ++ a4[], c[]
 
+               x:Boolean = $"42"
+
 ###### output: type_err3
        .tmp.code:8:12: error: expected number but variable 'c' is string
        .tmp.code:7:8: info: this is where 'c' was set to string
@@ -987,6 +997,8 @@ various places that `type_err()` are called.
        .tmp.code:38:29: error: expected number found Boolean
        .tmp.code:41:23: error: have number but need string
        .tmp.code:41:29: error: string cannot provide length
+       .tmp.code:43:21: error: Can only convert string to number, not Boolean
+       .tmp.code:43:8: info: variable 'x' was set as Boolean here.
        oceani: type error in program - not running.
 
 ###### test: type_err4
index a3574ea24e91167880aa12d2cff4bcefc1a1e412..a59ba63d9cd0ac1651ab3eab4cf0be8edc5e01a2 100644 (file)
@@ -2049,7 +2049,7 @@ tell if it was set or not later.
                        t->prepare_type(c, t, 1);       // NOTEST
 
                if (c->global_size & (t->align - 1))
-                       c->global_size = (c->global_size + t->align) & ~(t->align-1);   // NOTEST
+                       c->global_size = (c->global_size + t->align) & ~(t->align-1);
                if (!v) {
                        v = &scratch;
                        v->type = t;
@@ -3014,10 +3014,10 @@ function will be needed.
                        if (fl->type->print && fl->init) {
                                fprintf(f, " = ");
                                if (fl->type == Tstr)
-                                       fprintf(f, "\"");       // UNTESTED
+                                       fprintf(f, "\"");
                                print_value(fl->type, fl->init, f);
                                if (fl->type == Tstr)
-                                       fprintf(f, "\"");       // UNTESTED
+                                       fprintf(f, "\"");
                        }
                        fprintf(f, "\n");
                }
@@ -3865,7 +3865,7 @@ there.
                struct binode *b2 = cast(binode, b->right);
                left = interp_exec(c, b->left, &ltype);
                if (left.bool)
-                       rv = interp_exec(c, b2->left, &rvtype); // UNTESTED
+                       rv = interp_exec(c, b2->left, &rvtype);
                else
                        rv = interp_exec(c, b2->right, &rvtype);
                }
@@ -4142,9 +4142,9 @@ expression operator, and the `CMPop` non-terminal will match one of them.
                if (t)
                        propagate_types(b->right, c, perr, t, 0);
                else {
-                       t = propagate_types(b->right, c, perr, NULL, 0);        // UNTESTED
-                       if (t)  // UNTESTED
-                               t = propagate_types(b->left, c, perr, t, 0);    // UNTESTED
+                       t = propagate_types(b->right, c, perr, NULL, 0);        // NOTEST
+                       if (t)  // NOTEST
+                               t = propagate_types(b->left, c, perr, t, 0);    // NOTEST
                }
                if (!type_compat(type, Tbool, 0))
                        type_err(c, "error: Comparison returns %1 but %2 expected", prog,
@@ -4344,7 +4344,7 @@ parentheses around an expression converts it into a Term,
                /* op must be string, result is number */
                propagate_types(b->left, c, perr, Tstr, 0);
                if (!type_compat(type, Tnum, 0))
-                       type_err(c,     // UNTESTED
+                       type_err(c,
                          "error: Can only convert string to number, not %1",
                                prog, type, 0, NULL);
                *perr |= Erval;
@@ -4434,19 +4434,19 @@ parentheses around an expression converts it into a Term,
                rvtype = Tnum;
 
                struct text tx = right.str;
-               char tail[3];
+               char tail[3] = "";
                int neg = 0;
                if (tx.txt[0] == '-') {
-                       neg = 1;        // UNTESTED
-                       tx.txt++;       // UNTESTED
-                       tx.len--;       // UNTESTED
+                       neg = 1;
+                       tx.txt++;
+                       tx.len--;
                }
                if (number_parse(rv.num, tail, tx) == 0)
-                       mpq_init(rv.num);       // UNTESTED
+                       mpq_init(rv.num);
                else if (neg)
-                       mpq_neg(rv.num, rv.num);        // UNTESTED
+                       mpq_neg(rv.num, rv.num);
                if (tail[0])
-                       printf("Unsupported suffix: %.*s\n", tx.len, tx.txt);   // UNTESTED
+                       printf("Unsupported suffix: %.*s\n", tx.len, tx.txt);
 
                break;
        case Test:
@@ -4619,25 +4619,13 @@ the common header for all reductions to use.
 
 ###### print binode cases
        case Block:
-               if (indent < 0) {
-                       // simple statement
-                       if (b->left == NULL)    // UNTESTED
-                               printf("pass"); // UNTESTED
-                       else
-                               print_exec(b->left, indent, bracket);   // UNTESTED
-                       if (b->right) { // UNTESTED
-                               printf("; ");   // UNTESTED
-                               print_exec(b->right, indent, bracket);  // UNTESTED
-                       }
-               } else {
-                       // block, one per line
-                       if (b->left == NULL)
-                               do_indent(indent, "pass\n");
-                       else
-                               print_exec(b->left, indent, bracket);
-                       if (b->right)
-                               print_exec(b->right, indent, bracket);
-               }
+               // block, one per line
+               if (b->left == NULL)
+                       do_indent(indent, "pass\n");
+               else
+                       print_exec(b->left, indent, bracket);
+               if (b->right)
+                       print_exec(b->right, indent, bracket);
                break;
 
 ###### propagate binode cases