Skip to content

Commit

Permalink
Merge pull request #9680 from cabalism/test/project-hop-imports
Browse files Browse the repository at this point in the history
Add tests for project imports and constraint version conflicts
  • Loading branch information
mergify[bot] committed Feb 1, 2024
2 parents bd0dae7 + 78fcdc6 commit 663e98f
Show file tree
Hide file tree
Showing 65 changed files with 838 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: cabal-cyclical-1-hop.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: cabal-cyclical-2-hop-2.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: cabal-cyclical-2-hop.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: cabal-cyclical-2-hop-1.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: cabal-cyclical-1-hop.project
28 changes: 28 additions & 0 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ cyclical import of cyclical-2-out-out-back-a.config
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-2-out-out-self.project:1:
cyclical import of cyclical-2-out-out-self-b.config
# checking that cyclical check doesn't false-positive on same file names in different folders; hoping within a folder and then into a subfolder
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- my-0.1 (lib:my) (first run)
Configuring my-0.1...
Preprocessing library for my-0.1...
Building library for my-0.1...
# checking that cyclical check doesn't false-positive on same file names in different folders; hoping into a subfolder and then back out again
# cabal v2-build
# checking that cyclical check catches a same file name that imports itself
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-self.project:1:
cyclical import of cyclical-same-filename-out-out-self.config
# checking that cyclical check catches importing its importer (with the same file name)
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-backback.project:3:
cyclical import of cyclical-same-filename-out-out-backback.config
# checking that cyclical check catches importing its importer's importer (hopping over same file names)
# cabal v2-build
Error: [Cabal-7090]
Error parsing project file <ROOT>/cyclical-same-filename-out-out-back.project:1:
cyclical import of same-filename/cyclical-same-filename-out-out-back.config
# checking that imports work skipping into a subfolder and then back out again and again
# cabal v2-build
# checking bad conditional
# cabal v2-build
Error: [Cabal-7090]
Expand Down
74 changes: 72 additions & 2 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
-- +-- etc
log "checking cyclical with hops; out and back"
cyclical1a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-1-out-back.project" ]
assertOutputContains "cyclical import of cyclical-1-out-back.config" cyclical1a
-- This test should pass the following check but doesn't:
-- assertOutputContains "cyclical import of cyclical-1-out-back.project" cyclical1a

-- +-- cyclical-1-out-self.project
-- +-- cyclical-1-out-self.config (imports cyclical-1-out-self.config)
Expand All @@ -35,7 +36,8 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
-- +-- etc
log "checking cyclical with hops; out, out, twice back"
cyclical2a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-2-out-out-backback.project" ]
assertOutputContains "cyclical import of cyclical-2-out-out-backback-a.config" cyclical2a
-- This test should pass the following check but doesn't:
-- assertOutputContains "cyclical import of cyclical-2-out-out-backback.project" cyclical2a

-- +-- cyclical-2-out-out-back.project
-- +-- cyclical-2-out-out-back-a.config
Expand All @@ -55,6 +57,74 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
cyclical2c <- fails $ cabal' "v2-build" [ "--project-file=cyclical-2-out-out-self.project" ]
assertOutputContains "cyclical import of cyclical-2-out-out-self-b.config" cyclical2c

-- +-- noncyclical-same-filename-a.project
-- +-- noncyclical-same-filename-a.config
-- +-- same-filename/noncyclical-same-filename-a.config (no further imports so not cyclical)
log "checking that cyclical check doesn't false-positive on same file names in different folders; hoping within a folder and then into a subfolder"
cyclical3b <- cabal' "v2-build" [ "--project-file=noncyclical-same-filename-a.project" ]
assertOutputDoesNotContain "cyclical import of" cyclical3b

-- +-- noncyclical-same-filename-b.project
-- +-- same-filename/noncyclical-same-filename-b.config
-- +-- noncyclical-same-filename-b.config (no further imports so not cyclical)
log "checking that cyclical check doesn't false-positive on same file names in different folders; hoping into a subfolder and then back out again"
cyclical3c <- fails $ cabal' "v2-build" [ "--project-file=noncyclical-same-filename-b.project" ]
assertOutputDoesNotContain "cyclical import of" cyclical3c

-- +-- cyclical-same-filename-out-out-self.project
-- +-- cyclical-same-filename-out-out-self.config
-- +-- same-filename/cyclical-same-filename-out-out-self.config
-- +-- same-filename/cyclical-same-filename-out-out-self.config (already processed)
-- +-- etc
log "checking that cyclical check catches a same file name that imports itself"
cyclical4a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-self.project" ]
assertOutputContains "cyclical import of cyclical-same-filename-out-out-self.config" cyclical4a

-- +-- cyclical-same-filename-out-out-backback.project
-- +-- cyclical-same-filename-out-out-backback.config
-- +-- same-filename/cyclical-same-filename-out-out-backback.config
-- +-- cyclical-same-filename-out-out-backback.project (already processed)
-- +-- etc
log "checking that cyclical check catches importing its importer (with the same file name)"
cyclical4b <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-backback.project" ]
-- This test should pass the following check but doesn't:
-- assertOutputContains "cyclical import of cyclical-same-filename-out-out-backback.project" cyclical4b

-- +-- cyclical-same-filename-out-out-back.project
-- +-- cyclical-same-filename-out-out-back.config
-- +-- same-filename/cyclical-same-filename-out-out-back.config
-- +-- cyclical-same-filename-out-out-back.config (already processed)
-- +-- etc
log "checking that cyclical check catches importing its importer's importer (hopping over same file names)"
cyclical4c <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-back.project" ]
-- This test should pass the following check but doesn't:
-- assertOutputContains "cyclical import of cyclical-same-filename-out-out-back.config" cyclical4c

-- +-- hops-0.project
-- +-- hops/hops-1.config
-- +-- hops-2.config
-- +-- hops/hops-3.config
-- +-- hops-4.config
-- +-- hops/hops-5.config
-- +-- hops-6.config
-- +-- hops/hops-7.config
-- +-- hops-8.config
-- +-- hops/hops-9.config (no further imports so not cyclical)
log "checking that imports work skipping into a subfolder and then back out again and again"
-- This test should pass the following checks but doesn't, it fails (but it shouldn't):
hopping <- fails $ cabal' "v2-build" [ "--project-file=hops-0.project" ]
-- assertOutputContains "this build was affected by the following (project) config files:" hopping
-- assertOutputContains "hops-0.project" hopping
-- assertOutputContains "../hops-2.config" hopping
-- assertOutputContains "../hops-4.config" hopping
-- assertOutputContains "../hops-6.config" hopping
-- assertOutputContains "../hops-8.config" hopping
-- assertOutputContains "hops/hops-1.config" hopping
-- assertOutputContains "hops/hops-3.config" hopping
-- assertOutputContains "hops/hops-5.config" hopping
-- assertOutputContains "hops/hops-7.config" hopping
-- assertOutputContains "hops/hops-9.config" hopping

log "checking bad conditional"
badIf <- fails $ cabal' "v2-build" [ "--project-file=bad-conditional.project" ]
assertOutputContains "Cannot set compiler in a conditional clause of a cabal project file" badIf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: same-filename/cyclical-same-filename-out-out-back.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: cyclical-same-filename-out-out-back.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: same-filename/cyclical-same-filename-out-out-backback.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: cyclical-same-filename-out-out-backback.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: same-filename/cyclical-same-filename-out-out-self.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: cyclical-same-filename-out-out-self.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: hops/hops-1.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: hops/hops-3.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: hops/hops-5.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: hops/hops-7.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: hops/hops-9.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../hops-2.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../hops-4.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../hops-6.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../hops-8.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No imports here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: same-filename/noncyclical-same-filename-a.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: noncyclical-same-filename-a.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No imports here
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

import: same-filename/noncyclical-same-filename-b.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../cyclical-same-filename-out-out-back.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../cyclical-same-filename-out-out-backback.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: cyclical-same-filename-out-out-self.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No imports here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import: ../noncylical-same-filename-b.config
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/0-local.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/0-local.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config <ROOT>/0-local.project requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/0-local.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .
constraints: hashable ==1.4.3.0
constraints: hashable ==1.4.2.0
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/0-local.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude

main = cabalTest . withRepo "repo" . withProjectFile "0-local.project" $ do
fails $ cabal "v2-build" ["--dry-run"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages: .
allow-newer: hashable:*
constraints: hashable ==1.4.2.0
import: stackage-local.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages: .
allow-newer: hashable:*
import: stackage-local.config
constraints: hashable ==1.4.2.0
22 changes: 22 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/1-local.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/1-local-constraints-import.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config stackage-local.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/1-local-import-constraints.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config stackage-local.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/1-local.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

testVersionWin project =
withProjectFile project $ do
fails $ cabal "v2-build" ["--dry-run"]

main = cabalTest . withRepo "repo" $ do
testVersionWin "1-local-constraints-import.project"
testVersionWin "1-local-import-constraints.project"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages: .
allow-newer: hashable:*
constraints: hashable ==1.4.2.0
import: https://www.stackage.org/nightly-2023-12-07/cabal.config
import: with-ghc.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages: .
allow-newer: hashable:*
import: https://www.stackage.org/nightly-2023-12-07/cabal.config
constraints: hashable ==1.4.2.0
import: with-ghc.config
22 changes: 22 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/1-web.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/1-web-constraints-import.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config https://www.stackage.org/nightly-2023-12-07/cabal.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/1-web-import-constraints.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config https://www.stackage.org/nightly-2023-12-07/cabal.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/1-web.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude

testVersionWin project =
withProjectFile project $ do
fails $ cabal "v2-build" ["--dry-run"]

main = cabalTest . withRepo "repo" $ do
-- To avoid this diff:
-- -Build profile: -w ghc-9.6.3 -O1
-- +Build profile: -w ghc-<GHCVER> -O1
skipIfGhcVersion "== 9.6.3"
testVersionWin "1-web-constraints-import.project"
testVersionWin "1-web-import-constraints.project"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages: .
allow-newer: hashable:*
constraints: hashable ==1.4.2.0
import: hop-local.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages: .
allow-newer: hashable:*
import: hop-local.config
constraints: hashable ==1.4.2.0
22 changes: 22 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/2-local.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/2-local-constraints-import.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config stackage-local.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
# cabal v2-build
Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] trying: cabal-version-override-0.1.0.0 (user goal)
[__1] next goal: hashable (dependency of cabal-version-override)
[__1] rejecting: hashable-1.4.3.0 (constraint from project config <ROOT>/2-local-import-constraints.project requires ==1.4.2.0)
[__1] rejecting: hashable-1.4.2.0 (constraint from project config stackage-local.config requires ==1.4.3.0)
[__1] fail (backjumping, conflict set: cabal-version-override, hashable)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hashable (3), cabal-version-override (2)
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/VersionPriority/2-local.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

testVersionWin project =
withProjectFile project $ do
fails $ cabal "v2-build" ["--dry-run"]

main = cabalTest . withRepo "repo" $ do
testVersionWin "2-local-constraints-import.project"
testVersionWin "2-local-import-constraints.project"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages: .
allow-newer: hashable:*
constraints: hashable ==1.4.2.0
import: stackage-web.config
import: with-ghc.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages: .
allow-newer: hashable:*
import: stackage-web.config
constraints: hashable ==1.4.2.0
import: with-ghc.config

0 comments on commit 663e98f

Please sign in to comment.