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-04-13 12:27:39 +03:00
|
|
|
module Juvix.Compiler.Pipeline,
|
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-04-13 12:27:39 +03:00
|
|
|
import Juvix.Compiler.Pipeline
|
2022-12-20 15:05:40 +03:00
|
|
|
import Juvix.Extra.Paths
|
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
|
|
|
|
import Test.Tasty.HUnit
|
|
|
|
|
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
|
|
|
|
|
|
|
|
assertEqDiff :: Eq a => (a -> String) -> String -> a -> a -> Assertion
|
|
|
|
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
|