mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 01:52:11 +03:00
01a44e436d
* Big refactor in process * remove unnecessary functions from the prelude * remove comments
88 lines
2.6 KiB
Haskell
88 lines
2.6 KiB
Haskell
module Termination.Positive where
|
|
|
|
import Base
|
|
import Juvix.Compiler.Pipeline
|
|
import Termination.Negative qualified as N
|
|
|
|
data PosTest = PosTest
|
|
{ _name :: String,
|
|
_relDir :: FilePath,
|
|
_file :: FilePath
|
|
}
|
|
|
|
root :: FilePath
|
|
root = "tests/positive/Termination"
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
testDescr PosTest {..} =
|
|
let tRoot = root </> _relDir
|
|
in TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = tRoot,
|
|
_testAssertion = Single $ do
|
|
let entryPoint = (defaultEntryPoint _file) {_entryPointNoStdlib = True}
|
|
(void . runIO) (upToInternal entryPoint)
|
|
}
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Testing --no-termination flag with all termination negative tests
|
|
--------------------------------------------------------------------------------
|
|
|
|
rootNegTests :: FilePath
|
|
rootNegTests = "tests/negative/Termination"
|
|
|
|
testDescrFlag :: N.NegTest -> TestDescr
|
|
testDescrFlag N.NegTest {..} =
|
|
let tRoot = rootNegTests </> _relDir
|
|
in TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = tRoot,
|
|
_testAssertion = Single $ do
|
|
let entryPoint =
|
|
EntryPoint
|
|
{ _entryPointRoot = ".",
|
|
_entryPointNoTermination = True,
|
|
_entryPointNoPositivity = False,
|
|
_entryPointNoStdlib = True,
|
|
_entryPointPackage = emptyPackage,
|
|
_entryPointModulePaths = pure _file
|
|
}
|
|
|
|
(void . runIO) (upToInternal entryPoint)
|
|
}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
tests :: [PosTest]
|
|
tests =
|
|
[ PosTest "Ackerman nice def. is terminating" "." "Ack.juvix",
|
|
PosTest "Recursive functions on Lists" "." "Data/List.juvix"
|
|
]
|
|
|
|
testsWithKeyword :: [PosTest]
|
|
testsWithKeyword =
|
|
[ PosTest "terminating added to fx:=fx" "." "ToEmpty.juvix",
|
|
PosTest "terminating for all functions in the mutual block" "." "Mutual.juvix",
|
|
PosTest "Undefined is terminating by assumption" "." "Undefined.juvix"
|
|
]
|
|
|
|
negTests :: [N.NegTest]
|
|
negTests = N.tests
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
allTests :: TestTree
|
|
allTests =
|
|
testGroup
|
|
"Positive tests"
|
|
[ testGroup
|
|
"Well-known terminating functions"
|
|
(map (mkTest . testDescr) tests),
|
|
testGroup
|
|
"Bypass termination checking using --non-termination flag on negative tests"
|
|
(map (mkTest . testDescrFlag) negTests),
|
|
testGroup
|
|
"Terminating keyword"
|
|
(map (mkTest . testDescr) testsWithKeyword)
|
|
]
|