Skip to content

Add more new-freeze integration tests. #5135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,3 @@ In order, the following would be built:
- my-build-tool-dep-2.0 (exe:my-build-tool) (requires download & build)
- my-library-dep-1.0 (lib) (requires download & build)
- my-local-package-1.0 (lib) (first run)
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
- my-build-tool-dep-3.0 (exe:my-build-tool) (requires download & build)
- my-library-dep-1.0 (lib) (requires download & build)
- my-local-package-1.0 (lib) (first run)
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ main = cabalTest $ withSourceCopy $ do
-- cabal should be able to find an install plan that fits the constraints
-- from the freeze file.
cabal' "new-build" ["--dry-run"] >>= assertDoesNotUseLatestBuildTool

-- cabal should choose the latest version again after the freeze file is
-- removed.
liftIO $ removeFile freezeFile
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestBuildTool
where
assertUsesLatestBuildTool out = do
assertOutputContains "my-build-tool-dep-3.0 (exe:my-build-tool)" out
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/NewFreeze/Flags/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: my-local-package
version: 1.0
cabal-version: 1.20
build-type: Simple

library
build-depends: my-library-dep
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/NewFreeze/Flags/new_freeze.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# cabal update
Downloading the latest package list from test-local-repo
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- true-dep-1.0 (lib) (requires download & build)
- my-library-dep-1.0 (lib) (requires download & build)
- my-local-package-1.0 (lib) (first run)
# cabal new-freeze
Resolving dependencies...
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- false-dep-1.0 (lib) (requires download & build)
- my-library-dep-1.0 (lib) (requires download & build)
- my-local-package-1.0 (lib) (first run)
35 changes: 35 additions & 0 deletions cabal-testsuite/PackageTests/NewFreeze/Flags/new_freeze.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Test.Cabal.Prelude
import Control.Monad.IO.Class
import Data.Char
import System.Directory

-- Test that 'cabal new-freeze' freezes flag choices. my-local-package depends
-- on my-library-dep. my-library-dep has a flag, my-flag, which defaults to
-- true.
main = cabalTest $ withSourceCopy $
withRepo "repo" $ do
cabal' "new-build" ["--dry-run"] >>= assertDependencyFlagChoice True

cabal "new-freeze" ["--constraint=my-library-dep -my-flag"]

cwd <- fmap testCurrentDir getTestEnv
let freezeFile = cwd </> "cabal.project.freeze"

-- The freeze file should constrain the version and the flag.
-- TODO: The flag constraint should be qualified. See
-- https://github.com/haskell/cabal/issues/5134.
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
assertFileDoesContain freezeFile "my-library-dep -my-flag"

-- cabal should be able to find an install plan that fits the constraints
-- from the freeze file.
cabal' "new-build" ["--dry-run"] >>= assertDependencyFlagChoice False
where
-- my-library-dep's flag controls whether it depends on true-dep or
-- false-dep, so this function uses the dependency to infer the flag choice.
assertDependencyFlagChoice True out = do
assertOutputContains "true-dep-1.0 (lib)" out
assertOutputDoesNotContain "false-dep" out
assertDependencyFlagChoice False out = do
assertOutputContains "false-dep-1.0 (lib)" out
assertOutputDoesNotContain "true-dep" out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: false-dep
version: 1.0
cabal-version: 1.20
build-type: Simple

library
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: my-library-dep
version: 1.0
cabal-version: 1.20
build-type: Simple

flag my-flag
default: True
manual: False

library
build-depends: base
if flag(my-flag)
build-depends: true-dep
else
build-depends: false-dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: true-dep
version: 1.0
cabal-version: 1.20
build-type: Simple

library
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/NewFreeze/FreezeFile/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MyLibModule (message)

main = putStrLn message
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: my-local-package
version: 1.0
cabal-version: 1.20
build-type: Simple

executable my-exe
hs-source-dirs: .
main-is: Main.hs
build-depends: base, my-library-dep
default-language: Haskell2010
34 changes: 34 additions & 0 deletions cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# cabal update
Downloading the latest package list from test-local-repo
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- my-library-dep-2.0 (lib) (requires download & build)
- my-local-package-1.0 (exe:my-exe) (first run)
# cabal new-freeze
Resolving dependencies...
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- my-library-dep-1.0 (lib) (requires download & build)
- my-local-package-1.0 (exe:my-exe) (first run)
Configuring library for my-library-dep-1.0..
Preprocessing library for my-library-dep-1.0..
Building library for my-library-dep-1.0..
Installing library in <PATH>
Configuring executable 'my-exe' for my-local-package-1.0..
Preprocessing executable 'my-exe' for my-local-package-1.0..
Building executable 'my-exe' for my-local-package-1.0..
# cabal new-freeze
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
# cabal new-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- my-library-dep-2.0 (lib) (requires download & build)
- my-local-package-1.0 (exe:my-exe) (configuration changed)
# cabal new-freeze
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Test.Cabal.Prelude
import Control.Monad.IO.Class
import Data.Char
import System.Directory

-- Test for 'cabal new-freeze' with only a single library dependency.
-- my-local-package depends on my-library-dep, which has versions 1.0 and 2.0.
main = cabalTest $ withSourceCopy $
withRepo "repo" $ do
cwd <- fmap testCurrentDir getTestEnv
let freezeFile = cwd </> "cabal.project.freeze"

shouldNotExist freezeFile

-- new-build should choose the latest version for the dependency.
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency

-- Freeze a dependency on the older version.
cabal "new-freeze" ["--constraint=my-library-dep==1.0"]

-- The file should constrain the dependency, but not the local package.
shouldExist freezeFile
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
assertFileDoesNotContain freezeFile "my-local-package"

-- cabal should be able to build the package using the constraint from the
-- freeze file.
cabal' "new-build" [] >>= assertDoesNotUseLatestDependency

-- Re-running new-freeze should not change the constraints, because cabal
-- should use the existing freeze file when choosing the new install plan.
cabal "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"

-- cabal should choose the latest version again after the freeze file is
-- removed.
liftIO $ removeFile freezeFile
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestDependency

-- Re-running new-freeze with no constraints or freeze file should constrain
-- the dependency to the latest version.
cabal "new-freeze" []
assertFileDoesContain freezeFile "any.my-library-dep ==2.0"
assertFileDoesNotContain freezeFile "my-local-package"
where
assertUsesLatestDependency out = do
assertOutputContains "my-library-dep-2.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-1.0" out

assertDoesNotUseLatestDependency out = do
assertOutputContains "my-library-dep-1.0 (lib)" out
assertOutputDoesNotContain "my-library-dep-2.0" out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module MyLibModule (message) where

message = "Hello"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: my-library-dep
version: 1.0
cabal-version: 1.20
build-type: Simple

library
hs-source-dirs: .
build-depends: base
default-language: Haskell2010
exposed-modules: MyLibModule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module MyLibModule (message) where

message = "Hello"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: my-library-dep
version: 2.0
cabal-version: 1.20
build-type: Simple

library
hs-source-dirs: .
build-depends: base
default-language: Haskell2010
exposed-modules: MyLibModule