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,
|
|
|
|
)
|
|
|
|
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
|
2022-07-08 14:59:45 +03:00
|
|
|
import Juvix.Prelude
|
2022-05-16 18:17:28 +03:00
|
|
|
import System.Environment (lookupEnv)
|
2022-02-15 16:12:53 +03:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
2022-05-05 16:12:17 +03:00
|
|
|
import Text.Show.Pretty hiding (Html)
|
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,
|
|
|
|
_testRoot :: FilePath,
|
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
|
|
|
|
{ _wasmInfoActual :: FilePath -> IO Text
|
2022-08-01 13:53:19 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 19:10:53 +03:00
|
|
|
makeLenses ''TestDescr
|
|
|
|
|
2022-06-30 12:31:08 +03:00
|
|
|
data StdlibMode = StdlibInclude | StdlibExclude
|
|
|
|
deriving stock (Show, Eq)
|
|
|
|
|
2022-08-01 13:53:19 +03:00
|
|
|
data CompileMode = WASI StdlibMode | WASM WASMInfo
|
|
|
|
|
2022-02-15 16:12:53 +03:00
|
|
|
mkTest :: TestDescr -> TestTree
|
2022-04-07 19:10:53 +03:00
|
|
|
mkTest TestDescr {..} = case _testAssertion of
|
|
|
|
Single assertion -> testCase _testName $ withCurrentDirectory _testRoot assertion
|
|
|
|
Steps steps -> testCaseSteps _testName (withCurrentDirectory _testRoot . steps)
|
2022-05-05 16:12:17 +03:00
|
|
|
|
|
|
|
assertEqDiff :: (Eq a, Show a) => String -> a -> a -> Assertion
|
|
|
|
assertEqDiff msg a b
|
|
|
|
| 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
|
|
|
|
pa = lines $ ppShow a
|
|
|
|
pb = lines $ ppShow b
|
|
|
|
|
|
|
|
assertCmdExists :: FilePath -> Assertion
|
2022-05-30 14:40:52 +03:00
|
|
|
assertCmdExists cmd =
|
|
|
|
assertBool ("Command: " <> cmd <> " is not present on $PATH")
|
|
|
|
. isJust
|
|
|
|
=<< findExecutable cmd
|
2022-05-16 18:17:28 +03:00
|
|
|
|
|
|
|
assertEnvVar :: String -> String -> IO String
|
|
|
|
assertEnvVar msg varName = fromMaybeM (assertFailure msg) (lookupEnv varName)
|