From 9ebbba8472b61877cde06a7443f5cfaaf1dce23b Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 5 Nov 2024 12:00:28 -0800 Subject: [PATCH] Add tests --- .../Solver/Types/SourcePackage.hs | 4 +- .../Client/ProjectConfig/Legacy.hs | 10 +- cabal-install/tests/IntegrationTests2.hs | 573 ++++++++++++------ .../Distribution/Client/ArbitraryInstances.hs | 37 ++ .../Distribution/Client/FetchUtils.hs | 46 +- .../Distribution/Client/ProjectConfig.hs | 55 +- .../Distribution/Client/TreeDiffInstances.hs | 4 + .../Distribution/Solver/Modular/DSL.hs | 21 +- .../use-local-version-of-package.out | 3 +- .../use-local-package-as-setup-dep.out | 3 +- .../ConditionalAndImport/cabal.out | 16 +- .../SourceRepositoryPackage/A.hs | 3 + .../SourceRepositoryPackage/cabal.out | 16 + .../SourceRepositoryPackage/cabal.project | 7 + .../SourceRepositoryPackage/cabal.test.hs | 5 + .../SourceRepositoryPackage/plain.cabal | 11 + .../repo/my-lib-1.0/my-lib.cabal | 11 + .../repo/my-lib-1.0/src/MyLib.hs | 4 + .../repo/my-lib-2.0/my-lib.cabal | 11 + .../repo/my-lib-2.0/src/MyLib.hs | 4 + .../NewSdist/MultiTarget/all-test-sute.out | 2 +- .../MultiTarget/target-remote-package.out | 2 +- .../MultiTarget/valid-and-test-suite.out | 2 +- 23 files changed, 634 insertions(+), 216 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/A.hs create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.out create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.project create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/plain.cabal create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/my-lib.cabal create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/src/MyLib.hs create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/my-lib.cabal create mode 100644 cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/src/MyLib.hs diff --git a/cabal-install-solver/src/Distribution/Solver/Types/SourcePackage.hs b/cabal-install-solver/src/Distribution/Solver/Types/SourcePackage.hs index 35cba9b6e4a..1c4d5b4686f 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/SourcePackage.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/SourcePackage.hs @@ -1,5 +1,7 @@ {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveDataTypeable #-} + module Distribution.Solver.Types.SourcePackage ( PackageDescriptionOverride , SourcePackage(..) @@ -25,7 +27,7 @@ data SourcePackage loc = SourcePackage , srcpkgSource :: loc , srcpkgDescrOverride :: PackageDescriptionOverride } - deriving (Eq, Show, Generic, Typeable) + deriving (Eq, Show, Functor, Generic, Typeable) instance Binary loc => Binary (SourcePackage loc) instance Structured loc => Structured (SourcePackage loc) diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index d63e95a1697..089de936a04 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -1286,7 +1286,7 @@ legacyProjectConfigFieldDescrs :: ConstraintSource -> [FieldDescr LegacyProjectC legacyProjectConfigFieldDescrs constraintSrc = [ newLineListField "packages" - (pretty . fmap (Disp.text . renderPackageLocationToken)) + (Disp.text . renderPackageLocationToken . constraintPackage) ( (\pkg -> WithConstraintSource{constraintPackage = pkg, constraintConstraint = constraintSrc}) `fmap` parsePackageLocationTokenQ ) @@ -1294,7 +1294,7 @@ legacyProjectConfigFieldDescrs constraintSrc = (\v flags -> flags{legacyPackages = v}) , newLineListField "optional-packages" - (pretty . fmap (Disp.text . renderPackageLocationToken)) + (Disp.text . renderPackageLocationToken . constraintPackage) ( (\pkg -> WithConstraintSource{constraintPackage = pkg, constraintConstraint = constraintSrc}) `fmap` parsePackageLocationTokenQ ) @@ -1302,7 +1302,7 @@ legacyProjectConfigFieldDescrs constraintSrc = (\v flags -> flags{legacyPackagesOptional = v}) , commaNewLineListFieldParsec "extra-packages" - pretty + (pretty . constraintPackage) ( (\pkg -> WithConstraintSource{constraintPackage = pkg, constraintConstraint = constraintSrc}) `fmap` parsec ) @@ -1424,7 +1424,7 @@ legacySharedConfigFieldDescrs constraintSrc = . addFields [ commaNewLineListFieldParsec "constraints" - pretty + (pretty . constraintPackage) ( (\constraint -> WithConstraintSource{constraintPackage = constraint, constraintConstraint = constraintSrc}) `fmap` parsec ) @@ -1432,7 +1432,7 @@ legacySharedConfigFieldDescrs constraintSrc = (\v conf -> conf{configExConstraints = v}) , commaNewLineListFieldParsec "preferences" - pretty + (pretty . constraintPackage) ( (\preference -> WithConstraintSource{constraintPackage = preference, constraintConstraint = constraintSrc}) `fmap` parsec ) diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index a74d235c6e5..c878346bc08 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -38,12 +38,18 @@ import Distribution.Client.Types , UnresolvedSourcePackage ) import Distribution.Solver.Types.ConstraintSource - ( ConstraintSource (ConstraintSourceUnknown) + ( ConstraintSource (..) ) import Distribution.Solver.Types.PackageConstraint ( PackageProperty (PackagePropertySource) ) import Distribution.Solver.Types.SourcePackage as SP +import Distribution.Solver.Types.ProjectConfigPath + ( ProjectConfigPath (..) + ) +import Distribution.Solver.Types.WithConstraintSource + ( WithConstraintSource (..) + ) import qualified Distribution.Client.CmdBench as CmdBench import qualified Distribution.Client.CmdBuild as CmdBuild @@ -191,194 +197,305 @@ testTargetSelectors reportSubCase = do reportSubCase "cwd" do Right ts <- readTargetSelectors' [] - ts @?= [TargetPackage TargetImplicitCwd ["p-0.1"] Nothing] + ts + @?= [ WithConstraintSource + { constraintPackage = TargetPackage TargetImplicitCwd ["p-0.1"] Nothing + , constraintConstraint = ConstraintSourceImplicit + } + ] reportSubCase "all" do Right ts <- readTargetSelectors' - ["all", ":all"] - ts @?= replicate 2 (TargetAllPackages Nothing) + [ WithConstraintSource + { constraintPackage = "all" + , constraintConstraint = ConstraintSourceCommandlineFlag + } + , WithConstraintSource + { constraintPackage = ":all" + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ] + ts + @?= replicate + 2 + ( WithConstraintSource + { constraintPackage = TargetAllPackages Nothing + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) reportSubCase "filter" do Right ts <- - readTargetSelectors' - [ "libs" - , ":cwd:libs" - , "flibs" - , ":cwd:flibs" - , "exes" - , ":cwd:exes" - , "tests" - , ":cwd:tests" - , "benchmarks" - , ":cwd:benchmarks" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "libs" + , ":cwd:libs" + , "flibs" + , ":cwd:flibs" + , "exes" + , ":cwd:exes" + , "tests" + , ":cwd:tests" + , "benchmarks" + , ":cwd:benchmarks" + ] zipWithM_ (@?=) ts - [ TargetPackage TargetImplicitCwd ["p-0.1"] (Just kind) + [ WithConstraintSource + { constraintPackage = TargetPackage TargetImplicitCwd ["p-0.1"] (Just kind) + , constraintConstraint = ConstraintSourceCommandlineFlag + } | kind <- concatMap (replicate 2) [LibKind ..] ] reportSubCase "all:filter" do Right ts <- - readTargetSelectors' - [ "all:libs" - , ":all:libs" - , "all:flibs" - , ":all:flibs" - , "all:exes" - , ":all:exes" - , "all:tests" - , ":all:tests" - , "all:benchmarks" - , ":all:benchmarks" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "all:libs" + , ":all:libs" + , "all:flibs" + , ":all:flibs" + , "all:exes" + , ":all:exes" + , "all:tests" + , ":all:tests" + , "all:benchmarks" + , ":all:benchmarks" + ] zipWithM_ (@?=) ts - [ TargetAllPackages (Just kind) + [ WithConstraintSource + { constraintPackage = TargetAllPackages (Just kind) + , constraintConstraint = ConstraintSourceCommandlineFlag + } | kind <- concatMap (replicate 2) [LibKind ..] ] reportSubCase "pkg" do Right ts <- - readTargetSelectors' - [ ":pkg:p" - , "." - , "./" - , "p.cabal" - , "q" - , ":pkg:q" - , "q/" - , "./q/" - , "q/q.cabal" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ ":pkg:p" + , "." + , "./" + , "p.cabal" + , "q" + , ":pkg:q" + , "q/" + , "./q/" + , "q/q.cabal" + ] ts - @?= replicate 4 (mkTargetPackage "p-0.1") - ++ replicate 5 (mkTargetPackage "q-0.1") + @?= replicate + 4 + ( WithConstraintSource + { constraintPackage = mkTargetPackage "p-0.1" + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + ++ replicate + 5 + ( WithConstraintSource + { constraintPackage = mkTargetPackage "q-0.1" + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) reportSubCase "pkg:filter" do Right ts <- - readTargetSelectors' - [ "p:libs" - , ".:libs" - , ":pkg:p:libs" - , "p:flibs" - , ".:flibs" - , ":pkg:p:flibs" - , "p:exes" - , ".:exes" - , ":pkg:p:exes" - , "p:tests" - , ".:tests" - , ":pkg:p:tests" - , "p:benchmarks" - , ".:benchmarks" - , ":pkg:p:benchmarks" - , "q:libs" - , "q/:libs" - , ":pkg:q:libs" - , "q:flibs" - , "q/:flibs" - , ":pkg:q:flibs" - , "q:exes" - , "q/:exes" - , ":pkg:q:exes" - , "q:tests" - , "q/:tests" - , ":pkg:q:tests" - , "q:benchmarks" - , "q/:benchmarks" - , ":pkg:q:benchmarks" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "p:libs" + , ".:libs" + , ":pkg:p:libs" + , "p:flibs" + , ".:flibs" + , ":pkg:p:flibs" + , "p:exes" + , ".:exes" + , ":pkg:p:exes" + , "p:tests" + , ".:tests" + , ":pkg:p:tests" + , "p:benchmarks" + , ".:benchmarks" + , ":pkg:p:benchmarks" + , "q:libs" + , "q/:libs" + , ":pkg:q:libs" + , "q:flibs" + , "q/:flibs" + , ":pkg:q:flibs" + , "q:exes" + , "q/:exes" + , ":pkg:q:exes" + , "q:tests" + , "q/:tests" + , ":pkg:q:tests" + , "q:benchmarks" + , "q/:benchmarks" + , ":pkg:q:benchmarks" + ] zipWithM_ (@?=) ts $ - [ TargetPackage TargetExplicitNamed ["p-0.1"] (Just kind) + [ WithConstraintSource + { constraintPackage = TargetPackage TargetExplicitNamed ["p-0.1"] (Just kind) + , constraintConstraint = ConstraintSourceCommandlineFlag + } | kind <- concatMap (replicate 3) [LibKind ..] ] - ++ [ TargetPackage TargetExplicitNamed ["q-0.1"] (Just kind) + ++ [ WithConstraintSource + { constraintPackage = TargetPackage TargetExplicitNamed ["q-0.1"] (Just kind) + , constraintConstraint = ConstraintSourceCommandlineFlag + } | kind <- concatMap (replicate 3) [LibKind ..] ] reportSubCase "component" do Right ts <- - readTargetSelectors' - [ "p" - , "lib:p" - , "p:lib:p" - , ":pkg:p:lib:p" - , "lib:q" - , "q:lib:q" - , ":pkg:q:lib:q" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "p" + , "lib:p" + , "p:lib:p" + , ":pkg:p:lib:p" + , "lib:q" + , "q:lib:q" + , ":pkg:q:lib:q" + ] ts - @?= replicate 4 (TargetComponent "p-0.1" (CLibName LMainLibName) WholeComponent) - ++ replicate 3 (TargetComponent "q-0.1" (CLibName LMainLibName) WholeComponent) + @?= replicate + 4 + ( WithConstraintSource + { constraintPackage = TargetComponent "p-0.1" (CLibName LMainLibName) WholeComponent + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + ++ replicate + 3 + ( WithConstraintSource + { constraintPackage = TargetComponent "q-0.1" (CLibName LMainLibName) WholeComponent + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) reportSubCase "module" do Right ts <- - readTargetSelectors' - [ "P" - , "lib:p:P" - , "p:p:P" - , ":pkg:p:lib:p:module:P" - , "QQ" - , "lib:q:QQ" - , "q:q:QQ" - , ":pkg:q:lib:q:module:QQ" - , "pexe:PMain" -- p:P or q:QQ would be ambiguous here - , "qexe:QMain" -- package p vs component p - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "P" + , "lib:p:P" + , "p:p:P" + , ":pkg:p:lib:p:module:P" + , "QQ" + , "lib:q:QQ" + , "q:q:QQ" + , ":pkg:q:lib:q:module:QQ" + , "pexe:PMain" -- p:P or q:QQ would be ambiguous here + , "qexe:QMain" -- package p vs component p + ] ts - @?= replicate 4 (TargetComponent "p-0.1" (CLibName LMainLibName) (ModuleTarget "P")) - ++ replicate 4 (TargetComponent "q-0.1" (CLibName LMainLibName) (ModuleTarget "QQ")) - ++ [ TargetComponent "p-0.1" (CExeName "pexe") (ModuleTarget "PMain") - , TargetComponent "q-0.1" (CExeName "qexe") (ModuleTarget "QMain") + @?= replicate 4 (WithConstraintSource{constraintPackage = TargetComponent "p-0.1" (CLibName LMainLibName) (ModuleTarget "P"), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ replicate 4 (WithConstraintSource{constraintPackage = TargetComponent "q-0.1" (CLibName LMainLibName) (ModuleTarget "QQ"), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ [ WithConstraintSource + { constraintPackage = TargetComponent "p-0.1" (CExeName "pexe") (ModuleTarget "PMain") + , constraintConstraint = ConstraintSourceCommandlineFlag + } + , WithConstraintSource + { constraintPackage = TargetComponent "q-0.1" (CExeName "qexe") (ModuleTarget "QMain") + , constraintConstraint = ConstraintSourceCommandlineFlag + } ] reportSubCase "file" do Right ts <- - readTargetSelectors' - [ "./P.hs" - , "p:P.lhs" - , "lib:p:P.hsc" - , "p:p:P.hsc" - , ":pkg:p:lib:p:file:P.y" - , "q/QQ.hs" - , "q:QQ.lhs" - , "lib:q:QQ.hsc" - , "q:q:QQ.hsc" - , ":pkg:q:lib:q:file:QQ.y" - , "q/Q.hs" - , "q:Q.lhs" - , "lib:q:Q.hsc" - , "q:q:Q.hsc" - , ":pkg:q:lib:q:file:Q.y" - , "app/Main.hs" - , "p:app/Main.hs" - , "exe:ppexe:app/Main.hs" - , "p:ppexe:app/Main.hs" - , ":pkg:p:exe:ppexe:file:app/Main.hs" - , "a p p/Main.hs" - , "p:a p p/Main.hs" - , "exe:pppexe:a p p/Main.hs" - , "p:pppexe:a p p/Main.hs" - , ":pkg:p:exe:pppexe:file:a p p/Main.hs" - ] + readTargetSelectors' $ + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "./P.hs" + , "p:P.lhs" + , "lib:p:P.hsc" + , "p:p:P.hsc" + , ":pkg:p:lib:p:file:P.y" + , "q/QQ.hs" + , "q:QQ.lhs" + , "lib:q:QQ.hsc" + , "q:q:QQ.hsc" + , ":pkg:q:lib:q:file:QQ.y" + , "q/Q.hs" + , "q:Q.lhs" + , "lib:q:Q.hsc" + , "q:q:Q.hsc" + , ":pkg:q:lib:q:file:Q.y" + , "app/Main.hs" + , "p:app/Main.hs" + , "exe:ppexe:app/Main.hs" + , "p:ppexe:app/Main.hs" + , ":pkg:p:exe:ppexe:file:app/Main.hs" + , "a p p/Main.hs" + , "p:a p p/Main.hs" + , "exe:pppexe:a p p/Main.hs" + , "p:pppexe:a p p/Main.hs" + , ":pkg:p:exe:pppexe:file:a p p/Main.hs" + ] ts - @?= replicate 5 (TargetComponent "p-0.1" (CLibName LMainLibName) (FileTarget "P")) - ++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "QQ")) - ++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "Q")) - ++ replicate 5 (TargetComponent "p-0.1" (CExeName "ppexe") (FileTarget ("app" "Main.hs"))) - ++ replicate 5 (TargetComponent "p-0.1" (CExeName "pppexe") (FileTarget ("a p p" "Main.hs"))) + @?= replicate 5 (WithConstraintSource{constraintPackage = TargetComponent "p-0.1" (CLibName LMainLibName) (FileTarget "P"), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ replicate 5 (WithConstraintSource{constraintPackage = TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "QQ"), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ replicate 5 (WithConstraintSource{constraintPackage = TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "Q"), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ replicate 5 (WithConstraintSource{constraintPackage = TargetComponent "p-0.1" (CExeName "ppexe") (FileTarget ("app" "Main.hs")), constraintConstraint = ConstraintSourceCommandlineFlag}) + ++ replicate 5 (WithConstraintSource{constraintPackage = TargetComponent "p-0.1" (CExeName "pppexe") (FileTarget ("a p p" "Main.hs")), constraintConstraint = ConstraintSourceCommandlineFlag}) -- Note there's a bit of an inconsistency here: for the single-part -- syntax the target has to point to a file that exists, whereas for -- all the other forms we don't require that. @@ -392,15 +509,25 @@ testTargetSelectorBadSyntax :: Assertion testTargetSelectorBadSyntax = do (_, _, _, localPackages, _) <- configureProject testdir config let targets = - [ "foo:" - , "foo::bar" - , " :foo" - , "foo: :bar" - , "a:b:c:d:e:f" - , "a:b:c:d:e:f:g:h" - ] + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "foo:" + , "foo::bar" + , " :foo" + , "foo: :bar" + , "a:b:c:d:e:f" + , "a:b:c:d:e:f:g:h" + ] Left errs <- readTargetSelectors localPackages Nothing targets - zipWithM_ (@?=) errs (map TargetSelectorUnrecognised targets) + zipWithM_ + (@?=) + errs + (map (fmap TargetSelectorUnrecognised) targets) cleanProject testdir where testdir = "targets/empty" @@ -575,12 +702,32 @@ testTargetSelectorAmbiguous reportSubCase = do res <- readTargetSelectorsWith fakeDirActions - (map SpecificSourcePackage pkgs) + ( map + ( SpecificSourcePackage + . fmap + ( \loc -> + WithConstraintSource + { constraintPackage = loc + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + ) + pkgs + ) Nothing - [str] + [ WithConstraintSource + { constraintPackage = str + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ] case res of - Left [TargetSelectorAmbiguous _ tss'] -> - sort (map snd tss') @?= sort tss + Left + [ WithConstraintSource + { constraintPackage = TargetSelectorAmbiguous _ tss' + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ] -> + sort (map snd tss') @?= sort tss _ -> assertFailure $ "expected Left [TargetSelectorAmbiguous _ _], " @@ -596,11 +743,32 @@ testTargetSelectorAmbiguous reportSubCase = do res <- readTargetSelectorsWith fakeDirActions - (map SpecificSourcePackage pkgs) + ( map + ( SpecificSourcePackage + . fmap + ( \loc -> + WithConstraintSource + { constraintPackage = loc + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + ) + pkgs + ) Nothing - [str] + [ WithConstraintSource + { constraintPackage = str + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ] case res of - Right [ts'] -> ts' @?= ts + Right [ts'] -> + ts' + @?= ( WithConstraintSource + { constraintPackage = ts + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) _ -> assertFailure $ "expected Right [Target...], " @@ -695,24 +863,31 @@ testTargetSelectorNoCurrentPackage = do localPackages Nothing targets = - [ "libs" - , ":cwd:libs" - , "flibs" - , ":cwd:flibs" - , "exes" - , ":cwd:exes" - , "tests" - , ":cwd:tests" - , "benchmarks" - , ":cwd:benchmarks" - ] + map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceCommandlineFlag + } + ) + [ "libs" + , ":cwd:libs" + , "flibs" + , ":cwd:flibs" + , "exes" + , ":cwd:exes" + , "tests" + , ":cwd:tests" + , "benchmarks" + , ":cwd:benchmarks" + ] Left errs <- readTargetSelectors' targets zipWithM_ (@?=) errs - [ TargetSelectorNoCurrentPackage ts + [ fmap TargetSelectorNoCurrentPackage ts | target <- targets - , let ts = fromMaybe (error $ "failed to parse target string " ++ target) $ parseTargetString target + , let ts = fromMaybe (error $ "failed to parse target string " ++ constraintPackage target) $ parseTargetString target ] cleanProject testdir where @@ -723,7 +898,12 @@ testTargetSelectorNoTargets :: Assertion testTargetSelectorNoTargets = do (_, _, _, localPackages, _) <- configureProject testdir config Left errs <- readTargetSelectors localPackages Nothing [] - errs @?= [TargetSelectorNoTargetsInCwd True] + errs + @?= [ WithConstraintSource + { constraintPackage = TargetSelectorNoTargetsInCwd True + , constraintConstraint = ConstraintSourceImplicit + } + ] cleanProject testdir where testdir = "targets/complex" @@ -733,7 +913,12 @@ testTargetSelectorProjectEmpty :: Assertion testTargetSelectorProjectEmpty = do (_, _, _, localPackages, _) <- configureProject testdir config Left errs <- readTargetSelectors localPackages Nothing [] - errs @?= [TargetSelectorNoTargetsInProject] + errs + @?= [ WithConstraintSource + { constraintPackage = TargetSelectorNoTargetsInProject + , constraintConstraint = ConstraintSourceImplicit + } + ] cleanProject testdir where testdir = "targets/empty" @@ -755,7 +940,12 @@ testTargetSelectorCanonicalizedPath = do ( do let dirActions' = (dirActions symlink){TS.getCurrentDirectory = return virtcwd} Right ts <- readTargetSelectorsWith dirActions' localPackages Nothing [] - ts @?= [TargetPackage TargetImplicitCwd ["p-0.1"] Nothing] + ts + @?= [ WithConstraintSource + { constraintPackage = TargetPackage TargetImplicitCwd ["p-0.1"] Nothing + , constraintConstraint = ConstraintSourceImplicit + } + ] ) cleanProject testdir where @@ -849,10 +1039,10 @@ testTargetProblemsCommon config0 = do , projectConfigShared = (projectConfigShared config0) { projectConfigConstraints = - [ - ( UserConstraint (UserAnyQualifier "filepath") PackagePropertySource - , ConstraintSourceUnknown - ) + [ WithConstraintSource + { constraintPackage = UserConstraint (UserAnyQualifier "filepath") PackagePropertySource + , constraintConstraint = ConstraintSourceUnknown + } ] } } @@ -1754,7 +1944,15 @@ assertProjectDistinctTargets selectComponentTarget elaboratedPlan Nothing - targetSelectors + ( map + ( \target -> + WithConstraintSource + { constraintPackage = target + , constraintConstraint = ConstraintSourceUnknown + } + ) + targetSelectors + ) assertProjectTargetProblems :: forall err @@ -1804,10 +2002,23 @@ assertTargetProblems elaboratedPlan selectPackageTargets selectComponentTarget = selectComponentTarget elaboratedPlan Nothing - [targetSelector] + [ WithConstraintSource + { constraintPackage = targetSelector + , constraintConstraint = ConstraintSourceUnknown + } + ] in case res of Left [problem] -> - problem @?= expected targetSelector + problem + @?= ( ( \problem' -> + WithConstraintSource + { constraintPackage = problem' + , constraintConstraint = ConstraintSourceUnknown + } + ) + . expected + ) + targetSelector unexpected -> assertFailure $ "expected resolveTargets result: (Left [problem]) " @@ -1821,8 +2032,12 @@ testExceptionInFindingPackage config = do void $ planProject testdir config case locs of - [BadLocGlobEmptyMatch "./*.cabal"] -> return () - _ -> assertFailure "expected BadLocGlobEmptyMatch" + [ WithConstraintSource + { constraintPackage = BadLocGlobEmptyMatch "./*.cabal" + , constraintConstraint = ConstraintSourceMainConfig "." + } + ] -> return () + _ -> assertFailure $ "expected BadLocGlobEmptyMatch, found " <> show locs cleanProject testdir where testdir = "exception/no-pkg" @@ -1834,7 +2049,11 @@ testExceptionInFindingPackage2 config = do void $ planProject testdir config case locs of - [BadPackageLocationFile (BadLocDirNoCabalFile ".")] -> return () + [ WithConstraintSource + { constraintPackage = BadPackageLocationFile (BadLocDirNoCabalFile ".") + , constraintConstraint = ConstraintSourceProjectConfig (ProjectConfigPath ("cabal.project" :| [])) + } + ] -> return () _ -> assertFailure $ "expected BadLocDirNoCabalFile, got " ++ show locs cleanProject testdir where diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ArbitraryInstances.hs b/cabal-install/tests/UnitTests/Distribution/Client/ArbitraryInstances.hs index 6acc63072d1..534cb295b0b 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ArbitraryInstances.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ArbitraryInstances.hs @@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -fno-warn-orphans #-} @@ -40,8 +41,11 @@ import Distribution.Client.Targets import Distribution.Client.Types (RepoName (..), WriteGhcEnvironmentFilesPolicy) import Distribution.Client.Types.AllowNewer import Distribution.Client.Types.OverwritePolicy (OverwritePolicy) +import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..)) import Distribution.Solver.Types.OptionalStanza (OptionalStanza (..), OptionalStanzaMap, OptionalStanzaSet, optStanzaSetFromList, optStanzaTabulate) import Distribution.Solver.Types.PackageConstraint (PackageProperty (..)) +import Distribution.Solver.Types.ProjectConfigPath (ProjectConfigPath (..)) +import Distribution.Solver.Types.WithConstraintSource (WithConstraintSource (..)) import Data.Coerce (Coercible, coerce) import Network.URI (URI (..), URIAuth (..), isUnreserved) @@ -446,3 +450,36 @@ instance Arbitrary GlobPiece where globLiteralChars :: [Char] globLiteralChars = ['\0' .. '\128'] \\ "*{},/\\" + +------------------------------------------------------------------------------- +-- ConstraintSource +------------------------------------------------------------------------------- + +instance Arbitrary a => Arbitrary (NonEmpty a) where + arbitrary = do + xs' <- arbitrary @(NonEmptyList _) + case getNonEmpty xs' of + x : xs -> pure (x :| xs) + _ -> error "unreachable" + + -- No way to shrink a 1-element list. + shrink (_ :| []) = [] + shrink (x :| xs) = + let possibilities = shrink (NonEmpty (x : xs)) + in [ case getNonEmpty possibility of + x' : xs' -> x' :| xs' + _ -> error "unreachable" + | possibility <- possibilities + ] + +instance Arbitrary ProjectConfigPath where + arbitrary = genericArbitrary + shrink = genericShrink + +instance Arbitrary ConstraintSource where + arbitrary = genericArbitrary + shrink = genericShrink + +instance Arbitrary a => Arbitrary (WithConstraintSource a) where + arbitrary = genericArbitrary + shrink = genericShrink diff --git a/cabal-install/tests/UnitTests/Distribution/Client/FetchUtils.hs b/cabal-install/tests/UnitTests/Distribution/Client/FetchUtils.hs index c14682c2bcb..63c4df38b64 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/FetchUtils.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/FetchUtils.hs @@ -14,6 +14,12 @@ import Distribution.Client.HttpUtils (HttpCode, HttpTransport (..)) import Distribution.Client.Types.PackageLocation (PackageLocation (..), ResolvedPkgLoc) import Distribution.Client.Types.Repo (Repo (..), emptyRemoteRepo) import Distribution.Client.Types.RepoName (RepoName (..)) +import Distribution.Solver.Types.ConstraintSource + ( ConstraintSource (..) + ) +import Distribution.Solver.Types.WithConstraintSource + ( WithConstraintSource (..) + ) import Distribution.Types.PackageId (PackageIdentifier (..)) import Distribution.Types.PackageName (mkPackageName) import qualified Distribution.Verbosity as Verbosity @@ -61,18 +67,30 @@ testEmpty = do testPassLocalPackage :: Assertion testPassLocalPackage = do let repoCtxt = error "repoCtxt undefined" - loc = LocalUnpackedPackage "a" + loc = + WithConstraintSource + { constraintPackage = LocalUnpackedPackage "a" + , constraintConstraint = ConstraintSourceUnknown + } res <- asyncFetchPackages verbosity repoCtxt [loc] $ \downloadMap -> waitAsyncFetchPackage verbosity downloadMap loc - res @?= LocalUnpackedPackage "a" + res + @?= WithConstraintSource + { constraintPackage = LocalUnpackedPackage "a" + , constraintConstraint = ConstraintSourceUnknown + } testHttp :: Assertion testHttp = withFakeRepoCtxt get200 $ \repoCtxt repo -> do let pkgId = mkPkgId "foo" - loc = RepoTarballPackage repo pkgId Nothing + loc = + WithConstraintSource + { constraintPackage = RepoTarballPackage repo pkgId Nothing + , constraintConstraint = ConstraintSourceUnknown + } res <- asyncFetchPackages verbosity repoCtxt [loc] $ \downloadMap -> waitAsyncFetchPackage verbosity downloadMap loc - case res of + case constraintPackage res of RepoTarballPackage repo' pkgId' _ -> do repo' @?= repo pkgId' @?= pkgId @@ -94,7 +112,11 @@ testGetException = testGetAny $ userError "some error" -- 3. third download keeps running testGetAny :: Exception e => e -> Assertion testGetAny exc = withFakeRepoCtxt get $ \repoCtxt repo -> do - let loc pkgId = RepoTarballPackage repo pkgId Nothing + let loc pkgId = + WithConstraintSource + { constraintPackage = RepoTarballPackage repo pkgId Nothing + , constraintConstraint = ConstraintSourceUnknown + } pkgLocs = [loc throws, loc slowA, loc slowB] start <- getCurrentTime @@ -120,7 +142,11 @@ testGetAny exc = withFakeRepoCtxt get $ \repoCtxt repo -> do -- we still abort directly. testUncollectedInterrupt :: Assertion testUncollectedInterrupt = withFakeRepoCtxt get $ \repoCtxt repo -> do - let loc pkgId = RepoTarballPackage repo pkgId Nothing + let loc pkgId = + WithConstraintSource + { constraintPackage = RepoTarballPackage repo pkgId Nothing + , constraintConstraint = ConstraintSourceUnknown + } pkgLocs = [loc throws, loc slowA, loc slowB] start <- getCurrentTime @@ -147,14 +173,18 @@ testUncollectedInterrupt = withFakeRepoCtxt get $ \repoCtxt repo -> do -- the download and handle its exception.) testUncollectedException :: Assertion testUncollectedException = withFakeRepoCtxt get $ \repoCtxt repo -> do - let loc pkgId = RepoTarballPackage repo pkgId Nothing + let loc pkgId = + WithConstraintSource + { constraintPackage = RepoTarballPackage repo pkgId Nothing + , constraintConstraint = ConstraintSourceUnknown + } pkgLocs = [loc throws, loc foo] start <- getCurrentTime res <- asyncFetchPackages verbosity repoCtxt pkgLocs $ \downloadMap -> do waitAsyncFetchPackage verbosity downloadMap (loc foo) assertFaster start shortDelta - case res of + case constraintPackage res of RepoTarballPackage repo' pkgId' _ -> do repo' @?= repo pkgId' @?= foo diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index 1996dab1a1d..7d2c84e472f 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -52,9 +52,11 @@ import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.PackageConstraint import Distribution.Solver.Types.ProjectConfigPath import Distribution.Solver.Types.Settings +import Distribution.Solver.Types.WithConstraintSource import Distribution.Client.ProjectConfig import Distribution.Client.ProjectConfig.Legacy +import Distribution.Client.ProjectConfig.Types import UnitTests.Distribution.Client.ArbitraryInstances import UnitTests.Distribution.Client.TreeDiffInstances () @@ -305,10 +307,10 @@ prop_roundtrip_printparse_packages prop_roundtrip_printparse_packages pkglocstrs1 pkglocstrs2 repos named = roundtrip_printparse mempty - { projectPackages = map getPackageLocationString pkglocstrs1 - , projectPackagesOptional = map getPackageLocationString pkglocstrs2 - , projectPackagesRepo = repos - , projectPackagesNamed = named + { projectPackages = map (withProjectConfigConstraintSource . getPackageLocationString) pkglocstrs1 + , projectPackagesOptional = map (withProjectConfigConstraintSource . getPackageLocationString) pkglocstrs2 + , projectPackagesRepo = map withProjectConfigConstraintSource repos + , projectPackagesNamed = map withProjectConfigConstraintSource named } prop_roundtrip_printparse_buildonly :: ProjectConfigBuildOnly -> Property @@ -344,7 +346,7 @@ hackProjectConfigShared config = , projectConfigConstraints = -- TODO: [required eventually] parse ambiguity in constraint -- "pkgname -any" as either any version or disabled flag "any". - let ambiguous (UserConstraint _ (PackagePropertyFlags flags), _) = + let ambiguous (WithConstraintSource{constraintPackage = UserConstraint _ (PackagePropertyFlags flags)}) = (not . null) [ () | (name, False) <- unFlagAssignment flags, "any" `isPrefixOf` unFlagName name ] @@ -418,10 +420,10 @@ prop_roundtrip_printparse_RelaxDeps' rdep = instance Arbitrary ProjectConfig where arbitrary = ProjectConfig - <$> (map getPackageLocationString <$> arbitrary) - <*> (map getPackageLocationString <$> arbitrary) - <*> shortListOf 3 arbitrary - <*> arbitrary + <$> (map (fmap getPackageLocationString) <$> arbitraryWithConstraintSources) + <*> (map (fmap getPackageLocationString) <$> arbitraryWithConstraintSources) + <*> shortListOf 3 arbitraryWithConstraintSource + <*> arbitraryWithConstraintSources <*> arbitrary <*> arbitrary <*> arbitrary @@ -617,8 +619,8 @@ instance Arbitrary ProjectConfigShared where projectConfigActiveRepos <- arbitrary projectConfigIndexState <- arbitrary projectConfigStoreDir <- arbitraryFlag arbitraryShortToken - projectConfigConstraints <- arbitraryConstraints - projectConfigPreferences <- shortListOf 2 arbitrary + projectConfigConstraints <- arbitraryWithConstraintSources + projectConfigPreferences <- shortListOf 2 arbitraryWithConstraintSource projectConfigCabalVersion <- arbitrary projectConfigSolver <- arbitrary projectConfigAllowOlder <- arbitrary @@ -639,9 +641,6 @@ instance Arbitrary ProjectConfigShared where projectConfigMultiRepl <- arbitrary return ProjectConfigShared{..} where - arbitraryConstraints :: Gen [(UserConstraint, ConstraintSource)] - arbitraryConstraints = - fmap (\uc -> (uc, projectConfigConstraintSource)) <$> arbitrary fixInstallDirs x = x{InstallDirs.includedir = mempty, InstallDirs.mandir = mempty, InstallDirs.flibdir = mempty} shrink ProjectConfigShared{..} = @@ -684,12 +683,36 @@ instance Arbitrary ProjectConfigShared where <*> shrinker projectConfigProgPathExtra <*> shrinker projectConfigMultiRepl where - preShrink_Constraints = map fst - postShrink_Constraints = map (\uc -> (uc, projectConfigConstraintSource)) + preShrink_Constraints = map constraintPackage + postShrink_Constraints = + map + ( \uc -> + WithConstraintSource + { constraintPackage = uc + , constraintConstraint = projectConfigConstraintSource + } + ) projectConfigConstraintSource :: ConstraintSource projectConfigConstraintSource = ConstraintSourceProjectConfig nullProjectConfigPath +withProjectConfigConstraintSource :: a -> WithConstraintSource a +withProjectConfigConstraintSource inner = + WithConstraintSource + { constraintPackage = inner + , constraintConstraint = projectConfigConstraintSource + } + +-- | The constraint sources are not and cannot be displayed in the textual representation +-- of the project configuration, so we need to make sure they're replaced with a constant +-- for our round trip tests. +arbitraryWithConstraintSource :: Arbitrary a => Gen (WithConstraintSource a) +arbitraryWithConstraintSource = + withProjectConfigConstraintSource <$> arbitrary + +arbitraryWithConstraintSources :: Arbitrary a => Gen [WithConstraintSource a] +arbitraryWithConstraintSources = listOf arbitraryWithConstraintSource + instance Arbitrary ProjectConfigProvenance where arbitrary = elements [Implicit, Explicit (ProjectConfigPath $ "cabal.project" :| [])] diff --git a/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs b/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs index da9bd8ad90d..3d23b11dd0c 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/TreeDiffInstances.hs @@ -5,10 +5,12 @@ module UnitTests.Distribution.Client.TreeDiffInstances () where import Distribution.Solver.Types.ConstraintSource +import Distribution.Solver.Types.NamedPackage import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import Distribution.Solver.Types.ProjectConfigPath import Distribution.Solver.Types.Settings +import Distribution.Solver.Types.WithConstraintSource import Distribution.Client.BuildReports.Types import Distribution.Client.CmdInstall.ClientInstallFlags @@ -30,6 +32,7 @@ import Network.URI instance (ToExpr k, ToExpr v) => ToExpr (MapMappend k v) instance (ToExpr k, ToExpr v) => ToExpr (MapLast k v) +instance ToExpr a => ToExpr (WithConstraintSource a) instance ToExpr (f FilePath) => ToExpr (SourceRepositoryPackage f) @@ -43,6 +46,7 @@ instance ToExpr ClientInstallFlags instance ToExpr CombineStrategy instance ToExpr ProjectConfigPath instance ToExpr ConstraintSource +instance ToExpr NamedPackage instance ToExpr CountConflicts instance ToExpr FineGrainedConflicts instance ToExpr IndependentGoals diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs index 08e1d7fb141..84ba129e255 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs @@ -87,6 +87,7 @@ import qualified Distribution.Solver.Types.ComponentDeps as CD import Distribution.Solver.Types.ConstraintSource import Distribution.Solver.Types.Flag import Distribution.Solver.Types.LabeledPackageConstraint +import Distribution.Solver.Types.NamedPackage import Distribution.Solver.Types.OptionalStanza import Distribution.Solver.Types.PackageConstraint import qualified Distribution.Solver.Types.PackageIndex as CI.PackageIndex @@ -96,6 +97,7 @@ import Distribution.Solver.Types.Settings import Distribution.Solver.Types.SolverPackage import Distribution.Solver.Types.SourcePackage import Distribution.Solver.Types.Variable +import Distribution.Solver.Types.WithConstraintSource {------------------------------------------------------------------------------- Example package database DSL @@ -432,7 +434,11 @@ exAvSrcPkg ex = package = SourcePackage { srcpkgPackageId = pkgId - , srcpkgSource = LocalTarballPackage "<>" + , srcpkgSource = + WithConstraintSource + { constraintPackage = LocalTarballPackage "<>" + , constraintConstraint = ConstraintSourceUnknown + } , srcpkgDescrOverride = Nothing , srcpkgDescription = C.GenericPackageDescription @@ -849,7 +855,18 @@ exResolve ) (exDbPkgs db) | otherwise = [] - targets' = fmap (\p -> NamedPackage (C.mkPackageName p) []) targets + targets' = + fmap + ( \p -> + Named + ( WithConstraintSource + { constraintPackage = + NamedPackage (C.mkPackageName p) [] + , constraintConstraint = ConstraintSourceUnknown + } + ) + ) + targets params = addConstraints (fmap toConstraint constraints) $ addConstraints (fmap toLpc enableTests) $ diff --git a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackage/use-local-version-of-package.out b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackage/use-local-version-of-package.out index 92f3698edc6..b67e162a62e 100644 --- a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackage/use-local-version-of-package.out +++ b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackage/use-local-version-of-package.out @@ -19,7 +19,8 @@ Resolving dependencies... Error: [Cabal-7107] Could not resolve dependencies: [__0] next goal: pkg (user goal) -[__0] rejecting: pkg-2.0 (constraint from user target requires ==1.0) +[__0] rejecting: pkg-2.0 + (constraint from cabal.project requires ==1.0) [__0] rejecting: pkg-1.0 (constraint from command line flag requires ==2.0) [__0] fail (backjumping, conflict set: pkg) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: pkg (3) diff --git a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.out b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.out index de46b91c396..29ed238fd53 100644 --- a/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.out +++ b/cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.out @@ -9,7 +9,8 @@ Could not resolve dependencies: [__0] trying: pkg-1.0 (user goal) [__1] next goal: setup-dep (user goal) [__1] rejecting: setup-dep-2.0 (conflict: pkg => setup-dep>=1 && <2) -[__1] rejecting: setup-dep-1.0 (constraint from user target requires ==2.0) +[__1] rejecting: setup-dep-1.0 + (constraint from cabal.project requires ==2.0) [__1] fail (backjumping, conflict set: pkg, setup-dep) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: setup-dep (3), pkg (2) # pkg my-exe diff --git a/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out b/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out index be9a79bbc22..30adb39d72c 100644 --- a/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out +++ b/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out @@ -94,7 +94,13 @@ Configuration is affected by the following files: Configuration is affected by the following files: - same-filename/noncyclical-same-filename-b.config imported by: noncyclical-same-filename-b.project -Up to date +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - my-0.1 (lib:my) (configuration changed) +Configuring my-0.1... +Preprocessing library for my-0.1... +Building library for my-0.1... # checking that cyclical check catches a same file name that imports itself # cabal v2-build Error: [Cabal-7090] @@ -189,7 +195,13 @@ Configuration is affected by the following files: imported by: hops-2.config imported by: hops/hops-1.config imported by: hops-0.project -Up to date +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - my-0.1 (lib:my) (configuration changed) +Configuring my-0.1... +Preprocessing library for my-0.1... +Building library for my-0.1... # checking conflicting constraints skipping into a subfolder and then back out again and again # cabal v2-build Configuration is affected by the following files: diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/A.hs b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/A.hs new file mode 100644 index 00000000000..e0ba50b355f --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/A.hs @@ -0,0 +1,3 @@ +module A where + +str = "A" diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.out b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.out new file mode 100644 index 00000000000..10a874344bd --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.out @@ -0,0 +1,16 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# cabal v2-build +Configuration is affected by the following files: +- cabal.project +Resolving dependencies... +Error: [Cabal-7107] +Could not resolve dependencies: +[__0] next goal: my-lib (user goal) +[__0] rejecting: my-lib; 2.0, 1.0 + (constraint from cabal.project requires ==0.9) +[__0] trying: my-lib-0.9 +[__1] next goal: plain (user goal) +[__1] rejecting: plain-0.1.0.0 (conflict: my-lib==0.9, plain => my-lib>1) +[__1] fail (backjumping, conflict set: my-lib, plain) +After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: my-lib (4), plain (2) diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.project b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.project new file mode 100644 index 00000000000..3e0a13dee7f --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.project @@ -0,0 +1,7 @@ +packages: . + +-- This is `my-lib` 0.9. +source-repository-package + type: git + location: https://github.com/9999years/cabal-testsuite-my-lib.git + tag: 9a0af0aa81325c71e744def11db06265840ffb5f diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.test.hs b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.test.hs new file mode 100644 index 00000000000..447f63f3977 --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/cabal.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude + +main = cabalTest $ withRepo "repo" $ do + output <- fails $ cabal' "v2-build" ["plain"] + assertOutputContains "(constraint from cabal.project requires ==0.9)" output diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/plain.cabal b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/plain.cabal new file mode 100644 index 00000000000..1290a8f04da --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/plain.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: plain +version: 0.1.0.0 +license: BSD-3-Clause +author: Rebecca Turner +build-type: Simple + +library + exposed-modules: A + build-depends: base, my-lib >1 + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/my-lib.cabal b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/my-lib.cabal new file mode 100644 index 00000000000..24dd0a44e65 --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/my-lib.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: my-lib +version: 1.0 +license: BSD-3-Clause +author: Rebecca Turner + +library + exposed-modules: MyLib + hs-source-dirs: src + build-depends: base + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/src/MyLib.hs b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/src/MyLib.hs new file mode 100644 index 00000000000..1eca7fb8e6c --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-1.0/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib where + +myValue :: Int +myValue = 1 diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/my-lib.cabal b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/my-lib.cabal new file mode 100644 index 00000000000..586b90befa9 --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/my-lib.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: my-lib +version: 2.0 +license: BSD-3-Clause +author: Rebecca Turner + +library + exposed-modules: MyLib + hs-source-dirs: src + build-depends: base + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/src/MyLib.hs b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/src/MyLib.hs new file mode 100644 index 00000000000..1eca7fb8e6c --- /dev/null +++ b/cabal-testsuite/PackageTests/ConstraintSource/SourceRepositoryPackage/repo/my-lib-2.0/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib where + +myValue :: Int +myValue = 1 diff --git a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/all-test-sute.out b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/all-test-sute.out index cf7d268fa44..6c55a75947e 100644 --- a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/all-test-sute.out +++ b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/all-test-sute.out @@ -2,4 +2,4 @@ Configuration is affected by the following files: - cabal.project Error: [Cabal-7151] -It is not possible to package only the test suites from a package for distribution. Only entire packages may be packaged for distribution. +It is not possible to package only the test suites from a package for distribution. Only entire packages may be packaged for distribution. (from command line flag) diff --git a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/target-remote-package.out b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/target-remote-package.out index 2265a38e933..f1a4bf7ec30 100644 --- a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/target-remote-package.out +++ b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/target-remote-package.out @@ -2,4 +2,4 @@ Configuration is affected by the following files: - cabal.project Error: [Cabal-7151] -The package base cannot be packaged for distribution, because it is not local to this project. +The package base cannot be packaged for distribution, because it is not local to this project. (from command line flag) diff --git a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/valid-and-test-suite.out b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/valid-and-test-suite.out index 4da566899a8..690702b4378 100644 --- a/cabal-testsuite/PackageTests/NewSdist/MultiTarget/valid-and-test-suite.out +++ b/cabal-testsuite/PackageTests/NewSdist/MultiTarget/valid-and-test-suite.out @@ -2,4 +2,4 @@ Configuration is affected by the following files: - cabal.project Error: [Cabal-7151] -The component test suite 'a-tests' cannot be packaged for distribution on its own. Only entire packages may be packaged for distribution. +The component test suite 'a-tests' cannot be packaged for distribution on its own. Only entire packages may be packaged for distribution. (from command line flag)