-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
End-to-end Geb compilation tests (#1942)
* Adds end-to-end tests for compiling Juvix to Geb * Fixes bugs in the Core-to-Geb translation (`<=` and `let`) * Fixes a bug in the Geb evaluator (equality on integers)
- Loading branch information
Showing
58 changed files
with
657 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module BackendGeb.Compilation where | ||
|
||
import BackendGeb.Compilation.Positive qualified as P | ||
import Base | ||
|
||
allTests :: TestTree | ||
allTests = | ||
testGroup | ||
"Compilation to Geb" | ||
[P.allTests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module BackendGeb.Compilation.Base where | ||
|
||
import BackendGeb.FromCore.Base | ||
import Base | ||
import Juvix.Compiler.Backend (Target (TargetGeb)) | ||
import Juvix.Compiler.Builtins (iniState) | ||
import Juvix.Compiler.Core qualified as Core | ||
import Juvix.Compiler.Pipeline | ||
|
||
gebCompilationAssertion :: | ||
Path Abs File -> | ||
Path Abs File -> | ||
(String -> IO ()) -> | ||
Assertion | ||
gebCompilationAssertion mainFile expectedFile step = do | ||
step "Translate to JuvixCore" | ||
cwd <- getCurrentDir | ||
let entryPoint = (defaultEntryPoint cwd mainFile) {_entryPointTarget = TargetGeb} | ||
tab <- (^. Core.coreResultTable) . snd <$> runIO' iniState entryPoint upToCore | ||
coreToGebTranslationAssertion' tab entryPoint expectedFile step |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
module BackendGeb.Compilation.Positive where | ||
|
||
import BackendGeb.Compilation.Base | ||
import Base | ||
|
||
data PosTest = PosTest | ||
{ _name :: String, | ||
_relDir :: Path Rel Dir, | ||
_file :: Path Rel File, | ||
_expectedFile :: Path Rel File | ||
} | ||
|
||
root :: Path Abs Dir | ||
root = relToProject $(mkRelDir "tests/Geb/positive/Compilation") | ||
|
||
testDescr :: PosTest -> TestDescr | ||
testDescr PosTest {..} = | ||
let tRoot = root <//> _relDir | ||
file' = tRoot <//> _file | ||
expected' = tRoot <//> _expectedFile | ||
in TestDescr | ||
{ _testName = _name, | ||
_testRoot = tRoot, | ||
_testAssertion = | ||
Steps $ | ||
gebCompilationAssertion file' expected' | ||
} | ||
|
||
allTests :: TestTree | ||
allTests = | ||
testGroup | ||
"JuvixGeb positive compilation tests" | ||
(map (mkTest . testDescr) tests) | ||
|
||
tests :: [PosTest] | ||
tests = | ||
[ PosTest | ||
"Test001: not function" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test001.juvix") | ||
$(mkRelFile "out/test001.geb"), | ||
PosTest | ||
"Test002: pattern matching" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test002.juvix") | ||
$(mkRelFile "out/test002.geb"), | ||
PosTest | ||
"Test003: inductive types" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test003.juvix") | ||
$(mkRelFile "out/test003.geb"), | ||
PosTest | ||
"Test004: definitions" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test004.juvix") | ||
$(mkRelFile "out/test004.geb"), | ||
PosTest | ||
"Test005: basic arithmetic" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test005.juvix") | ||
$(mkRelFile "out/test005.geb"), | ||
PosTest | ||
"Test006: arithmetic" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test006.juvix") | ||
$(mkRelFile "out/test006.geb"), | ||
PosTest | ||
"Test007: single-constructor inductive types" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test007.juvix") | ||
$(mkRelFile "out/test007.geb"), | ||
PosTest | ||
"Test008: higher-order inductive types" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test008.juvix") | ||
$(mkRelFile "out/test008.geb"), | ||
PosTest | ||
"Test009: let" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test009.juvix") | ||
$(mkRelFile "out/test009.geb"), | ||
PosTest | ||
"Test010: functions returning functions with variable capture" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test010.juvix") | ||
$(mkRelFile "out/test010.geb"), | ||
PosTest | ||
"Test011: applications with lets and cases in function position" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test011.juvix") | ||
$(mkRelFile "out/test011.geb"), | ||
PosTest | ||
"Test012: mid-square hashing (unrolled)" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test012.juvix") | ||
$(mkRelFile "out/test012.geb") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.