fix catching of exceptions in tests

This commit is contained in:
2026-08-18 23:56:22 -06:00
parent eb51f4fff7
commit ca1b53f3d1
11 changed files with 61 additions and 22 deletions
+1
View File
@@ -0,0 +1 @@
(call/cc (_) 1234)
+5
View File
@@ -0,0 +1,5 @@
(call/cc
(λ (k1)
(call/cc
(λ (k2)
(k1 456)))))
+2
View File
@@ -0,0 +1,2 @@
ret > ExitSuccess
out > 456
+5
View File
@@ -0,0 +1,5 @@
(call/cc
(λ (k1)
(call/cc
(λ (k2)
(k2 456)))))
+4 -2
View File
@@ -71,6 +71,7 @@ library
, binary , binary
, bytestring , bytestring
, containers , containers
, deepseq
, effectful , effectful
, effectful-core , effectful-core
, effectful-plugin , effectful-plugin
@@ -112,6 +113,7 @@ test-suite test
build-depends: build-depends:
, base , base
, deepseq
, directory , directory
, effectful , effectful
, filepath , filepath
@@ -119,11 +121,11 @@ test-suite test
, gyehoek , gyehoek
, lens , lens
, process-extras , process-extras
, text
, sexp-grammar , sexp-grammar
, tasty , tasty
, tasty-expected-failure
, tasty-hunit , tasty-hunit
, tasty-silver , tasty-silver
, tasty-expected-failure , text
default-language: GHC2024 default-language: GHC2024
+1
View File
@@ -34,6 +34,7 @@ import Gyehoek.Stack.VM (eval, writeObj, Obj)
import qualified Data.Text as T import qualified Data.Text as T
import Data.List (List) import Data.List (List)
import Gyehoek.Stack.Syntax (encodeProgram) import Gyehoek.Stack.Syntax (encodeProgram)
import Effectful.Exception
main :: IO () main :: IO ()
+16 -8
View File
@@ -57,12 +57,13 @@ import Effectful.FileSystem (runFileSystem)
import qualified Effectful.FileSystem.IO as FS import qualified Effectful.FileSystem.IO as FS
import qualified Data.Text.Encoding as T import qualified Data.Text.Encoding as T
import qualified Effectful.FileSystem.IO.ByteString as FB import qualified Effectful.FileSystem.IO.ByteString as FB
import Control.DeepSeq (NFData)
newtype Name = MkName { inner :: Text } newtype Name = MkName { inner :: Text }
deriving newtype (Show, Eq, Ord, IsString, Gen, Hashable) deriving newtype (Show, Eq, Ord, IsString, Gen, Hashable)
deriving stock (Generic, Data) deriving stock (Generic, Data)
deriving anyclass (Wrapped) deriving anyclass (Wrapped, NFData)
instance Prefixed Name where instance Prefixed Name where
prefixed (MkName s) = _Wrapped' . prefixed @Text s . from _Wrapped' prefixed (MkName s) = _Wrapped' . prefixed @Text s . from _Wrapped'
@@ -87,7 +88,8 @@ data Prim e
| PrimMakeClosure { code :: e, env :: List e } | PrimMakeClosure { code :: e, env :: List e }
| PrimEnvRef e Int | PrimEnvRef e Int
| PrimCallCC e | PrimCallCC e
deriving (Show, Generic, Functor, Foldable, Traversable, Data, Eq) deriving stock (Show, Generic, Functor, Foldable, Traversable, Data, Eq)
deriving anyclass (NFData)
instance Each (Prim e) (Prim e') e e' instance Each (Prim e) (Prim e') e e'
@@ -97,7 +99,8 @@ data Lit
| LitBool Bool | LitBool Bool
| LitString Text | LitString Text
| LitQuote Sexp | LitQuote Sexp
deriving (Show, Generic, Data, Eq) deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
pattern Void :: Lit pattern Void :: Lit
pattern Void = LitNil pattern Void = LitNil
@@ -105,7 +108,8 @@ pattern Void = LitNil
data Def data Def
= DefConstant Name Exp = DefConstant Name Exp
| DefProcedure Name (List Name) (List Exp) | DefProcedure Name (List Name) (List Exp)
deriving (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Exp data Exp
= ExpLet (NonEmpty (Name, Exp)) Exp = ExpLet (NonEmpty (Name, Exp)) Exp
@@ -117,24 +121,28 @@ data Exp
| ExpLambda (List Name) Exp | ExpLambda (List Name) Exp
| ExpVar Name | ExpVar Name
| ExpApply Exp (List Exp) | ExpApply Exp (List Exp)
deriving (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Sexp data Sexp
= SexpCons Sexp Sexp = SexpCons Sexp Sexp
| SexpSymbol Text | SexpSymbol Text
| SexpLit Lit | SexpLit Lit
deriving (Show, Generic, Data, Eq) deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
data CommandOrDef data CommandOrDef
= Command Exp = Command Exp
| Definition Def | Definition Def
| Begin (List CommandOrDef) | Begin (List CommandOrDef)
deriving (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Program = MkProgram data Program = MkProgram
{ commandsAndDefs :: List CommandOrDef { commandsAndDefs :: List CommandOrDef
} }
deriving (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
instance Each Program Program (Either Exp Def) (Either Exp Def) where instance Each Program Program (Either Exp Def) (Either Exp Def) where
each = #commandsAndDefs . each . go each = #commandsAndDefs . each . go
+9 -1
View File
@@ -1,6 +1,7 @@
{-# LANGUAGE TemplateHaskellQuotes #-} {-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveAnyClass #-}
module Gyehoek.Stack.Syntax module Gyehoek.Stack.Syntax
( Program(..) ( Program(..)
, Block(..) , Block(..)
@@ -32,6 +33,7 @@ import Effectful
import Gyehoek.Scheme.Syntax (Name(..), Lit(..), Prim(..)) import Gyehoek.Scheme.Syntax (Name(..), Lit(..), Prim(..))
import GHC.Exts (IsList(..)) import GHC.Exts (IsList(..))
import Data.List (intersperse) import Data.List (intersperse)
import Control.DeepSeq (NFData)
newtype Program = MkProgram newtype Program = MkProgram
@@ -39,6 +41,7 @@ newtype Program = MkProgram
} }
deriving stock (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving newtype (Semigroup, Monoid) deriving newtype (Semigroup, Monoid)
deriving anyclass (NFData)
instance IsList Program where instance IsList Program where
type Item Program = Block type Item Program = Block
@@ -51,6 +54,7 @@ data Block = MkBlock
, code :: List Instr , code :: List Instr
} }
deriving stock (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
instance Each Block Block Instr Instr where instance Each Block Block Instr Instr where
each = #code . each each = #code . each
@@ -64,11 +68,13 @@ data Instr
| Call Val (List Val) | Call Val (List Val)
| If Val (List Instr) (List Instr) | If Val (List Instr) (List Instr)
deriving stock (Show, Generic, Data) deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Val data Val
= ValReg Name = ValReg Name
| ValImm Imm | ValImm Imm
deriving stock (Show, Generic, Data, Eq) deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
pattern ValLabel :: Name -> Val pattern ValLabel :: Name -> Val
pattern ValLabel x = ValImm (ImmLabel x) pattern ValLabel x = ValImm (ImmLabel x)
@@ -78,10 +84,12 @@ data Imm
| ImmBool Bool | ImmBool Bool
| ImmLabel Name | ImmLabel Name
deriving stock (Show, Generic, Data, Eq) deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
data Obj data Obj
= ObjImm Imm = ObjImm Imm
deriving (Show, Generic, Data, Eq) deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
--- sexp work --- sexp work
+18 -11
View File
@@ -10,11 +10,12 @@ import System.Directory
import Data.Function import Data.Function
import System.Environment.Blank (getEnvDefault) import System.Environment.Blank (getEnvDefault)
import qualified System.Process.Text as PT import qualified System.Process.Text as PT
import Control.Exception (catches, ErrorCall(..), Handler(..)) import Control.Exception (catches, ErrorCall(..), Handler(..), catch, SomeException (SomeException), Exception (displayException))
import Gyehoek.Stack.VM (writeObj) import Gyehoek.Stack.VM (writeObj)
import Data.Text qualified as T import Data.Text qualified as T
import System.Exit (ExitCode(..)) import System.Exit (ExitCode(..))
import Test.Tasty.ExpectedFailure (expectFail) import Test.Tasty.ExpectedFailure (expectFail, ignoreTestBecause)
import Control.DeepSeq (($!!))
brokenWasmTests :: List String brokenWasmTests :: List String
@@ -36,8 +37,9 @@ root = do
let tests = all_cases let tests = all_cases
& fmap ("golden"</>) & fmap ("golden"</>)
testGroup "golden" <$> sequenceA testGroup "golden" <$> sequenceA
[ {-wasmTests tests [ ignoreTestBecause "wasm codegen is on the backburner"
, -}stackifyTests tests <$> wasmTests tests
, stackifyTests tests
] ]
maybeBroken name broken = applyWhen (name `elem` broken) expectFail maybeBroken name broken = applyWhen (name `elem` broken) expectFail
@@ -65,14 +67,19 @@ stackifyTests files = do
let testname = takeFileName test let testname = takeFileName test
scmfile = test </> "source.scm" scmfile = test </> "source.scm"
resultfile = test </> "exec" resultfile = test </> "exec"
-- action = Driver.eval_e2e' scmfile >>= \case
-- Right rs ->
-- pure ( ExitSuccess
-- , T.unwords . fmap writeObj $ rs
-- , "" )
-- Left e -> pure (ExitFailure 1, "", T.pack $ displayException e)
action = action =
catches (do rs <- Driver.eval_e2e scmfile catch @SomeException
pure ( ExitSuccess (do rs <- Driver.eval_e2e scmfile
, T.unwords . fmap writeObj $ rs pure $!! ( ExitSuccess
, "" )) , T.unwords . fmap writeObj $ rs
[ Handler \(ErrorCall s) -> , "" ))
pure (ExitFailure 1, "", T.pack s) \e -> pure (ExitFailure 1, "", T.pack $ displayException e)
]
in maybeBroken testname brokenStackifyTests $ in maybeBroken testname brokenStackifyTests $
goldenVsAction goldenVsAction
testname testname