Skip to content

Commit

Permalink
Add solver unit tests for sub-library dependencies (issue haskell#6039).
Browse files Browse the repository at this point in the history
  • Loading branch information
grayjay committed May 13, 2019
1 parent 6134cee commit 1efd4d3
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Distribution.Solver.Types.PackageConstraint
import qualified Distribution.Solver.Types.PackagePath as P
import UnitTests.Distribution.Solver.Modular.DSL
import UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils
import Distribution.Types.LibraryVisibility

tests :: [TF.TestTree]
tests = [
Expand Down Expand Up @@ -281,7 +282,7 @@ tests = [
, runTest $ mkTest dbBJ7 "bj7" ["A"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
, runTest $ indep $ mkTest dbBJ8 "bj8" ["A", "B"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
]
, testGroup "library dependencies" [
, testGroup "main library dependencies" [
let db = [Right $ exAvNoLibrary "A" 1 `withExe` ExExe "exe" []]
in runTest $ mkTest db "install build target without a library" ["A"] $
solverSuccess [("A", 1)]
Expand All @@ -298,6 +299,46 @@ tests = [
in runTest $ mkTest db "choose version of build-depends dependency that has a library" ["A"] $
solverSuccess [("A", 1), ("B", 1)]
]
, testGroup "sub-library dependencies" [
let db = [ Right $ exAv "A" 1 [ExSubLibAny "B" "sub-lib"]
, Right $ exAv "B" 1 [] ]
in runTest $
mkTest db "reject package that is missing required sub-library" ["A"] $
solverFailure $ isInfixOf $
"rejecting: B-1.0.0 (does not contain library 'sub-lib', which is required by A)"

, let db = [ Right $ exAv "A" 1 [ExSubLibAny "B" "sub-lib"]
, Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib" LibraryVisibilityPrivate [] ]
in runTest $
mkTest db "reject package with private but required sub-library" ["A"] $
solverFailure $ isInfixOf $ "rejecting: B-1.0.0 (library 'sub-lib' is private, but it is required by A)"

, let db = [ Right $ exAv "A" 1 [ExAny "B"]
, Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib" LibraryVisibilityPrivate []
, Right $ exAv "C" 1 [ExSubLibAny "B" "sub-lib"] ]
goals :: [ExampleVar]
goals = [
P QualNone "A"
, P QualNone "B"
, P QualNone "C"
]
in runTest $ goalOrder goals $
mkTest db "reject package that requires a private sub-library" ["A", "C"] $
solverFailure $ isInfixOf $
"rejecting: C-1.0.0 (requires library 'sub-lib' from B, but the component is private)"

, let db = [ Right $ exAv "A" 1 [ExSubLibAny "B" "sub-lib-v1"]
, Right $ exAv "B" 2 [] `withSubLibrary` ExSubLib "sub-lib-v2" LibraryVisibilityPublic []
, Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib-v1" LibraryVisibilityPublic [] ]
in runTest $ mkTest db "choose version of package containing correct sub-library" ["A"] $
solverSuccess [("A", 1), ("B", 1)]

, let db = [ Right $ exAv "A" 1 [ExSubLibAny "B" "sub-lib"]
, Right $ exAv "B" 2 [] `withSubLibrary` ExSubLib "sub-lib" LibraryVisibilityPrivate []
, Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib" LibraryVisibilityPublic [] ]
in runTest $ mkTest db "choose version of package with public sub-library" ["A"] $
solverSuccess [("A", 1), ("B", 1)]
]
-- build-tool-depends dependencies
, testGroup "build-tool-depends" [
runTest $ mkTest dbBuildTools "simple exe dependency" ["A"] (solverSuccess [("A", 1), ("bt-pkg", 2)])
Expand Down

0 comments on commit 1efd4d3

Please sign in to comment.