Skip to content

Commit

Permalink
Add noncyclical tests that hop over folders
Browse files Browse the repository at this point in the history
- Allow for bad behaviour of master branch
- Add cyclical checks with same file names and hops
- Add cyclical import tests with 1 and 2 hops in cycle
- Expected output has project with full project path
- Add newlines at EOF
  • Loading branch information
philderbeast committed Feb 1, 2024
1 parent 381245d commit 78fcdc6
Show file tree
Hide file tree
Showing 32 changed files with 146 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

0 comments on commit 78fcdc6

Please sign in to comment.