2022-05-30 14:40:52 +03:00
|
|
|
module Termination.Negative (module Termination.Negative) where
|
|
|
|
|
|
|
|
import Base
|
2022-07-08 14:59:45 +03:00
|
|
|
import Juvix.Pipeline
|
|
|
|
import Juvix.Termination
|
2022-05-30 14:40:52 +03:00
|
|
|
|
|
|
|
type FailMsg = String
|
|
|
|
|
|
|
|
data NegTest = NegTest
|
|
|
|
{ _name :: String,
|
|
|
|
_relDir :: FilePath,
|
|
|
|
_file :: FilePath,
|
|
|
|
_checkErr :: TerminationError -> Maybe FailMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
testDescr :: NegTest -> TestDescr
|
|
|
|
testDescr NegTest {..} =
|
|
|
|
let tRoot = root </> _relDir
|
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2022-06-30 12:31:08 +03:00
|
|
|
let entryPoint = (defaultEntryPoint _file) {_entryPointNoStdlib = True}
|
2022-05-30 14:40:52 +03:00
|
|
|
result <- runIOEither (upToMicroJuvix entryPoint)
|
2022-07-08 14:59:45 +03:00
|
|
|
case mapLeft fromJuvixError result of
|
2022-05-30 14:40:52 +03:00
|
|
|
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)
|
|
|
|
|
|
|
|
root :: FilePath
|
|
|
|
root = "tests/negative/Termination"
|
|
|
|
|
|
|
|
tests :: [NegTest]
|
|
|
|
tests =
|
|
|
|
[ NegTest
|
|
|
|
"Mutual recursive functions non terminating"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"Mutual.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Another mutual block non terminating"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"Ord.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Only one function, f, marked terminating in a mutual block"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"TerminatingF.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Only one function, g, marked terminating in a mutual block"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"TerminatingG.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"f x := f x is not terminating"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"ToEmpty.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Tree"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"Data/Tree.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Quicksort is not terminating"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"Data/QuickSort.juvix"
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing
|
|
|
|
]
|