From 21929f1ae2d0cb09d28f6b68b2ad421168a9488c Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Thu, 21 Nov 2019 01:06:32 -0800 Subject: [PATCH] Add solver unit tests for sub-library dependencies (issue #6039). --- .../Distribution/Solver/Modular/Solver.hs | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index 65a7d6114bf..3abd45f5047 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -281,7 +281,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)] @@ -298,6 +298,62 @@ 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 $ exAvNoLibrary "B" 1 `withSubLibrary` exSubLib "sub-lib" [] ] + 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 [ExSubLibAny "B" "sub-lib"] + , Right $ exAvNoLibrary "B" 1 + `withSubLibrary` exSubLib "sub-lib" [ExFlagged "make-lib-private" (dependencies []) publicDependencies] ] + in runTest $ constraints [ExFlagConstraint (ScopeAnyQualifier "B") "make-lib-private" True] $ + mkTest db "reject package with sub-library made private by flag constraint" ["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 [ExSubLibAny "B" "sub-lib"] + , Right $ exAvNoLibrary "B" 1 + `withSubLibrary` exSubLib "sub-lib" [ExFlagged "make-lib-private" (dependencies []) publicDependencies] ] + in runTest $ + mkTest db "treat sub-library as visible even though flag choice could make it private" ["A"] $ + solverSuccess [("A", 1), ("B", 1)] + + , let db = [ Right $ exAv "A" 1 [ExAny "B"] + , Right $ exAv "B" 1 [] `withSubLibrary` exSubLib "sub-lib" [] + , 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" publicDependencies + , Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib-v1" publicDependencies ] + 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" (dependencies []) + , Right $ exAv "B" 1 [] `withSubLibrary` ExSubLib "sub-lib" publicDependencies ] + 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)])