Skip to content

Commit

Permalink
Fix up existing tests with multiline expectations
Browse files Browse the repository at this point in the history
(cherry picked from commit 484ac9c)

# Conflicts:
#	cabal-testsuite/PackageTests/ProjectImport/DedupUsingConfigFromComplex/cabal.out
#	cabal-testsuite/PackageTests/ProjectImport/DedupUsingConfigFromComplex/cabal.test.hs
  • Loading branch information
philderbeast authored and mergify[bot] committed Jan 14, 2025
1 parent ead42eb commit 1a4350a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ main = setupAndCabalTest . withPackageDb $ do
assertEqual
("executable should have linked with the internal library")
("foo foo myLibFunc internal")
(concatOutput (resultOutput r))
(lineBreaksToSpaces $ resultOutput r)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ main = setupAndCabalTest . withPackageDb $ do
assertEqual
("executable should have linked with the internal library")
("foo foo myLibFunc internal")
(concatOutput (resultOutput r))
(lineBreaksToSpaces $ resultOutput r)
8 changes: 6 additions & 2 deletions cabal-testsuite/PackageTests/CheckSetup/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ main = cabalTest $ do
"The dependency 'setup-depends: 'base' does not specify "
++ "an upper bound on the version number"

-- Replace line breaks with spaces in the haystack so that we can search
-- for a string that wraps lines.
let lineBreakBlind = needleHaystack{txHaystack = txContainsId{txFwd = lineBreaksToSpaces}}

-- Asserts for the desired check messages after configure.
assertOutputContains libError1 checkResult
assertOutputContains libError2 checkResult
assertOn lineBreakBlind libError1 checkResult
assertOn lineBreakBlind libError2 checkResult

return ()
199 changes: 89 additions & 110 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Test.Cabal.Prelude

normalizeWindowsOutput :: String -> String
normalizeWindowsOutput = if isWindows then map (\x -> case x of '/' -> '\\'; _ -> x) else id
import Test.Cabal.OutputNormalizer
import Data.Function ((&))

main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
let log = recordHeader . pure
Expand Down Expand Up @@ -111,89 +110,65 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
-- +-- 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"
hopping <- cabal' "v2-build" [ "--project-file=hops-0.project" ]
assertOutputContains "Configuration is affected by the following files" hopping
assertOutputContains "- hops-0.project" hopping

assertOutputContains
(normalizeWindowsOutput "- hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops-6.config \
\ imported by: hops/hops-5.config \
\ imported by: hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops-8.config \
\ imported by: hops/hops-7.config \
\ imported by: hops-6.config \
\ imported by: hops/hops-5.config \
\ imported by: hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops/hops-5.config \
\ imported by: hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops/hops-7.config \
\ imported by: hops-6.config \
\ imported by: hops/hops-5.config \
\ imported by: hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

assertOutputContains
(normalizeWindowsOutput "- hops/hops-9.config \
\ imported by: hops-8.config \
\ imported by: hops/hops-7.config \
\ imported by: hops-6.config \
\ imported by: hops/hops-5.config \
\ imported by: hops-4.config \
\ imported by: hops/hops-3.config \
\ imported by: hops-2.config \
\ imported by: hops/hops-1.config \
\ imported by: hops-0.project")
hopping

"Configuration is affected by the following files:\n\
\- hops-0.project\n\
\- hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops-6.config\n\
\ imported by: hops/hops-5.config\n\
\ imported by: hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops-8.config\n\
\ imported by: hops/hops-7.config\n\
\ imported by: hops-6.config\n\
\ imported by: hops/hops-5.config\n\
\ imported by: hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops/hops-5.config\n\
\ imported by: hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops/hops-7.config\n\
\ imported by: hops-6.config\n\
\ imported by: hops/hops-5.config\n\
\ imported by: hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project\n\
\- hops/hops-9.config\n\
\ imported by: hops-8.config\n\
\ imported by: hops/hops-7.config\n\
\ imported by: hops-6.config\n\
\ imported by: hops/hops-5.config\n\
\ imported by: hops-4.config\n\
\ imported by: hops/hops-3.config\n\
\ imported by: hops-2.config\n\
\ imported by: hops/hops-1.config\n\
\ imported by: hops-0.project"
& normalizeWindowsOutput
& flip (assertOn multilineNeedleHaystack) hopping

-- The project is named oops as it is like hops but has conflicting constraints.
-- +-- oops-0.project
Expand All @@ -208,36 +183,40 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
-- +-- oops/oops-9.config (has conflicting constraints)
log "checking conflicting constraints skipping into a subfolder and then back out again and again"
oopsing <- fails $ cabal' "v2-build" [ "all", "--project-file=oops-0.project" ]
assertOutputContains "rejecting: hashable-1.4.2.0" oopsing
assertOutputContains "rejecting: hashable-1.4.3.0" oopsing
assertOutputContains "(constraint from oops-0.project requires ==1.4.3.0)" oopsing

assertOutputContains
(normalizeWindowsOutput " (constraint from oops/oops-9.config requires ==1.4.2.0) \
\ imported by: oops-8.config \
\ imported by: oops/oops-7.config \
\ imported by: oops-6.config \
\ imported by: oops/oops-5.config \
\ imported by: oops-4.config \
\ imported by: oops/oops-3.config \
\ imported by: oops-2.config \
\ imported by: oops/oops-1.config \
\ imported by: oops-0.project")
oopsing

"Could not resolve dependencies:\n\
\[__0] trying: oops-0.1 (user goal)\n\
\[__1] next goal: hashable (dependency of oops)\n\
\[__1] rejecting: hashable-1.4.3.0\n\
\ (constraint from oops/oops-9.config requires ==1.4.2.0)\n\
\ imported by: oops-8.config\n\
\ imported by: oops/oops-7.config\n\
\ imported by: oops-6.config\n\
\ imported by: oops/oops-5.config\n\
\ imported by: oops-4.config\n\
\ imported by: oops/oops-3.config\n\
\ imported by: oops-2.config\n\
\ imported by: oops/oops-1.config\n\
\ imported by: oops-0.project\n\
\[__1] rejecting: hashable-1.4.2.0\n\
\ (constraint from oops-0.project requires ==1.4.3.0)"
& normalizeWindowsOutput
& flip (assertOn multilineNeedleHaystack) oopsing

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

log "checking that missing package message lists configuration provenance"
missing <- fails $ cabal' "v2-build" [ "--project-file=cabal-missing-package.project" ]
assertOutputContains
(normalizeWindowsOutput "When using configuration from: \
\ - cabal-missing-package.project \
\ - missing/pkgs.config \
\ - missing/pkgs/default.config \
\The following errors occurred: \
\ - The package location 'pkg-doesnt-exist' does not exist.")
missing

"When using configuration from:\n\
\ - cabal-missing-package.project\n\
\ - missing/pkgs.config\n\
\ - missing/pkgs/default.config\n\
\The following errors occurred:\n\
\ - The package location 'pkg-doesnt-exist' does not exist."
& normalizeWindowsOutput
& flip (assertOn multilineNeedleHaystack) missing

return ()
10 changes: 5 additions & 5 deletions cabal-testsuite/PackageTests/NewBuild/T4288/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Test.Cabal.Prelude
import Data.Function ((&))

-- This test is similar to the simplified example in issue #4288. The package's
-- setup script only depends on base and setup-helper. setup-helper exposes a
Expand All @@ -10,8 +11,7 @@ main = cabalTest $ do
skipUnless "no v2-build compatible boot-Cabal" =<< hasNewBuildCompatBootCabal
r <- recordMode DoNotRecord $ cabal' "v2-build" ["T4288"]
assertOutputContains "This is setup-helper-1.0." r
assertOutputContains
("In order, the following will be built: "
++ " - setup-helper-1.0 (lib:setup-helper) (first run) "
++ " - T4288-1.0 (lib:T4288) (first run)")
r
"In order, the following will be built:\n\
\ - setup-helper-1.0 (lib:setup-helper) (first run)\n\
\ - T4288-1.0 (lib:T4288) (first run)"
& flip (assertOn multilineNeedleHaystack) r
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# check "using config from message" with URI imports
# cabal v2-build
# check project configuration with URI imports is listed in full and
# check package directories and locations are reported in order
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Test.Cabal.Prelude
import Data.Function ((&))

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

log "checking \"using config from message\" with URI imports"
out <- fails $ cabal' "v2-build" [ "all", "--dry-run", "--project-file=no-pkgs.project" ]

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

log "checking that package directories and locations are reported in order"

"The following errors occurred:\n\
\ - The package directory 'no-pkg-1' does not contain any .cabal file.\n\
\ - The package location 'no-pkg-2-dir' does not exist.\n\
\ - The package directory 'no-pkg-3' does not contain any .cabal file.\n\
\ - The package location 'no-pkg-4-dir' does not exist."
& flip (assertOn multilineNeedleHaystack) out

return ()
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Test.Cabal.Prelude
import Data.Function ((&))

-- The local package, pkg-1.0, depends on build-tool-pkg-1 as a library and
-- build-tool-pkg-2 as a build-tool. This test checks that cabal uses the
Expand All @@ -16,16 +17,13 @@ main = cabalTest $ withShorterPathForNewBuildStore $ do
r1 <- recordMode DoNotRecord $
cabal' "v2-build" ["pkg:my-exe"]

let msg = concat
[ "In order, the following will be built:"
, " - build-tool-pkg-1 (lib) (requires build)"
, " - build-tool-pkg-2 (lib) (requires build)"
, " - build-tool-pkg-2 (exe:build-tool-exe) (requires build)"
, " - pkg-1.0 (exe:my-exe) (first run)"
]
"In order, the following will be built:\n\
\ - build-tool-pkg-1 (lib) (requires build)\n\
\ - build-tool-pkg-2 (lib) (requires build)\n\
\ - build-tool-pkg-2 (exe:build-tool-exe) (requires build)\n\
\ - pkg-1.0 (exe:my-exe) (first run)"
& flip (assertOn multilineNeedleHaystack) r1

assertOutputContains msg r1
withPlan $ do
r2 <- runPlanExe' "pkg" "my-exe" []
assertOutputContains
"build-tool library version: 1, build-tool exe version: 2" r2
assertOn multilineNeedleHaystack "build-tool library version: 1,\nbuild-tool exe version: 2" r2

0 comments on commit 1a4350a

Please sign in to comment.