From 4e5c62ce299f422fa51b96245f74f652e3511433 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 6 May 2019 17:57:05 +1000 Subject: [PATCH] oceani-tests: add tests for various token-errors This pushes our coverage over 80% Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 80160a0..d0b1419 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -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.75) exit(1) }' \ + if (ran < (ran + skip) *0.8) exit(1) }' \ coverage/oceani.mdc.gcov @rm -f .tmp* @@ -399,6 +399,11 @@ Syntax errors aren't handled well yet - the result is almost always a single message about the first error. So this section will be fairly thin until we add proper parsing recovery in the face of common errors. +A special case of syntax errors is token errors, when a token is only +accepted because the parser doesn't know quite enough to reject it. +There are handled better as they are quite local, so a single test +program can trigger most of the possible errors. + To handle erronous code, we need a different set of tests, as we need to capture `stderr`. The same test code will be used for type errors too. As error messages contain the line number, and we don't want changes to @@ -420,6 +425,7 @@ separate file first, then run from there. ###### test list oceani_failing_tests := syn1 + oceani_failing_tests += tokerr ###### test: syn1 @@ -429,6 +435,37 @@ separate file first, then run from there. ###### output: syn1 .tmp.code:3:11: error: unhandled parse error: then +###### test: tokerr + program: + a := 1i // imaginary numbers aren't understood + b:[2i]number // array sizes are handled separately + c:[3.14159]Boolean // array sizes must be integers + d:[1_000_000_000_000]number // they mustn't be huge + patn: string = "foo[ ,_]*bar"re // regexp strings are just a dream + + multi := """ + This is a multiline string + With an unsupportable suffix + """Aa + + xx:unknown = 24 + yy:[unknowable]number + zzsize := 4 + zz:[zzsize]string // size must be constant, use ::= + +###### output: tokerr + .tmp.code:3:13: error: unsupported number suffix: 1i + .tmp.code:4:11: error: unsupported number suffix: 2i + .tmp.code:5:11: error: array size must be an integer: 3.14159 + .tmp.code:6:11: error: array size is too large: 1_000_000_000_000 + .tmp.code:7:23: error: unsupported string suffix: "foo[ ,_]*bar"re + .tmp.code:9:17: error: unsupported string suffix: """ + This is a multiline string + With an unsupportable suffix + """Aa + .tmp.code:14:11: error: undefined type: unknown + .tmp.code:15:12: error: name undeclared: unknowable + .tmp.code:17:12: error: array size must be a constant: zzsize ## Test erroneous command line args -- 2.43.0