Skip to content

Commit

Permalink
add negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Mar 21, 2023
1 parent a94a618 commit d1f239f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/Compilation.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Compilation where

import Base
import Compilation.Negative qualified as N
import Compilation.Positive qualified as P

allTests :: TestTree
allTests = testGroup "Juvix compilation pipeline tests" [P.allTests]
allTests = testGroup "Juvix compilation pipeline tests" [P.allTests, N.allTests]
13 changes: 13 additions & 0 deletions test/Compilation/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ compileAssertion mode mainFile expectedFile step = do
EvalOnly -> evalAssertion
CompileOnly stdinText -> compileAssertion' stdinText
EvalAndCompile -> evalAssertion >> compileAssertion' ""

compileErrorAssertion ::
Path Abs File ->
(String -> IO ()) ->
Assertion
compileErrorAssertion mainFile step = do
step "Translate to JuvixCore"
cwd <- getCurrentDir
let entryPoint = defaultEntryPoint cwd mainFile
tab <- (^. Core.coreResultTable) . snd <$> runIO' iniState entryPoint upToCore
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toEval' tab of
Left _ -> assertBool "" True
Right _ -> assertFailure "no error"
37 changes: 37 additions & 0 deletions test/Compilation/Negative.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Compilation.Negative where

import Base
import Compilation.Base

data NegTest = NegTest
{ _name :: String,
_relDir :: Path Rel Dir,
_file :: Path Rel File
}

root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/Compilation/negative")

testDescr :: NegTest -> TestDescr
testDescr NegTest {..} =
let tRoot = root <//> _relDir
file' = tRoot <//> _file
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Steps $ compileErrorAssertion file'
}

allTests :: TestTree
allTests =
testGroup
"Juvix compilation pipeline negative tests"
(map (mkTest . testDescr) tests)

tests :: [NegTest]
tests =
[ NegTest
"Pattern matching coverage"
$(mkRelDir ".")
$(mkRelFile "test001.juvix")
]
14 changes: 14 additions & 0 deletions tests/Compilation/negative/test001.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- pattern matching coverage
module test001;

open import Stdlib.Prelude;

f : List Nat -> List Nat -> Nat;
f (x :: xs) (y :: ys) := x + y;
f _ (_ :: (z :: zs)) := z;
f _ nil := 0;

main : Nat;
main := f (1 :: nil) (2 :: nil);

end;

0 comments on commit d1f239f

Please sign in to comment.