2023-01-12 13:22:32 +03:00
|
|
|
module Compilation.Base where
|
|
|
|
|
|
|
|
import Base
|
2023-03-14 18:24:07 +03:00
|
|
|
import Core.Compile.Base
|
2023-02-15 13:30:12 +03:00
|
|
|
import Core.Eval.Base
|
2023-03-30 14:39:27 +03:00
|
|
|
import Juvix.Compiler.Core qualified as Core
|
2023-03-20 12:13:07 +03:00
|
|
|
import Juvix.Data.PPOutput
|
2023-01-12 13:22:32 +03:00
|
|
|
|
2023-03-21 17:34:46 +03:00
|
|
|
data CompileAssertionMode
|
|
|
|
= EvalOnly
|
|
|
|
| -- | Specify text to be sent to stdin of the process under test
|
|
|
|
CompileOnly Text
|
|
|
|
| EvalAndCompile
|
|
|
|
|
2023-01-12 13:22:32 +03:00
|
|
|
compileAssertion ::
|
2023-03-21 17:34:46 +03:00
|
|
|
CompileAssertionMode ->
|
2023-01-12 13:22:32 +03:00
|
|
|
Path Abs File ->
|
|
|
|
Path Abs File ->
|
|
|
|
(String -> IO ()) ->
|
|
|
|
Assertion
|
2023-03-21 17:34:46 +03:00
|
|
|
compileAssertion mode mainFile expectedFile step = do
|
2023-01-12 13:22:32 +03:00
|
|
|
step "Translate to JuvixCore"
|
2023-04-13 12:27:39 +03:00
|
|
|
entryPoint <- defaultEntryPointCwdIO mainFile
|
2023-03-30 14:39:27 +03:00
|
|
|
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
|
2023-03-27 11:42:27 +03:00
|
|
|
case run $ runReader Core.defaultCoreOptions $ runError $ Core.toEval' tab of
|
2023-03-20 12:13:07 +03:00
|
|
|
Left err -> assertFailure (show (pretty (fromJuvixError @GenericError err)))
|
|
|
|
Right tab' -> do
|
2023-05-15 19:01:40 +03:00
|
|
|
let evalAssertion = coreEvalAssertion' EvalModePlain tab' mainFile expectedFile step
|
2023-03-21 17:34:46 +03:00
|
|
|
compileAssertion' stdinText = coreCompileAssertion' tab' mainFile expectedFile stdinText step
|
|
|
|
case mode of
|
|
|
|
EvalOnly -> evalAssertion
|
|
|
|
CompileOnly stdinText -> compileAssertion' stdinText
|
|
|
|
EvalAndCompile -> evalAssertion >> compileAssertion' ""
|
2023-03-27 11:42:27 +03:00
|
|
|
|
|
|
|
compileErrorAssertion ::
|
|
|
|
Path Abs File ->
|
|
|
|
(String -> IO ()) ->
|
|
|
|
Assertion
|
|
|
|
compileErrorAssertion mainFile step = do
|
|
|
|
step "Translate to JuvixCore"
|
2023-04-13 12:27:39 +03:00
|
|
|
entryPoint <- defaultEntryPointCwdIO mainFile
|
2023-03-30 14:39:27 +03:00
|
|
|
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
|
2023-04-04 12:58:36 +03:00
|
|
|
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStripped' tab of
|
2023-03-27 11:42:27 +03:00
|
|
|
Left _ -> assertBool "" True
|
|
|
|
Right _ -> assertFailure "no error"
|