Skip to content

Commit fb2a017

Browse files
committed
Add a test for new-freeze, with build tool dependencies.
1 parent 96e5450 commit fb2a017

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-local-package
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
library
7+
build-depends: base, my-library-dep
8+
build-tool-depends: my-build-tool-dep:my-build-tool >= 2
9+
default-language: Haskell2010
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# cabal update
2+
Downloading the latest package list from test-local-repo
3+
# cabal new-build
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following would be built:
7+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
8+
- my-build-tool-dep-3.0 (exe:my-build-tool) (requires download & build)
9+
- my-library-dep-1.0 (lib) (requires download & build)
10+
- my-local-package-1.0 (lib) (first run)
11+
# cabal new-freeze
12+
Resolving dependencies...
13+
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
14+
# cabal new-build
15+
Resolving dependencies...
16+
Build profile: -w ghc-<GHCVER> -O1
17+
In order, the following would be built:
18+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
19+
- my-build-tool-dep-2.0 (exe:my-build-tool) (requires download & build)
20+
- my-library-dep-1.0 (lib) (requires download & build)
21+
- my-local-package-1.0 (lib) (first run)
22+
# cabal new-build
23+
Resolving dependencies...
24+
Build profile: -w ghc-<GHCVER> -O1
25+
In order, the following would be built:
26+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
27+
- my-build-tool-dep-3.0 (exe:my-build-tool) (requires download & build)
28+
- my-library-dep-1.0 (lib) (requires download & build)
29+
- my-local-package-1.0 (lib) (first run)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Test.Cabal.Prelude
2+
import Control.Monad.IO.Class
3+
import System.Directory
4+
5+
-- Test that 'cabal new-freeze' works with multiple versions of a build tool
6+
-- dependency.
7+
--
8+
-- The repository contains versions 1.0, 2.0, and 3.0 of the build tool. One
9+
-- library requires >= 2, and the other requires < 2, so cabal should pick
10+
-- versions 1.0 and 3.0 of build tool when there are no constraints.
11+
main = cabalTest $ withSourceCopy $ do
12+
withRepo "repo" $ do
13+
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestBuildTool
14+
15+
-- Force the libraries to use versions 1.0 and 2.0 of the build tool.
16+
cabal "new-freeze" ["--constraint=any.my-build-tool-dep < 3"]
17+
18+
cwd <- fmap testCurrentDir getTestEnv
19+
let freezeFile = cwd </> "cabal.project.freeze"
20+
21+
-- The freeze file should specify a version range that includes both
22+
-- versions of the build tool from the install plan. (The version range will
23+
-- be replaced with qualified constraints once #3502 is fully implemented).
24+
assertFileDoesContain freezeFile "any.my-build-tool-dep ==1.0 || ==2.0"
25+
26+
-- The library constraint should have an exact version.
27+
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
28+
29+
-- The local package should be unconstrained.
30+
assertFileDoesNotContain freezeFile "my-local-package"
31+
32+
-- cabal should be able to find an install plan that fits the constraints.
33+
cabal' "new-build" ["--dry-run"] >>= assertDoesNotUseLatestBuildTool
34+
35+
-- cabal should choose the latest version again after the freeze file is
36+
-- removed.
37+
liftIO $ removeFile freezeFile
38+
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestBuildTool
39+
where
40+
assertUsesLatestBuildTool out = do
41+
assertOutputContains "my-build-tool-dep-3.0 (exe:my-build-tool)" out
42+
assertOutputDoesNotContain "my-build-tool-dep-2.0" out
43+
44+
assertDoesNotUseLatestBuildTool out = do
45+
assertOutputContains "my-build-tool-dep-2.0 (exe:my-build-tool)" out
46+
assertOutputDoesNotContain "my-build-tool-dep-3.0" out
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 2.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 3.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-library-dep
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
library
7+
build-depends: base
8+
build-tool-depends: my-build-tool-dep:my-build-tool < 2
9+
default-language: Haskell2010

0 commit comments

Comments
 (0)