X-Git-Url: https://ocean-lang.org/code/?a=blobdiff_plain;f=csrc%2Foceani-tests.mdc;h=11c3f19ffcd93a4c8760d9cbe85a3505befd46ae;hb=85e747e065a6f4b2236acc8b3a2471de4d831c95;hp=90bfc19da11d84241256fdba41c6b06bd5376db9;hpb=b5a63d46c787e442d44b5fd1d70d007498bd5058;p=ocean diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 90bfc19..11c3f19 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -80,11 +80,11 @@ arguments separated from the name by commas. For each test, there is a section @mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage || true @ awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \ END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \ - if (ran < (ran + skip) *0.94) exit(1) }' \ + if (ran < (ran + skip) *0.9495) exit(1) }' \ coverage/oceani.mdc.gcov @rm -f .tmp* - @for T in $(oceani_tests); do \ + @[ -n "$$SKIP_VALGRIND" ] || for T in $(oceani_tests); do \ echo -n "Valgrind $$T.. "; \ i="$$IFS"; IFS=,; set $$T; IFS="$$i"; t=$$1; shift; \ if ! valgrind --error-exitcode=1 --log-file=.tmp.valg ./oceani --section "test: $$t" oceani-tests.mdc $${1+"$$@"} \ @@ -198,8 +198,21 @@ Test merging of variables from multiple cases print num,", ", print + for i:=0; then i=i+1; while i < 5: + switch i: + case 0: num:="zero" + case 1: num:="one" + case 2: num:="two" + case 3: num:="three" + else num:="many" + // re-declare a CondScope variable + num := i*i + print num,", ", + print + ###### output: varmerge zero , one , two , three , many , + 0 , 1 , 4 , 9 , 16 , ## Conditions and Loops @@ -282,9 +295,10 @@ Here I break it into two parts, keeping the array code separate. ###### test: sayhello - program As Bs astr bbools: - A := $As; B := $Bs - bbool := bbools == "True" + program ac av: + A := $av[1]; B := $av[2] + astr := av[3] + bbool := av[ac-1] == "True" print "Hello World, what lovely oceans you have!" /* When a variable is defined in both branches of an 'if', * and used afterwards, the variables are merged. @@ -533,7 +547,7 @@ ad-hoc things array related. for i:=0; then i=i+1; while i<5: j ::= i - ra:[5]number + ra:[j]number ra[i-1] = i*i ra[6] = 42 // mustn't crash print '', bools[i], ra[j-1], @@ -551,10 +565,11 @@ Time to test if structure declarations and accesses work correctly. ###### test: structs + const three ::= 3 struct foo - size:[3]number + size:[three]number name:string - active:Boolean + active:Boolean = True struct baz { a:number; b:Boolean; } @@ -570,7 +585,8 @@ Time to test if structure declarations and accesses work correctly. info[i].name = nm info[i].size[0] = i*i - info[i].active = nm == "jane" + if nm != "jane": + info[i].active = False for i:=0; then i=i+1; while i < 4: print info[i].name, info[i].active, info[i].size[0] @@ -748,6 +764,7 @@ various places that `type_err()` are called. bar:foo foo.c = 43 print c.foo + print bar.c ###### output: type_err3 .tmp.code:8:12: error: expected number but variable 'c' is string @@ -777,6 +794,7 @@ various places that `type_err()` are called. .tmp.code:32:8: error: field reference attempted on none, not a struct .tmp.code:32:16: error: expected none found number .tmp.code:33:14: error: field reference attempted on string, not a struct + .tmp.code:34:14: error: cannot find requested field in foo oceani: type error in program - not running. ###### test: type_err4 @@ -791,7 +809,7 @@ various places that `type_err()` are called. oceani: type error in program - not running. ###### test list - oceani_failing_tests += type_err_const type_err_const1 + oceani_failing_tests += type_err_const type_err_const1 missing_program ###### test: type_err_const const @@ -822,6 +840,13 @@ various places that `type_err()` are called. .tmp.code:3:12: Syntax error in constant: : .tmp.code:4:12: Syntax error in constant: : +###### test: missing_program + const + foo::="bar" + +###### output: missing_program + oceani: no program found. + ## Test erroneous command line args To improve coverage, we want to test correct handling of strange command