From 2695c0f296a14d870d91822108f5d52105fddc4e Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 12 May 2019 19:26:23 -0700 Subject: [PATCH] Add solver unit tests for sub-library dependencies (issue #6039). --- .../Distribution/Solver/Modular/Solver.hs | 43 ++++++++++++++++++- 1 file changed, 42 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 d6c1a1db2ae..7439c710f4e 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -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 = [ @@ -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)] @@ -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)])