1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 10:03:22 +03:00
juvix/test/Termination/Negative.hs

81 lines
2.3 KiB
Haskell
Raw Normal View History

module Termination.Negative (module Termination.Negative) where
import Base
import Juvix.Compiler.Builtins.Effect
import Juvix.Compiler.Internal.Translation.FromAbstract.Analysis.Termination
import Juvix.Compiler.Pipeline
type FailMsg = String
data NegTest = NegTest
{ _name :: String,
2022-12-20 15:05:40 +03:00
_relDir :: Path Rel Dir,
_file :: Path Rel File,
_checkErr :: TerminationError -> Maybe FailMsg
}
testDescr :: NegTest -> TestDescr
testDescr NegTest {..} =
2022-12-20 15:05:40 +03:00
let tRoot = root <//> _relDir
file' = tRoot <//> _file
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Single $ do
2022-12-20 15:05:40 +03:00
let entryPoint = (defaultEntryPoint tRoot file') {_entryPointNoStdlib = True}
result <- runIOEither iniState entryPoint upToInternal
case mapLeft fromJuvixError result of
Left (Just lexError) -> whenJust (_checkErr lexError) assertFailure
Left Nothing -> assertFailure "The termination checker did not find an error."
Right _ -> assertFailure "An error ocurred but it was not by the termination checker."
}
allTests :: TestTree
allTests =
testGroup
"Termination negative tests"
(map (mkTest . testDescr) tests)
2022-12-20 15:05:40 +03:00
root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/negative/Termination")
tests :: [NegTest]
tests =
[ NegTest
"Mutual recursive functions non terminating"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Mutual.juvix")
$ \case
ErrNoLexOrder {} -> Nothing,
NegTest
"Another mutual block non terminating"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Ord.juvix")
$ \case
ErrNoLexOrder {} -> Nothing,
NegTest
"Only one function, f, marked terminating in a mutual block"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "TerminatingF.juvix")
$ \case
ErrNoLexOrder {} -> Nothing,
NegTest
"Only one function, g, marked terminating in a mutual block"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "TerminatingG.juvix")
$ \case
ErrNoLexOrder {} -> Nothing,
NegTest
"Tree"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Data/Tree.juvix")
$ \case
ErrNoLexOrder {} -> Nothing,
NegTest
"Quicksort is not terminating"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Data/QuickSort.juvix")
$ \case
ErrNoLexOrder {} -> Nothing
]