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-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-11-16 18:19:52 +03:00
|
|
|
Path Abs Dir ->
|
2023-10-20 13:03:56 +03:00
|
|
|
Int ->
|
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-11-28 18:43:14 +03:00
|
|
|
compileAssertion = compileAssertionEntry id
|
|
|
|
|
|
|
|
compileAssertionEntry ::
|
|
|
|
(EntryPoint -> EntryPoint) ->
|
|
|
|
Path Abs Dir ->
|
|
|
|
Int ->
|
|
|
|
CompileAssertionMode ->
|
|
|
|
Path Abs File ->
|
|
|
|
Path Abs File ->
|
|
|
|
(String -> IO ()) ->
|
|
|
|
Assertion
|
|
|
|
compileAssertionEntry adjustEntry root' optLevel mode mainFile expectedFile step = do
|
2023-01-12 13:22:32 +03:00
|
|
|
step "Translate to JuvixCore"
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- adjustEntry <$> testDefaultEntryPointIO root' mainFile
|
2023-12-30 22:15:35 +03:00
|
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToStoredCore
|
|
|
|
let tab' = Core.computeCombinedInfoTable (_pipelineResult ^. Core.coreResultModule)
|
|
|
|
evalAssertion = coreEvalAssertion' EvalModePlain tab' mainFile expectedFile step
|
|
|
|
compileAssertion' stdinText = coreCompileAssertion' optLevel 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 ::
|
2023-11-16 18:19:52 +03:00
|
|
|
Path Abs Dir ->
|
2023-03-27 11:42:27 +03:00
|
|
|
Path Abs File ->
|
|
|
|
(String -> IO ()) ->
|
|
|
|
Assertion
|
2023-11-16 18:19:52 +03:00
|
|
|
compileErrorAssertion root' mainFile step = do
|
2023-03-27 11:42:27 +03:00
|
|
|
step "Translate to JuvixCore"
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- testDefaultEntryPointIO root' mainFile
|
2023-12-30 22:15:35 +03:00
|
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToCore
|
|
|
|
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStored' (_pipelineResult ^. Core.coreResultModule) >>= Core.toStripped' of
|
2023-03-27 11:42:27 +03:00
|
|
|
Left _ -> assertBool "" True
|
|
|
|
Right _ -> assertFailure "no error"
|