1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Compilation/Base.hs
janmasrovira 5de0026d83
Add juvix global project under xdg directory and other improvements (#1963)
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-04-13 11:27:39 +02:00

46 lines
1.6 KiB
Haskell

module Compilation.Base where
import Base
import Core.Compile.Base
import Core.Eval.Base
import Juvix.Compiler.Core qualified as Core
import Juvix.Data.PPOutput
data CompileAssertionMode
= EvalOnly
| -- | Specify text to be sent to stdin of the process under test
CompileOnly Text
| EvalAndCompile
compileAssertion ::
CompileAssertionMode ->
Path Abs File ->
Path Abs File ->
(String -> IO ()) ->
Assertion
compileAssertion mode mainFile expectedFile step = do
step "Translate to JuvixCore"
entryPoint <- defaultEntryPointCwdIO mainFile
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
case run $ runReader Core.defaultCoreOptions $ runError $ Core.toEval' tab of
Left err -> assertFailure (show (pretty (fromJuvixError @GenericError err)))
Right tab' -> do
let evalAssertion = coreEvalAssertion' tab' mainFile expectedFile step
compileAssertion' stdinText = coreCompileAssertion' tab' mainFile expectedFile stdinText step
case mode of
EvalOnly -> evalAssertion
CompileOnly stdinText -> compileAssertion' stdinText
EvalAndCompile -> evalAssertion >> compileAssertion' ""
compileErrorAssertion ::
Path Abs File ->
(String -> IO ()) ->
Assertion
compileErrorAssertion mainFile step = do
step "Translate to JuvixCore"
entryPoint <- defaultEntryPointCwdIO mainFile
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStripped' tab of
Left _ -> assertBool "" True
Right _ -> assertFailure "no error"