1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Base.hs
Paul Cadman ed78f2636b
Embed standard library in the minijuvix binary (#210)
* Embed stdlib in minijuvix library

We add a new step at the beginning of the pipeline called Setup that
registers the modules in the standard library with the Files effect. The
standard library is then used when the Scoper queries the Files effect
for modules as it resolves import statements.

Use of the standard library can be disabled using the global
`--no-stdlib` command-line option.

* CI: Checkout submodules recursively for stdlib

* Add a new `--no-stdlib` option to shell check

* Poke CI

* CI: Checkout submodules in the test job
2022-06-30 11:31:08 +02:00

57 lines
1.4 KiB
Haskell

module Base
( module Test.Tasty,
module Test.Tasty.HUnit,
module MiniJuvix.Prelude,
module Base,
)
where
import Data.Algorithm.Diff
import Data.Algorithm.DiffOutput
import MiniJuvix.Prelude
import System.Environment (lookupEnv)
import Test.Tasty
import Test.Tasty.HUnit
import Text.Show.Pretty hiding (Html)
data AssertionDescr
= Single Assertion
| Steps ((String -> IO ()) -> Assertion)
data TestDescr = TestDescr
{ _testName :: String,
_testRoot :: FilePath,
-- | relative to root
_testAssertion :: AssertionDescr
}
makeLenses ''TestDescr
data StdlibMode = StdlibInclude | StdlibExclude
deriving stock (Show, Eq)
mkTest :: TestDescr -> TestTree
mkTest TestDescr {..} = case _testAssertion of
Single assertion -> testCase _testName $ withCurrentDirectory _testRoot assertion
Steps steps -> testCaseSteps _testName (withCurrentDirectory _testRoot . steps)
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"
fail msg
where
pa = lines $ ppShow a
pb = lines $ ppShow b
assertCmdExists :: FilePath -> Assertion
assertCmdExists cmd =
assertBool ("Command: " <> cmd <> " is not present on $PATH")
. isJust
=<< findExecutable cmd
assertEnvVar :: String -> String -> IO String
assertEnvVar msg varName = fromMaybeM (assertFailure msg) (lookupEnv varName)