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
|
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
|
|
|
|
<$> defaultEntryPointCwdIO file'
|
2022-07-25 19:38:44 +03:00
|
|
|
|
|
|
|
step "Pipeline up to reachability"
|
2023-03-30 14:39:27 +03:00
|
|
|
p :: Internal.InternalTypedResult <- snd <$> runIO' 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]
|
|
|
|
getNames m = concatMap getDeclName (m ^. (Internal.moduleBody . Internal.moduleStatements))
|
2022-07-25 19:38:44 +03:00
|
|
|
where
|
2022-09-26 20:14:17 +03:00
|
|
|
getDeclName :: Internal.Statement -> [Text]
|
2022-07-25 19:38:44 +03:00
|
|
|
getDeclName = \case
|
2023-05-15 14:02:09 +03:00
|
|
|
Internal.StatementMutual (Internal.MutualBlock f) -> map getMutualName (toList f)
|
2022-09-26 20:14:17 +03:00
|
|
|
Internal.StatementAxiom ax -> [ax ^. (Internal.axiomName . Internal.nameText)]
|
|
|
|
Internal.StatementInclude i -> getNames (i ^. Internal.includeModule)
|
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
|
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-04-13 10:16:49 +03:00
|
|
|
["test", "Unit", "Bool", "Nat", "Int"]
|
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
|
|
|
)
|
|
|
|
]
|