2022-07-25 19:38:44 +03:00
|
|
|
module Reachability.Positive where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import Data.HashSet qualified as HashSet
|
2022-09-26 20:14:17 +03:00
|
|
|
import Juvix.Compiler.Internal.Language qualified as Internal
|
|
|
|
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Context qualified as Internal
|
2023-11-16 18:19:52 +03:00
|
|
|
import Juvix.Data.Effect.TaggedLock
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
data PosTest = PosTest
|
|
|
|
{ _name :: String,
|
2022-12-20 15:05:40 +03:00
|
|
|
_relDir :: Path Rel Dir,
|
2022-07-25 19:38:44 +03:00
|
|
|
_stdlibMode :: StdlibMode,
|
2022-12-20 15:05:40 +03:00
|
|
|
_file :: Path Rel File,
|
2022-07-25 19:38:44 +03:00
|
|
|
_reachable :: HashSet String
|
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''PosTest
|
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/positive")
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} =
|
2022-12-20 15:05:40 +03:00
|
|
|
let tRoot = root <//> _relDir
|
|
|
|
file' = tRoot <//> _file
|
2022-07-25 19:38:44 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Steps $ \step -> do
|
|
|
|
let noStdlib = _stdlibMode == StdlibExclude
|
2023-04-13 12:27:39 +03:00
|
|
|
entryPoint <-
|
|
|
|
set entryPointNoStdlib noStdlib
|
2023-11-16 18:19:52 +03:00
|
|
|
<$> defaultEntryPointIO' LockModeExclusive tRoot file'
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
step "Pipeline up to reachability"
|
2023-11-16 18:19:52 +03:00
|
|
|
p :: Internal.InternalTypedResult <- snd <$> runIOExclusive entryPoint upToInternalReachability
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
step "Check reachability results"
|
2022-09-26 20:14:17 +03:00
|
|
|
let names = concatMap getNames (p ^. Internal.resultModules)
|
2022-07-25 19:38:44 +03:00
|
|
|
mapM_ check names
|
|
|
|
}
|
|
|
|
where
|
|
|
|
check n = assertBool ("unreachable not filtered: " ++ unpack n) (HashSet.member (unpack n) _reachable)
|
|
|
|
|
2022-09-26 20:14:17 +03:00
|
|
|
getNames :: Internal.Module -> [Text]
|
2023-06-30 16:01:46 +03:00
|
|
|
getNames m =
|
|
|
|
concatMap getDeclName (m ^. Internal.moduleBody . Internal.moduleStatements)
|
|
|
|
<> concatMap (getNames . (^. Internal.importModule . Internal.moduleIxModule)) (m ^. Internal.moduleBody . Internal.moduleImports)
|
2022-07-25 19:38:44 +03:00
|
|
|
where
|
2023-10-10 16:55:17 +03:00
|
|
|
getDeclName :: Internal.MutualBlock -> [Text]
|
2022-07-25 19:38:44 +03:00
|
|
|
getDeclName = \case
|
2023-10-10 16:55:17 +03:00
|
|
|
(Internal.MutualBlock f) -> map getMutualName (toList f)
|
2023-05-15 14:02:09 +03:00
|
|
|
getMutualName :: Internal.MutualStatement -> Text
|
|
|
|
getMutualName = \case
|
|
|
|
Internal.StatementFunction f -> f ^. Internal.funDefName . Internal.nameText
|
|
|
|
Internal.StatementInductive f -> f ^. Internal.inductiveName . Internal.nameText
|
2023-10-10 16:55:17 +03:00
|
|
|
Internal.StatementAxiom ax -> ax ^. (Internal.axiomName . Internal.nameText)
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Reachability positive tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
|
|
|
[ PosTest
|
|
|
|
"Reachability with modules"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Reachability")
|
2022-07-25 19:38:44 +03:00
|
|
|
StdlibInclude
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelFile "M.juvix")
|
2022-07-25 19:38:44 +03:00
|
|
|
( HashSet.fromList
|
|
|
|
["f", "g", "h", "Bool", "Maybe"]
|
|
|
|
),
|
|
|
|
PosTest
|
|
|
|
"Reachability with modules and standard library"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Reachability")
|
2022-07-25 19:38:44 +03:00
|
|
|
StdlibInclude
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelFile "N.juvix")
|
2022-07-25 19:38:44 +03:00
|
|
|
( HashSet.fromList
|
2023-11-03 12:01:03 +03:00
|
|
|
[ "test",
|
|
|
|
"Unit",
|
|
|
|
"Bool",
|
|
|
|
"Nat",
|
|
|
|
"Int",
|
|
|
|
"fromNat",
|
|
|
|
"Natural",
|
|
|
|
"fromInt",
|
|
|
|
"Integral",
|
|
|
|
"naturalNatI",
|
|
|
|
"naturalIntI",
|
|
|
|
"integralIntI",
|
|
|
|
"+",
|
|
|
|
"*",
|
|
|
|
"sub",
|
|
|
|
"udiv",
|
|
|
|
"div",
|
|
|
|
"mod",
|
|
|
|
"intSubNat",
|
|
|
|
"negNat",
|
|
|
|
"neg",
|
|
|
|
"-"
|
|
|
|
]
|
2022-07-25 19:38:44 +03:00
|
|
|
),
|
|
|
|
PosTest
|
|
|
|
"Reachability with public imports"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Reachability")
|
2022-07-25 19:38:44 +03:00
|
|
|
StdlibInclude
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelFile "O.juvix")
|
2022-07-25 19:38:44 +03:00
|
|
|
( HashSet.fromList
|
2023-01-27 18:21:38 +03:00
|
|
|
["f", "g", "h", "k", "Bool", "Maybe", "Nat"]
|
2022-07-25 19:38:44 +03:00
|
|
|
)
|
|
|
|
]
|