82 lines
2.4 KiB
Haskell
82 lines
2.4 KiB
Haskell
module Gyehoek.Test.Golden (root) where
|
|
|
|
import Test.Tasty (TestTree, testGroup)
|
|
import Test.Tasty.Silver
|
|
import Gyehoek.Driver qualified as Driver
|
|
import System.FilePath
|
|
import Data.List (List)
|
|
import Data.Functor ((<&>))
|
|
import System.Directory
|
|
import Data.Function
|
|
import System.Environment.Blank (getEnvDefault)
|
|
import qualified System.Process.Text as PT
|
|
import Control.Exception (SomeException (SomeException), Exception (..), catch)
|
|
import Gyehoek.Stack.VM (writeObj)
|
|
import Data.Text qualified as T
|
|
import System.Exit (ExitCode(..))
|
|
import Test.Tasty.ExpectedFailure (expectFail, ignoreTestBecause)
|
|
import Control.DeepSeq (($!!))
|
|
|
|
|
|
brokenWasmTests :: List String
|
|
brokenWasmTests =
|
|
[
|
|
]
|
|
|
|
brokenStackifyTests :: List String
|
|
brokenStackifyTests =
|
|
[ "adder"
|
|
, "let-fn"
|
|
, "callcc-nested1" -- requires closure-conversion
|
|
]
|
|
|
|
root :: IO TestTree
|
|
root = do
|
|
all_cases <- listDirectory "golden"
|
|
let tests = all_cases
|
|
& fmap ("golden"</>)
|
|
testGroup "golden" <$> sequenceA
|
|
[ ignoreTestBecause "wasm codegen is on the backburner"
|
|
<$> wasmTests tests
|
|
, stackifyTests tests
|
|
]
|
|
|
|
maybeBroken name broken = applyWhen (name `elem` broken) expectFail
|
|
wasmTests :: List FilePath -> IO TestTree
|
|
wasmTests files = do
|
|
cmd <- getEnvDefault "GYEHOEK_RUNTIME"
|
|
"runtime/target/debug/gyehoek-runtime"
|
|
pure $ testGroup "wasm execution" $ files <&> \test ->
|
|
let testname = takeFileName test
|
|
scmfile = test </> "source.scm"
|
|
resultfile = test </> "exec"
|
|
action = do
|
|
t <- Driver.lower_e2e scmfile
|
|
PT.readProcessWithExitCode cmd ["-"] t
|
|
in maybeBroken testname brokenWasmTests $
|
|
goldenVsAction
|
|
testname
|
|
resultfile
|
|
action
|
|
printProcResult
|
|
|
|
stackifyTests :: List FilePath -> IO TestTree
|
|
stackifyTests files = do
|
|
pure $ testGroup "stackified execution" $ files <&> \test ->
|
|
let testname = takeFileName test
|
|
scmfile = test </> "source.scm"
|
|
resultfile = test </> "exec"
|
|
action =
|
|
catch @SomeException
|
|
(do rs <- Driver.eval_e2e scmfile
|
|
pure $!! ( ExitSuccess
|
|
, T.unwords . fmap writeObj $ rs
|
|
, "" ))
|
|
\e -> pure (ExitFailure 1, "", T.pack $ displayException e)
|
|
in maybeBroken testname brokenStackifyTests $
|
|
goldenVsAction
|
|
testname
|
|
resultfile
|
|
action
|
|
printProcResult
|