Skip to content

Commit 7e0f040

Browse files
authored
Merge pull request #10735 from cabalism/test/assert-output-matches
Implement assert matches with assert on
2 parents 51e1817 + b2d1fcc commit 7e0f040

File tree

12 files changed

+99
-63
lines changed

12 files changed

+99
-63
lines changed

cabal-testsuite/AssertTests/cabal.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Multiline string marking:
2+
# ^When using configuration from:$
3+
# ^ - else.project$
4+
# ^ - dir-else/else.config$
5+
# ^The following errors occurred:$
6+
# ^ - The package location 'no-pkg-here' does not exist.$
7+
# Pseudo multiline string marking:
8+
# ^When using configuration from: - else.project - dir-else/else.config The following errors occurred: - The package location 'no-pkg-here' does not exist.$
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Test.Cabal.Prelude
2+
import Data.List (isInfixOf)
3+
import System.Directory
4+
import System.Exit
5+
6+
mkResult :: String -> Result
7+
mkResult = Result ExitSuccess "run"
8+
9+
main = cabalTest . recordMode RecordMarked $ do
10+
let log = recordHeader . pure
11+
12+
msg <- readFileVerbatim "msg.expect.txt"
13+
let out = mkResult msg
14+
let msgSingle = lineBreaksToSpaces msg
15+
16+
log "Multiline string marking:"
17+
mapM_ log (lines . delimitLines $ encodeLf msg)
18+
assertOn isInfixOf multilineNeedleHaystack msg out
19+
assertOutputContains msg out
20+
21+
assertOutputMatches "^When.*from:$" out
22+
assertOutputMatches "no[-]{1,1}pkg-here" out
23+
24+
assertOutputMatches "else\\.project" out
25+
assertOutputMatches "else\\/else" out
26+
27+
assertOutputMatches "^The f[lo]{4,}wing[[:space:]]errors[ ]{1,1}occurred[:]*$" out
28+
29+
assertOutputMatches " errors " out
30+
assertOutputDoesNotMatch " error " out
31+
32+
assertOutputMatches "[[:space:]]+errors[[:space:]]+" out
33+
assertOutputDoesNotMatch "[[:space:]]+error[[:space:]]+" out
34+
35+
log "Pseudo multiline string marking:"
36+
mapM_ log (lines . delimitLines $ encodeLf msgSingle)
37+
assertOn isInfixOf multilineNeedleHaystack{expectNeedleInHaystack = False} msgSingle out
38+
assertOutputDoesNotContain msgSingle out
39+
40+
return ()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
When using configuration from:
2+
- else.project
3+
- dir-else/else.config
4+
The following errors occurred:
5+
- The package location 'no-pkg-here' does not exist.

cabal-testsuite/PackageTests/CheckSetup/setup.test.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Test.Cabal.Prelude
2+
import Data.List (isInfixOf)
23

34
-- Test that setup shows all the 'autogen-modules' warnings.
45
main = cabalTest $ do
@@ -15,10 +16,10 @@ main = cabalTest $ do
1516

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

2021
-- Asserts for the desired check messages after configure.
21-
assertOn lineBreakBlind libError1 checkResult
22-
assertOn lineBreakBlind libError2 checkResult
22+
assertOn isInfixOf lineBreakBlind libError1 checkResult
23+
assertOn isInfixOf lineBreakBlind libError2 checkResult
2324

2425
return ()

cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Test.Cabal.Prelude
22
import Test.Cabal.OutputNormalizer
33
import Data.Function ((&))
44
import Data.Functor ((<&>))
5+
import Data.List (isInfixOf)
56

67
main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
78
let log = recordHeader . pure
@@ -113,7 +114,7 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
113114
hopping <- cabal' "v2-build" [ "--project-file=hops-0.project" ]
114115

115116
readFileVerbatim "hops.expect.txt" >>=
116-
flip (assertOn multilineNeedleHaystack) hopping . normalizePathSeparators
117+
flip (assertOn isInfixOf multilineNeedleHaystack) hopping . normalizePathSeparators
117118

118119
-- The project is named oops as it is like hops but has conflicting constraints.
119120
-- +-- oops-0.project
@@ -130,7 +131,7 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
130131
oopsing <- fails $ cabal' "v2-build" [ "all", "--project-file=oops-0.project" ]
131132

132133
readFileVerbatim "oops.expect.txt"
133-
>>= flip (assertOn multilineNeedleHaystack) oopsing . normalizePathSeparators
134+
>>= flip (assertOn isInfixOf multilineNeedleHaystack) oopsing . normalizePathSeparators
134135

135136
-- The project is named yops as it is like hops but with y's for forks.
136137
-- +-- yops-0.project
@@ -173,6 +174,6 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
173174
missing <- fails $ cabal' "v2-build" [ "--project-file=cabal-missing-package.project" ]
174175

175176
readFileVerbatim "cabal-missing-package.expect.txt"
176-
>>= flip (assertOn multilineNeedleHaystack) missing . normalizePathSeparators
177+
>>= flip (assertOn isInfixOf multilineNeedleHaystack) missing . normalizePathSeparators
177178

178179
return ()

cabal-testsuite/PackageTests/NewBuild/T4288/cabal.test.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Test.Cabal.Prelude
22
import Data.Function ((&))
3+
import Data.List (isInfixOf)
34

45
-- This test is similar to the simplified example in issue #4288. The package's
56
-- setup script only depends on base and setup-helper. setup-helper exposes a
@@ -14,4 +15,4 @@ main = cabalTest $ do
1415
"In order, the following will be built:\n\
1516
\ - setup-helper-1.0 (lib:setup-helper) (first run)\n\
1617
\ - T4288-1.0 (lib:T4288) (first run)"
17-
& flip (assertOn multilineNeedleHaystack) r
18+
& flip (assertOn isInfixOf multilineNeedleHaystack) r

cabal-testsuite/PackageTests/ProjectImport/DedupUsingConfigFromComplex/cabal.test.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Test.Cabal.Prelude
22
import Data.Function ((&))
3+
import Data.List (isInfixOf)
34

45
main = cabalTest . flakyIfCI 10927. recordMode RecordMarked $ do
56
let log = recordHeader . pure
@@ -11,6 +12,6 @@ main = cabalTest . flakyIfCI 10927. recordMode RecordMarked $ do
1112
log "check package directories and locations are reported in order"
1213

1314
readFileVerbatim "errors.expect.txt"
14-
>>= flip (assertOn multilineNeedleHaystack) out . normalizePathSeparators
15+
>>= flip (assertOn isInfixOf multilineNeedleHaystack) out . normalizePathSeparators
1516

1617
return ()

cabal-testsuite/PackageTests/ProjectImport/ParseErrorProvenance/cabal.out

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# cabal v2-build
22
Warnings found while parsing the project file, else.project:
33
- dir-else/else.config: Unrecognized section '_' on line 3
4-
# Multiline string marking:
5-
# ^When using configuration from:$
6-
# ^ - else.project$
7-
# ^ - dir-else/else.config$
8-
# ^The following errors occurred:$
9-
# ^ - The package location 'no-pkg-here' does not exist.$
10-
# Pseudo multiline string marking:
11-
# ^When using configuration from: - else.project - dir-else/else.config The following errors occurred: - The package location 'no-pkg-here' does not exist.$
124
# cabal v2-build
135
Error: [Cabal-7090]
146
Error parsing project file cabal.project:3:

cabal-testsuite/PackageTests/ProjectImport/ParseErrorProvenance/cabal.test.hs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
import Test.Cabal.Prelude
2-
import System.Directory
32

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

76
outElse <- fails $ cabal' "v2-build" [ "all", "--dry-run", "--project-file=else.project" ]
8-
97
msg <- readFileVerbatim "msg.expect.txt"
10-
let msgSingle = lineBreaksToSpaces msg
11-
12-
log "Multiline string marking:"
13-
mapM_ log (lines . delimitLines $ encodeLf msg)
14-
15-
log "Pseudo multiline string marking:"
16-
mapM_ log (lines . delimitLines $ encodeLf msgSingle)
17-
18-
assertOn multilineNeedleHaystack msg outElse
19-
assertOn multilineNeedleHaystack{expectNeedleInHaystack = False} msgSingle outElse
20-
218
assertOutputContains msg outElse
22-
assertOutputDoesNotContain msgSingle outElse
239

2410

2511
outDefault <- fails $ cabal' "v2-build" [ "all", "--dry-run", "--project-file=cabal.project" ]

cabal-testsuite/PackageTests/Regression/T5409/use-different-versions-of-dependency-for-library-and-build-tool.test.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Test.Cabal.Prelude
22
import Data.Function ((&))
3+
import Data.List (isInfixOf)
34

45
-- The local package, pkg-1.0, depends on build-tool-pkg-1 as a library and
56
-- build-tool-pkg-2 as a build-tool. This test checks that cabal uses the
@@ -22,8 +23,8 @@ main = cabalTest $ withShorterPathForNewBuildStore $ do
2223
\ - build-tool-pkg-2 (lib) (requires build)\n\
2324
\ - build-tool-pkg-2 (exe:build-tool-exe) (requires build)\n\
2425
\ - pkg-1.0 (exe:my-exe) (first run)"
25-
& flip (assertOn multilineNeedleHaystack) r1
26+
& flip (assertOn isInfixOf multilineNeedleHaystack) r1
2627

2728
withPlan $ do
2829
r2 <- runPlanExe' "pkg" "my-exe" []
29-
assertOn multilineNeedleHaystack "build-tool library version: 1,\nbuild-tool exe version: 2" r2
30+
assertOn isInfixOf multilineNeedleHaystack "build-tool library version: 1,\nbuild-tool exe version: 2" r2

0 commit comments

Comments
 (0)