diff --git a/scripts/test b/scripts/test index 0909682..5165b44 100755 --- a/scripts/test +++ b/scripts/test @@ -20,12 +20,16 @@ for fn in tests/*.newt ; do echo "Compile failure mismatch for $fn" diff ${fn}.fail tmp/${bn}.compile failed=$((failed + 1)) + if [ $1 = "--fix" ]; then + cp tmp/${bn}.compile ${fn}.fail + fi continue fi elif [ $cerr != "0" ]; then echo Compile failed for $fn failed=$((failed + 1)) cat tmp/${bn}.compile + continue fi # if there is a golden file, run the code and compare output @@ -40,6 +44,9 @@ for fn in tests/*.newt ; do echo "Output mismatch for $fn" diff ${fn}.golden tmp/${bn}.out failed=$((failed + 1)) + if [ $1 = "--fix" ]; then + cp tmp/${bn}.out ${fn}.golden + fi fi fi done diff --git a/src/Main.newt b/src/Main.newt index 42b1d4d..e4db61d 100644 --- a/src/Main.newt +++ b/src/Main.newt @@ -54,8 +54,7 @@ writeSource fn = do :: Nil) ++ map (render 90 ∘ noAlt) docs (Right _) <- liftIO {M} $ writeFile fn src - | Left err => exitFailure (show err) - -- (Right _) <- chmodRaw fn 493 | Left err => exitFailure (show err) + | Left err => throwError $ E (MkFC fn $ MkBounds 0 0 0 0) err pure MkUnit @@ -105,22 +104,22 @@ processModule importFC base stk qn@(QN ns nm) = do modifyTop [modules := updateMap modns (emptyModCtx "") top.modules] let fn = (joinBy "/" (base :: ns)) ++ "/" ++ nm ++ ".newt" (Right src) <- liftIO {M} $ readFile fn - | Left err => exitFailure "ERROR at \{show importFC}: error reading \{fn}: \{show err}" + | Left err => throwError $ E importFC "error reading \{fn}: \{show err}" let (Right toks) = tokenise fn src - | Left err => exitFailure (showError src err) + | Left err => throwError err let (Right ((nameFC, modName), ops, toks)) = partialParse fn parseModHeader top.ops toks - | Left (err, toks) => exitFailure (showError src err) + | Left (err, toks) => throwError err log 1 $ \ _ => "scan imports for module \{modName}" let ns = split modName "." let (path, modName') = unsnoc $ split1 modName "." -- let bparts = split base "/" let (True) = qn == QN path modName' - | _ => exitFailure "ERROR at \{show nameFC}: module name \{show modName} doesn't match file name \{show fn}" + | _ => throwError $ E nameFC "module name \{show modName} doesn't match file name \{show fn}" let (Right (imports, ops, toks)) = partialParse fn parseImports ops toks - | Left (err, toks) => exitFailure (showError src err) + | Left (err, toks) => throwError err let importNames = map importToQN imports @@ -176,7 +175,7 @@ processModule importFC base stk qn@(QN ns nm) = do logMetas $ reverse $ listValues top.metaCtx.metas let (Nil) = top.errors - | errors => exitFailure "Compile failed" + | errors => throwError $ E importFC "Failed to compile module \{show qn}" pure src where tryProcessDecl : String -> List String → Decl -> M Unit @@ -200,7 +199,7 @@ showErrors fn src = do let (Nil) = top.errors | errors => do traverse (putStrLn ∘ showError src) errors - exitFailure "Compile failed" + throwError $ E (MkFC fn $ MkBounds 0 0 0 0) "Compile failed" pure MkUnit invalidateModule : QName -> M Unit diff --git a/tests/BadAlt.newt.fail b/tests/BadAlt.newt.fail index 6bcbdc9..083c563 100644 --- a/tests/BadAlt.newt.fail +++ b/tests/BadAlt.newt.fail @@ -7,4 +7,4 @@ ERROR at tests/BadAlt.newt:6:6--6:13: Prelude._:<_ not a constructor for (Prelud foo (xs :< x) = x ^^^^^^^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module BadAlt diff --git a/tests/Duplicate.newt.fail b/tests/Duplicate.newt.fail index ca34564..780e49b 100644 --- a/tests/Duplicate.newt.fail +++ b/tests/Duplicate.newt.fail @@ -6,4 +6,4 @@ ERROR at tests/Duplicate.newt:4:1--4:5: Duplicate.Left is already defined at tes data Either : U -> U -> U where ^^^^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module Duplicate diff --git a/tests/ErrMsg2.newt.fail b/tests/ErrMsg2.newt.fail index ea490da..f0a6573 100644 --- a/tests/ErrMsg2.newt.fail +++ b/tests/ErrMsg2.newt.fail @@ -3,4 +3,4 @@ module Prelude module ErrMsg2 ERROR at tests/ErrMsg2.newt:6:13--6:15: Expected '=>' at Keyword:-> -Compile failed +ERROR at :1:1--1:2: Failed to compile module ErrMsg2 diff --git a/tests/ErrorDup.newt.fail b/tests/ErrorDup.newt.fail index 3d02085..21ff394 100644 --- a/tests/ErrorDup.newt.fail +++ b/tests/ErrorDup.newt.fail @@ -18,4 +18,4 @@ ERROR at tests/ErrorDup.newt:9:7--9:10: Nat already declared class Nat where ^^^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module ErrorDup diff --git a/tests/LitConCase.newt.fail b/tests/LitConCase.newt.fail index 000172f..de85dda 100644 --- a/tests/LitConCase.newt.fail +++ b/tests/LitConCase.newt.fail @@ -6,4 +6,4 @@ ERROR at tests/LitConCase.newt:7:5--7:11: expected Prim.Int foo MkUnit = MkUnit ^^^^^^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module LitConCase diff --git a/tests/Possible.newt.fail b/tests/Possible.newt.fail index ab1832b..dd28978 100644 --- a/tests/Possible.newt.fail +++ b/tests/Possible.newt.fail @@ -7,4 +7,4 @@ ERROR at tests/Possible.newt:6:5--6:8: possible constructors: [Prelude.Z, Prelud foo () ^^^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module Possible diff --git a/tests/Quantity.newt.fail b/tests/Quantity.newt.fail index 32d9669..f75cc2a 100644 --- a/tests/Quantity.newt.fail +++ b/tests/Quantity.newt.fail @@ -7,4 +7,4 @@ ERROR at tests/Quantity.newt:11:15--11:16: used erased value x$0 (FIXME FC may b bar {x} = foo x ^ -Compile failed +ERROR at :1:1--1:2: Failed to compile module Quantity