Skip to content

Commit

Permalink
Add tests for default-package-bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jun 14, 2024
1 parent 005a58a commit 5eea631
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Cabal-described/src/Distribution/Described.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import Distribution.Types.AbiDependency (AbiDependency)
import Distribution.Types.AbiHash (AbiHash)
import Distribution.Types.BenchmarkType (BenchmarkType)
import Distribution.Types.BuildType (BuildType)
import Distribution.Types.DefaultBound (DefaultBound)
import Distribution.Types.Dependency (Dependency)
import Distribution.Types.ExecutableScope (ExecutableScope)
import Distribution.Types.ExeDependency (ExeDependency)
Expand Down Expand Up @@ -369,6 +370,21 @@ instance Described CompilerId where
<> fromString "-"
<> describe (Proxy :: Proxy Version)

instance Described DefaultBound where
describe _ = REUnion
[ REAppend
[ RENamed "pkg-name" (describe (Proxy :: Proxy PackageName))
, reChar ':' <> reUnqualComponent
, RESpaces <> vr
]
, REAppend
[ RENamed "pkg-name" (describe (Proxy :: Proxy PackageName))
, RESpaces <> vr
]
]
where
vr = RENamed "version-range" (describe (Proxy :: Proxy VersionRange))

instance Described Dependency where
describe _ = REAppend
[ RENamed "pkg-name" (describe (Proxy :: Proxy PackageName))
Expand Down
1 change: 1 addition & 0 deletions Cabal-tree-diff/src/Data/TreeDiff/Instances/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ instance ToExpr CompilerFlavor
instance ToExpr CompilerId
instance ToExpr ComponentId
instance ToExpr DebugInfoLevel
instance ToExpr DefaultBound
instance ToExpr DefUnitId
instance ToExpr DumpBuildInfo
instance ToExpr ExeDependency
Expand Down
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/DefaultPackageBounds/bar/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- |

module Main where

main = pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cabal-version: 3.14
name: bar
version: 0.1.0.0

executable bar
default-language: Haskell2010
main-is: Main.hs
31 changes: 31 additions & 0 deletions cabal-testsuite/PackageTests/DefaultPackageBounds/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# cabal build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- bar-0.1.0.0 (exe:bar) (first run)
- foo-0.1.0.0 (lib) (first run)
# cabal build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: foo-0.1.0.0 (user goal)
[__1] rejecting: foo:-build-depends-conflict (constraint from config file, command line flag, or user target requires opposite flag selection)
[__1] trying: foo:+build-depends-conflict
[__2] next goal: time (dependency of foo +/-build-depends-conflict)
[__2] rejecting: time-<VERSION>/installed-<HASH> (conflict: foo +build-depends-conflict => time<0)
[__2] fail (backjumping, conflict set: foo, time, foo:build-depends-conflict)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: foo (4), foo:build-depends-conflict (3), time (2)
# cabal build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: bar-0.1.0.0 (user goal)
[__1] trying: foo-0.1.0.0 (user goal)
[__2] rejecting: foo:-build-tool-conflict (constraint from config file, command line flag, or user target requires opposite flag selection)
[__2] trying: foo:+build-tool-conflict
[__3] next goal: foo:bar:exe.bar (dependency of foo +/-build-tool-conflict)
[__3] rejecting: foo:bar:exe.bar~>bar-0.1.0.0 (conflict: foo +build-tool-conflict => foo:bar:exe.bar (exe bar)<0)
[__3] rejecting: foo:bar:exe.bar-0.1.0.0 (multiple instances)
[__3] fail (backjumping, conflict set: bar, foo, foo:bar:exe.bar, foo:build-tool-conflict)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: foo (4), foo:bar:exe.bar (3), foo:build-tool-conflict (3), bar (2)
Try running with --minimize-conflict-set to improve the error message.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: . bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude

main = cabalTest $ withProjectFile "cabal.project" $ do
cabal "build" ["foo", "--dry-run"]
fails $ cabal "build" ["foo", "-fbuild-depends-conflict"]
fails $ cabal "build" ["foo", "-fbuild-tool-conflict"]
31 changes: 31 additions & 0 deletions cabal-testsuite/PackageTests/DefaultPackageBounds/foo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cabal-version: 3.14
name: foo
version: 0.1.0.0

default-package-bounds:
, time <0
, bar:bar <0

flag build-depends-conflict
manual: True
default: False
description: cause conflict

flag build-tool-conflict
manual: True
default: False
description: cause conflict

library
if flag(build-depends-conflict)
build-depends:
time
else
build-depends:
time >0
default-language: Haskell2010

if flag(build-tool-conflict)
build-tool-depends: bar:bar
else
build-tool-depends: bar:bar >0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: foo-0.1.0.0 (user goal)
[__1] next goal: time (dependency of foo)
[__1] rejecting: time-<VERSION>/installed-<HASH> (conflict: foo => time<1)
[__1] fail (backjumping, conflict set: foo, time)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: foo (3), time (2)
# cabal build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- foo-0.1.0.0 (lib) (first run)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "build" ["foo", "--dry-run"]
cabal "build" ["foo", "--dry-run", "--allow-newer"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 3.14
name: foo
version: 0.1.0.0
license: BSD-3-Clause
license-file: LICENSE
author: Javier Sagredo
maintainer: [email protected]
build-type: Simple
extra-doc-files: CHANGELOG.md

default-package-bounds:
time <1

library
build-depends: base
, time
hs-source-dirs: src
default-language: Haskell2010
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/Regression/T9640/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Configuring one-custom-0.1.0.0...
Preprocessing library for one-custom-0.1.0.0...
Building library for one-custom-0.1.0.0...
Installing library in <PATH>
Warning: depend-on-custom-with-exe.cabal:16:1: Ignoring trailing fields after sections: "ghc-options"
Warning: depend-on-custom-with-exe.cabal:16:1: Ignoring trailing fields after sections: "ghc-options". Consider moving these fields before any stanzas in your cabal file.
Configuring library for depend-on-custom-with-exe-0.1.0.0...
Preprocessing library for depend-on-custom-with-exe-0.1.0.0...
Building library for depend-on-custom-with-exe-0.1.0.0...

0 comments on commit 5eea631

Please sign in to comment.