Files
gyehoek-hs/test/Gyehoek/Test/Golden.hs
T
msyds 6949ff7fdf
build / build (push) Successful in 20s
convert (limited) letrec
2026-08-18 20:38:17 -06:00

88 lines
2.3 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 (catches, ErrorCall(..), Handler(..))
import Gyehoek.Stack.VM (writeObj)
import Data.Text qualified as T
import System.Exit (ExitCode(..))
import Test.Tasty.ExpectedFailure (expectFail)
brokenWasmTests :: List String
brokenWasmTests =
[ "adder"
, "apply-twice"
, "square"
, "fn-of-fn"
, "let-fn"
, "apply2"
, "factorial"
]
brokenStackifyTests :: List String
brokenStackifyTests =
[ "apply-twice"
, "adder"
, "apply2"
, "let-fn"
]
root :: IO TestTree
root = do
all_cases <- listDirectory "golden"
let tests = all_cases
& fmap ("golden"</>)
testGroup "golden" <$> sequenceA
[ 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 =
catches (do rs <- Driver.eval_e2e scmfile
pure ( ExitSuccess
, T.unwords . fmap writeObj $ rs
, "" ))
[ Handler \(ErrorCall s) ->
pure (ExitFailure 1, "", T.pack s)
]
in maybeBroken testname brokenStackifyTests $
goldenVsAction
testname
resultfile
action
printProcResult