1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-19 12:51:39 +03:00
juvix/test/Compilation/Base.hs
Jan Mas Rovira 69594edc7b
Read Package on demand and cache it (#2548)
This patch dramatically increases the efficiency of `juvix dev root`,
which was unnecessarily parsing all dependencies included in the
`Package.juvix` file. Other commands that do not require the `Package`
will also be faster.

It also refactors some functions so that the `TaggedLock` effect is run
globally.

I've added `singletons-base` as a dependency so we can have `++` on the
type level. We've tried to define a type family ourselves but inference
was not working properly.
2023-12-06 18:24:59 +01:00

60 lines
1.9 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 ::
Path Abs Dir ->
Int ->
CompileAssertionMode ->
Path Abs File ->
Path Abs File ->
(String -> IO ()) ->
Assertion
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
step "Translate to JuvixCore"
entryPoint <- adjustEntry <$> testDefaultEntryPointIO root' mainFile
tab <- (^. Core.coreResultTable) . snd <$> testRunIO 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' 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' ""
compileErrorAssertion ::
Path Abs Dir ->
Path Abs File ->
(String -> IO ()) ->
Assertion
compileErrorAssertion root' mainFile step = do
step "Translate to JuvixCore"
entryPoint <- testDefaultEntryPointIO root' mainFile
tab <- (^. Core.coreResultTable) . snd <$> testRunIO entryPoint upToCore
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStripped' tab of
Left _ -> assertBool "" True
Right _ -> assertFailure "no error"