mirror of
https://github.com/anoma/juvix.git
synced 2024-12-16 19:22:26 +03:00
657de73b98
* import all non-compile axioms with alphanum names in entrypoint This commit adds `__attribute__((input_name(<name>)))` to the type signature of all axioms that do not have a compile block. This indicates to the compiler that this function should be added to the input table of the WASM binary. Adds a test that an imported function can be called from Juvix. * test: Run node command in same directory as WASM output * Don't generate importName for non-alphnum axioms * Add a tutorial on Juvix module to JS interop via Wasm
64 lines
1.6 KiB
Haskell
64 lines
1.6 KiB
Haskell
module Base
|
|
( module Test.Tasty,
|
|
module Test.Tasty.HUnit,
|
|
module Juvix.Prelude,
|
|
module Base,
|
|
)
|
|
where
|
|
|
|
import Control.Monad.Extra as Monad
|
|
import Data.Algorithm.Diff
|
|
import Data.Algorithm.DiffOutput
|
|
import Juvix.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
|
|
}
|
|
|
|
newtype WASMInfo = WASMInfo
|
|
{ _wasmInfoActual :: FilePath -> IO Text
|
|
}
|
|
|
|
makeLenses ''TestDescr
|
|
|
|
data StdlibMode = StdlibInclude | StdlibExclude
|
|
deriving stock (Show, Eq)
|
|
|
|
data CompileMode = WASI StdlibMode | WASM WASMInfo
|
|
|
|
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"
|
|
Monad.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)
|