2022-05-30 14:40:52 +03:00
|
|
|
module Termination.Negative (module Termination.Negative) where
|
|
|
|
|
|
|
|
import Base
|
2023-06-20 12:02:37 +03:00
|
|
|
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Termination
|
2023-11-16 18:19:52 +03:00
|
|
|
import Juvix.Data.Effect.TaggedLock
|
2022-05-30 14:40:52 +03:00
|
|
|
|
|
|
|
type FailMsg = String
|
|
|
|
|
|
|
|
data NegTest = NegTest
|
|
|
|
{ _name :: String,
|
2022-12-20 15:05:40 +03:00
|
|
|
_relDir :: Path Rel Dir,
|
|
|
|
_file :: Path Rel File,
|
2022-05-30 14:40:52 +03:00
|
|
|
_checkErr :: TerminationError -> Maybe FailMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
testDescr :: NegTest -> TestDescr
|
|
|
|
testDescr NegTest {..} =
|
2022-12-20 15:05:40 +03:00
|
|
|
let tRoot = root <//> _relDir
|
|
|
|
file' = tRoot <//> _file
|
2022-05-30 14:40:52 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2023-11-16 18:19:52 +03:00
|
|
|
entryPoint <- set entryPointNoStdlib True <$> defaultEntryPointIO' LockModeExclusive tRoot file'
|
|
|
|
result <- runIOEither' LockModeExclusive entryPoint upToInternalTyped
|
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)
|
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/negative/Termination")
|
2022-05-30 14:40:52 +03:00
|
|
|
|
|
|
|
tests :: [NegTest]
|
|
|
|
tests =
|
|
|
|
[ NegTest
|
|
|
|
"Mutual recursive functions non terminating"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Mutual.juvix")
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Another mutual block non terminating"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "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-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "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-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "TerminatingG.juvix")
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Tree"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Data/Tree.juvix")
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Quicksort is not terminating"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Data/QuickSort.juvix")
|
2023-08-30 17:38:59 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Loop in axiom type"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Axiom.juvix")
|
2023-10-27 11:19:07 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Loop with default arguments"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "DefaultArguments.juvix")
|
2022-05-30 14:40:52 +03:00
|
|
|
$ \case
|
|
|
|
ErrNoLexOrder {} -> Nothing
|
|
|
|
]
|