Skip to content

Commit

Permalink
Add positive tests for package loading
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Oct 23, 2023
1 parent ba0faa8 commit bff579c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ where

import Base
import Package.Negative qualified as N
import Package.Positive qualified as P

allTests :: TestTree
allTests = testGroup "Package loading tests" [N.allTests]
allTests = testGroup "Package loading tests" [N.allTests, P.allTests]
62 changes: 62 additions & 0 deletions test/Package/Positive.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Package.Positive where

import Base
import Juvix.Compiler.Pipeline.Package

type FailMsg = String

data PosTest = PosTest
{ _name :: String,
_relDir :: Path Rel Dir,
_checkPackage :: Package -> BuildDir -> Maybe FailMsg
}

root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/positive/PackageLoader")

testDescr :: PosTest -> TestDescr
testDescr PosTest {..} =
let tRoot = root <//> _relDir
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Single $ do
withTempDir' $ \d -> do
let buildDir = CustomBuildDir (Abs d)
res <- runM . runError @JuvixError . runFilesIO . readPackage tRoot $ buildDir
case res of
Right p -> whenJust (_checkPackage p buildDir) assertFailure
Left {} -> assertFailure "An error ocurred when reading the package."
}

allTests :: TestTree
allTests =
testGroup
"Package loading positive tests"
( map (mkTest . testDescr) packageLoadingTests
)

packageLoadingTests :: [PosTest]
packageLoadingTests =
[
PosTest
"empty YAML is valid"
$(mkRelDir "YamlEmpty")
$ \p _ -> if
| p ^. packageName == defaultPackageName -> Nothing
| otherwise -> Just "Package did not have default name",
PosTest
"no dependencies uses default stdlib"
$(mkRelDir "YamlNoDependencies")
$ \p b -> case p ^? packageDependencies . _head of
Just d -> if
| d == defaultStdlibDep b -> Nothing
| otherwise -> Just "Package dependency is not the default standard library"
_ -> Just "The package has no dependencies",
PosTest
"empty dependencies does not use default stdlib"
$(mkRelDir "YamlEmptyDependencies")
$ \p _ -> if
| null (p ^. packageDependencies) -> Nothing
| otherwise -> Just "Expected dependencies to be empty"
]
Empty file.
2 changes: 2 additions & 0 deletions tests/positive/PackageLoader/YamlEmptyDependencies/juvix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: abc
dependencies: []
1 change: 1 addition & 0 deletions tests/positive/PackageLoader/YamlNoDependencies/juvix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: abc

0 comments on commit bff579c

Please sign in to comment.