2022-05-05 16:12:17 +03:00
|
|
|
module BackendC.Positive where
|
|
|
|
|
2022-06-28 11:25:43 +03:00
|
|
|
import BackendC.Base
|
2022-05-05 16:12:17 +03:00
|
|
|
import Base
|
2022-08-02 19:58:45 +03:00
|
|
|
import System.Process qualified as P
|
2022-05-05 16:12:17 +03:00
|
|
|
|
|
|
|
data PosTest = PosTest
|
|
|
|
{ _name :: String,
|
2022-06-30 12:31:08 +03:00
|
|
|
_relDir :: FilePath,
|
2022-08-01 13:53:19 +03:00
|
|
|
_compileMode :: CompileMode
|
2022-05-05 16:12:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''PosTest
|
|
|
|
|
|
|
|
root :: FilePath
|
|
|
|
root = "tests/positive/MiniC"
|
|
|
|
|
|
|
|
mainFile :: FilePath
|
2022-07-08 14:59:45 +03:00
|
|
|
mainFile = "Input.juvix"
|
2022-05-05 16:12:17 +03:00
|
|
|
|
2022-05-13 12:44:06 +03:00
|
|
|
expectedFile :: FilePath
|
|
|
|
expectedFile = "expected.golden"
|
|
|
|
|
2022-08-02 19:58:45 +03:00
|
|
|
actualCallExport :: Text -> [Text] -> FilePath -> IO Text
|
|
|
|
actualCallExport funName funArgs outputFile =
|
|
|
|
pack
|
|
|
|
<$> P.readProcess
|
|
|
|
"wasmer"
|
|
|
|
(["run", outputFile, "--invoke", unpack funName] <> (unpack <$> funArgs))
|
|
|
|
""
|
|
|
|
|
|
|
|
actualCallNode :: FilePath -> FilePath -> IO Text
|
|
|
|
actualCallNode jsFile outputFile = do
|
|
|
|
assertCmdExists "node"
|
|
|
|
let outputDir = takeDirectory outputFile
|
|
|
|
outputJsFile = outputDir </> jsFile
|
|
|
|
copyFile jsFile outputJsFile
|
|
|
|
withCurrentDirectory
|
|
|
|
outputDir
|
|
|
|
( pack
|
|
|
|
<$> P.readProcess
|
|
|
|
"node"
|
|
|
|
[outputJsFile]
|
|
|
|
""
|
|
|
|
)
|
|
|
|
|
2022-05-05 16:12:17 +03:00
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} =
|
|
|
|
let tRoot = root </> _relDir
|
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
2022-08-01 13:53:19 +03:00
|
|
|
_testAssertion = Steps $ case _compileMode of
|
|
|
|
WASI stdlibMode -> wasiClangAssertion stdlibMode mainFile expectedFile ""
|
|
|
|
WASM i -> wasmClangAssertion i mainFile expectedFile
|
2022-05-05 16:12:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Backend C positive tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
2022-08-01 13:53:19 +03:00
|
|
|
[ PosTest "HelloWorld" "HelloWorld" (WASI StdlibExclude),
|
|
|
|
PosTest "Inductive types and pattern matching" "Nat" (WASI StdlibExclude),
|
|
|
|
PosTest "Polymorphic types" "Polymorphism" (WASI StdlibExclude),
|
|
|
|
PosTest "Polymorphic axioms" "PolymorphicAxioms" (WASI StdlibExclude),
|
|
|
|
PosTest "Polymorphic target" "PolymorphicTarget" (WASI StdlibExclude),
|
|
|
|
PosTest "Multiple modules" "MultiModules" (WASI StdlibExclude),
|
|
|
|
PosTest "Higher Order Functions" "HigherOrder" (WASI StdlibExclude),
|
|
|
|
PosTest "Higher Order Functions and explicit holes" "PolymorphismHoles" (WASI StdlibExclude),
|
|
|
|
PosTest "Closures with no environment" "ClosureNoEnv" (WASI StdlibExclude),
|
|
|
|
PosTest "Closures with environment" "ClosureEnv" (WASI StdlibExclude),
|
|
|
|
PosTest "SimpleFungibleTokenImplicit" "SimpleFungibleTokenImplicit" (WASI StdlibExclude),
|
|
|
|
PosTest "Mutually recursive function" "MutuallyRecursive" (WASI StdlibExclude),
|
|
|
|
PosTest "Nested List type" "NestedList" (WASI StdlibExclude),
|
|
|
|
PosTest "Builtin types and functions" "Builtins" (WASI StdlibExclude),
|
|
|
|
PosTest "Import from embedded standard library" "StdlibImport" (WASI StdlibInclude),
|
|
|
|
PosTest "Axiom without a compile block" "AxiomNoCompile" (WASI StdlibInclude),
|
2022-08-02 19:58:45 +03:00
|
|
|
PosTest "Invoke a function using exported name" "ExportName" (WASM (WASMInfo (actualCallExport "fun" []))),
|
|
|
|
PosTest "Invoke a function using exported name with args" "ExportNameArgs" (WASM (WASMInfo (actualCallExport "fun" ["0"]))),
|
|
|
|
PosTest "Invoke an imported function in Juvix and exported function in JS" "ImportExportName" (WASM (WASMInfo (actualCallNode "input.js")))
|
2022-05-05 16:12:17 +03:00
|
|
|
]
|