2022-04-05 20:57:21 +03:00
|
|
|
module Base
|
|
|
|
( module Test.Tasty,
|
|
|
|
module Test.Tasty.HUnit,
|
2022-07-08 14:59:45 +03:00
|
|
|
module Juvix.Prelude,
|
2022-04-05 20:57:21 +03:00
|
|
|
module Base,
|
2022-12-20 15:05:40 +03:00
|
|
|
module Juvix.Extra.Paths,
|
2023-01-05 19:48:26 +03:00
|
|
|
module Juvix.Prelude.Env,
|
2023-10-23 14:38:52 +03:00
|
|
|
module Juvix.Compiler.Pipeline.Run,
|
|
|
|
module Juvix.Compiler.Pipeline.EntryPoint.IO,
|
2022-04-05 20:57:21 +03:00
|
|
|
)
|
|
|
|
where
|
2022-02-15 16:12:53 +03:00
|
|
|
|
2022-07-25 18:51:42 +03:00
|
|
|
import Control.Monad.Extra as Monad
|
2022-05-05 16:12:17 +03:00
|
|
|
import Data.Algorithm.Diff
|
|
|
|
import Data.Algorithm.DiffOutput
|
2023-12-06 20:24:59 +03:00
|
|
|
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Termination
|
2023-10-23 14:38:52 +03:00
|
|
|
import Juvix.Compiler.Pipeline.EntryPoint.IO
|
2023-12-30 22:15:35 +03:00
|
|
|
import Juvix.Compiler.Pipeline.Loader.PathResolver
|
2023-10-23 14:38:52 +03:00
|
|
|
import Juvix.Compiler.Pipeline.Run
|
2023-12-06 20:24:59 +03:00
|
|
|
import Juvix.Data.Effect.TaggedLock
|
2023-10-30 16:05:52 +03:00
|
|
|
import Juvix.Extra.Paths hiding (rootBuildDir)
|
2023-03-27 11:42:27 +03:00
|
|
|
import Juvix.Prelude hiding (assert)
|
2023-01-05 19:48:26 +03:00
|
|
|
import Juvix.Prelude.Env
|
2022-02-15 16:12:53 +03:00
|
|
|
import Test.Tasty
|
2024-01-11 15:04:38 +03:00
|
|
|
import Test.Tasty.HUnit hiding (assertFailure)
|
|
|
|
import Test.Tasty.HUnit qualified as HUnit
|
2022-02-15 16:12:53 +03:00
|
|
|
|
2022-04-05 20:57:21 +03:00
|
|
|
data AssertionDescr
|
|
|
|
= Single Assertion
|
2022-02-18 15:01:42 +03:00
|
|
|
| Steps ((String -> IO ()) -> Assertion)
|
|
|
|
|
2022-04-05 20:57:21 +03:00
|
|
|
data TestDescr = TestDescr
|
2022-04-07 19:10:53 +03:00
|
|
|
{ _testName :: String,
|
2022-12-20 15:05:40 +03:00
|
|
|
_testRoot :: Path Abs Dir,
|
2022-04-05 20:57:21 +03:00
|
|
|
-- | relative to root
|
2022-04-07 19:10:53 +03:00
|
|
|
_testAssertion :: AssertionDescr
|
2022-02-15 16:12:53 +03:00
|
|
|
}
|
|
|
|
|
2022-08-02 19:58:45 +03:00
|
|
|
newtype WASMInfo = WASMInfo
|
2022-12-20 15:05:40 +03:00
|
|
|
{ _wasmInfoActual :: Path Abs File -> IO Text
|
2022-08-01 13:53:19 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 19:10:53 +03:00
|
|
|
makeLenses ''TestDescr
|
|
|
|
|
2023-01-05 19:48:26 +03:00
|
|
|
data StdlibMode
|
|
|
|
= StdlibInclude
|
|
|
|
| StdlibExclude
|
2022-06-30 12:31:08 +03:00
|
|
|
deriving stock (Show, Eq)
|
|
|
|
|
2023-01-05 19:48:26 +03:00
|
|
|
data CompileMode
|
|
|
|
= WASI StdlibMode
|
|
|
|
| WASM WASMInfo
|
2022-08-01 13:53:19 +03:00
|
|
|
|
2022-02-15 16:12:53 +03:00
|
|
|
mkTest :: TestDescr -> TestTree
|
2022-04-07 19:10:53 +03:00
|
|
|
mkTest TestDescr {..} = case _testAssertion of
|
2023-04-13 12:27:39 +03:00
|
|
|
Single assertion -> testCase _testName (withCurrentDir _testRoot assertion)
|
2022-12-20 15:05:40 +03:00
|
|
|
Steps steps -> testCaseSteps _testName (withCurrentDir _testRoot . steps)
|
2022-05-05 16:12:17 +03:00
|
|
|
|
2023-02-14 18:27:11 +03:00
|
|
|
assertEqDiffText :: String -> Text -> Text -> Assertion
|
|
|
|
assertEqDiffText = assertEqDiff unpack
|
|
|
|
|
2023-08-25 19:37:23 +03:00
|
|
|
assertEqDiff :: (Eq a) => (a -> String) -> String -> a -> a -> Assertion
|
2023-02-14 18:27:11 +03:00
|
|
|
assertEqDiff show_ msg a b
|
2022-05-05 16:12:17 +03:00
|
|
|
| a == b = return ()
|
|
|
|
| otherwise = do
|
|
|
|
putStrLn (pack $ ppDiff (getGroupedDiff pa pb))
|
|
|
|
putStrLn "End diff"
|
2022-07-25 18:51:42 +03:00
|
|
|
Monad.fail msg
|
2022-05-05 16:12:17 +03:00
|
|
|
where
|
2023-02-14 18:27:11 +03:00
|
|
|
pa = lines $ show_ a
|
|
|
|
pb = lines $ show_ b
|
|
|
|
|
|
|
|
assertEqDiffShow :: (Eq a, Show a) => String -> a -> a -> Assertion
|
|
|
|
assertEqDiffShow = assertEqDiff show
|
2022-05-05 16:12:17 +03:00
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
assertCmdExists :: Path Rel File -> Assertion
|
2022-05-30 14:40:52 +03:00
|
|
|
assertCmdExists cmd =
|
2022-12-20 15:05:40 +03:00
|
|
|
assertBool ("Command: " <> toFilePath cmd <> " is not present on $PATH")
|
2022-05-30 14:40:52 +03:00
|
|
|
. isJust
|
|
|
|
=<< findExecutable cmd
|
2023-12-06 20:24:59 +03:00
|
|
|
|
|
|
|
testTaggedLockedToIO :: Sem PipelineAppEffects a -> IO a
|
|
|
|
testTaggedLockedToIO =
|
|
|
|
runFinal
|
|
|
|
. resourceToIOFinal
|
|
|
|
. embedToFinal @IO
|
|
|
|
. runTaggedLock LockModeExclusive
|
|
|
|
|
|
|
|
testRunIO ::
|
|
|
|
forall a.
|
|
|
|
EntryPoint ->
|
|
|
|
Sem (PipelineEff PipelineAppEffects) a ->
|
2023-12-30 22:15:35 +03:00
|
|
|
IO (ResolverState, PipelineResult a)
|
2023-12-06 20:24:59 +03:00
|
|
|
testRunIO e = testTaggedLockedToIO . runIO defaultGenericOptions e
|
|
|
|
|
|
|
|
testDefaultEntryPointIO :: Path Abs Dir -> Path Abs File -> IO EntryPoint
|
|
|
|
testDefaultEntryPointIO cwd mainFile = testTaggedLockedToIO (defaultEntryPointIO cwd mainFile)
|
|
|
|
|
|
|
|
testDefaultEntryPointNoFileIO :: Path Abs Dir -> IO EntryPoint
|
|
|
|
testDefaultEntryPointNoFileIO cwd = testTaggedLockedToIO (defaultEntryPointNoFileIO cwd)
|
|
|
|
|
|
|
|
testRunIOEither ::
|
|
|
|
EntryPoint ->
|
|
|
|
Sem (PipelineEff PipelineAppEffects) a ->
|
2023-12-30 22:15:35 +03:00
|
|
|
IO (Either JuvixError (ResolverState, PipelineResult a))
|
2023-12-06 20:24:59 +03:00
|
|
|
testRunIOEither entry = testTaggedLockedToIO . runIOEither entry
|
|
|
|
|
|
|
|
testRunIOEitherTermination ::
|
|
|
|
EntryPoint ->
|
|
|
|
Sem (Termination ': PipelineEff PipelineAppEffects) a ->
|
2023-12-30 22:15:35 +03:00
|
|
|
IO (Either JuvixError (ResolverState, PipelineResult a))
|
2023-12-06 20:24:59 +03:00
|
|
|
testRunIOEitherTermination entry =
|
2023-12-30 22:15:35 +03:00
|
|
|
testRunIOEither entry
|
2023-12-06 20:24:59 +03:00
|
|
|
. evalTermination iniTerminationState
|
2024-01-11 15:04:38 +03:00
|
|
|
|
|
|
|
assertFailure :: (MonadIO m) => String -> m a
|
|
|
|
assertFailure = liftIO . HUnit.assertFailure
|