Skip to content

Commit

Permalink
Add woops project test
Browse files Browse the repository at this point in the history
- Add woops test
- Regen expected output without duplication
- Add "when using config from" tests
- Remove unnecessary normalizeWindowsOutput
- Change assertion message
- Match on (\n|\r\n) for line endings
- Note /tmp/cabal-testsuite-*/ not seen on Windows
- Always have the project itself sort first
- Use with-ghc.config with woops project
- Remove docProjectConfigPaths
- docProjectConfigFiles is the better name when not reporting "imported by"
- Use --dry-run for config listing tests
- Only use woops project once in tests
- Don't use same project twice in tests
- Put dedup test into its own folder
  • Loading branch information
philderbeast committed Dec 11, 2024
1 parent 63cb8fd commit 4ab4537
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# checking "using config from message" with URI imports
# cabal v2-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Test.Cabal.Prelude

main = cabalTest . recordMode RecordMarked $ do
let log = recordHeader . pure

log "checking \"using config from message\" with URI imports"
woopping <- fails $ cabal' "v2-build" [ "--dry-run", "--project-file=woops-0-packages-in-woops.project" ]

-- Use assertRegex when the output is tainted by the temp directory, like
-- this:
--
-- When using configuration from:
-- - /tmp/cabal-testsuite-282695/woops-0.project
-- - /tmp/cabal-testsuite-282695/woops-2.config etc
assertRegex
"Project configuration with URI imports is listed in full"
"When using configuration from:(\n|\r\n) \
\ .*woops-0-packages-in-woops\\.project(\n|\r\n) \
\ .*with-ghc\\.config(\n|\r\n) \
\ .*woops-0\\.config(\n|\r\n) \
\ .*woops-2\\.config(\n|\r\n) \
\ .*woops-4\\.config(\n|\r\n) \
\ .*woops-6\\.config(\n|\r\n) \
\ .*woops-8\\.config(\n|\r\n) \
\ .*woops-1\\.config(\n|\r\n) \
\ .*woops-3\\.config(\n|\r\n) \
\ .*woops-5\\.config(\n|\r\n) \
\ .*woops-7\\.config(\n|\r\n) \
\ .*woops-9\\.config(\n|\r\n) \
\ .*https://www.stackage.org/lts-21.25/cabal.config(\n|\r\n)"
woopping

assertOutputContains
"The following errors occurred: \
\ - The package directory 'woops' does not contain any .cabal file."
woopping

return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- WARNING: Override the `with-compiler: ghc-x.y.z` of the stackage import, of
-- https://www.stackage.org/nightly-yyyy-mm-dd/cabal.config. Otherwise tests
-- will fail with:
-- -Error: [Cabal-5490]
-- -Cannot find the program 'ghc'. User-specified path 'ghc-x.y.z' does not
-- refer to an executable and the program is not on the system path.
with-compiler: ghc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: woops

import: woops-0.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import: woops/woops-1.config
import: woops/woops-3.config
import: woops/woops-5.config
import: woops/woops-7.config
import: woops/woops-9.config

import: with-ghc.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: woops/woops-3.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: woops/woops-5.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: woops/woops-7.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: woops/woops-9.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: ../woops-2.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: ../woops-4.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: ../woops-6.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import: ../woops-8.config
import: https://www.stackage.org/lts-21.25/cabal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- No imports here
import: https://www.stackage.org/lts-21.25/cabal.config
6 changes: 4 additions & 2 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ 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
Configuration is affected by the following files:
- noncyclical-same-filename-a.project
- noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.project
- noncyclical-same-filename-a.project
- same-filename/noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.config
imported by: noncyclical-same-filename-a.project
Expand All @@ -83,10 +83,10 @@ 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
Configuration is affected by the following files:
- noncyclical-same-filename-b.project
- noncyclical-same-filename-b.config
imported by: same-filename/noncyclical-same-filename-b.config
imported by: noncyclical-same-filename-b.project
- noncyclical-same-filename-b.project
- same-filename/noncyclical-same-filename-b.config
imported by: noncyclical-same-filename-b.project
Up to date
Expand Down Expand Up @@ -379,6 +379,8 @@ Configuration is affected by the following files:
imported by: yops/yops-1.config
imported by: yops-0.project
Up to date
# checking "using config from message" without URI imports
# cabal v2-build
# checking bad conditional
# cabal v2-build
Error: [Cabal-7090]
Expand Down
35 changes: 35 additions & 0 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,41 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
log "checking if we detect when the same config is imported via many different paths (we don't)"
yopping <- cabal' "v2-build" [ "--project-file=yops-0.project" ]

log "checking \"using config from message\" without URI imports"
withDirectory "yops" $ do
yopping <- fails $ cabal' "v2-build" [ "--dry-run", "--project-file=../yops-0.project" ]

-- Use assertRegex when the output is tainted by the temp directory, like
-- this:
--
-- When using configuration from:
-- - /tmp/cabal-testsuite-286573/yops-0.project
-- - /tmp/cabal-testsuite-286573/yops-2.config etc
--
-- The addition of the /tmp/cabal-testsuite-*/ prefix, I observed on Ubuntu
-- but not on Windows.
assertRegex
"Project configuration without URI imports is listed in full"
"When using configuration from:(\n|\r\n) \
\ .*yops-0\\.project(\n|\r\n) \
\ .*yops-2\\.config(\n|\r\n) \
\ .*yops-4\\.config(\n|\r\n) \
\ .*yops-6\\.config(\n|\r\n) \
\ .*yops-8\\.config(\n|\r\n) \
\ .*yops-1\\.config(\n|\r\n) \
\ .*yops-3\\.config(\n|\r\n) \
\ .*yops-5\\.config(\n|\r\n) \
\ .*yops-7\\.config(\n|\r\n) \
\ .*yops-9\\.config(\n|\r\n)"
yopping

assertOutputContains
"The following errors occurred: \
\ - The package directory '.' does not contain any .cabal file."
yopping

return ()

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,7 @@
-- WARNING: Override the `with-compiler: ghc-x.y.z` of the stackage import, of
-- https://www.stackage.org/nightly-yyyy-mm-dd/cabal.config. Otherwise tests
-- will fail with:
-- -Error: [Cabal-5490]
-- -Cannot find the program 'ghc'. User-specified path 'ghc-x.y.z' does not
-- refer to an executable and the program is not on the system path.
with-compiler: ghc

0 comments on commit 4ab4537

Please sign in to comment.