Skip to content

Commit

Permalink
Add normalizePathSeparator
Browse files Browse the repository at this point in the history
- Don't modify path separator for URIs
- Don't normalize path with anything URI-like
- Normalize expected output
- Rename to normalizePathSeparators
- Add an explicit export list to NeedleHaystack
- Drop unlines . lines added trailing newline
- Show example of normalizePathSeparators
- Tidy up haddocks
- Use local unsnoc definition to avoid CPP
- Define local unlines
- Satisfy fix-whitespace
- Don't use <EOL>
- Rename to delimitLines
- Satisfy fix-whitespace
- Rename the changelog with *.md extension
- Add a section on cabal-testsuite changes
- Rename the function to readFileVerbatim
- Add to contributing and cabal-testsuite's readme
- Use setup for the noun
- Typo s/displaying/display
- Typo "can easier"
- Use unsnoc from Cabal-syntax Utils.Generic
- Add a note [Multiline Needles]
- Remove doctests available elsewhere

Co-Authored-By: brandon s allbery kf8nh <[email protected]>
  • Loading branch information
philderbeast and geekosaur committed Jan 1, 2025
1 parent 24af359 commit bef4f89
Show file tree
Hide file tree
Showing 10 changed files with 453 additions and 94 deletions.
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,12 @@ description: {
}
```

Changelogs may also be written in "markdown-frontmatter" format. This is useful if your
description contains braces, which must be escaped with backslashes in `.cabal` file
format. The front matter is in YAML syntax, not `.cabal` file syntax, and the file
Changelogs may also be written in "markdown-frontmatter" format. This is useful
if your description contains braces, which must be escaped with backslashes in
`.cabal` file format. Another benefit of using an `.md` extension with your
changelog is that it will be checked for typos.

The front matter is in YAML syntax, not `.cabal` file syntax, and the file
_must_ begin with a line containing only hyphens.

```markdown
Expand Down
14 changes: 7 additions & 7 deletions cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
-- +-- 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 (normalizeWindowsOutput "cyclical import of same-filename/cyclical-same-filename-out-out-self.config") cyclical4a
assertOutputContains (normalizePathSeparators "cyclical import of same-filename/cyclical-same-filename-out-out-self.config") cyclical4a

-- +-- cyclical-same-filename-out-out-backback.project
-- +-- cyclical-same-filename-out-out-backback.config
Expand Down Expand Up @@ -112,8 +112,8 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
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" ]

readVerbatimFile "hops.expect.txt" >>=
flip (assertOn multilineNeedleHaystack) hopping . normalizeWindowsOutput
readFileVerbatim "hops.expect.txt" >>=
flip (assertOn multilineNeedleHaystack) hopping . normalizePathSeparators

-- The project is named oops as it is like hops but has conflicting constraints.
-- +-- oops-0.project
Expand All @@ -129,8 +129,8 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
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" ]

readVerbatimFile "oops.expect.txt"
>>= flip (assertOn multilineNeedleHaystack) oopsing . normalizeWindowsOutput
readFileVerbatim "oops.expect.txt"
>>= flip (assertOn multilineNeedleHaystack) oopsing . normalizePathSeparators

-- The project is named yops as it is like hops but with y's for forks.
-- +-- yops-0.project
Expand Down Expand Up @@ -172,7 +172,7 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
log "checking that missing package message lists configuration provenance"
missing <- fails $ cabal' "v2-build" [ "--project-file=cabal-missing-package.project" ]

readVerbatimFile "cabal-missing-package.expect.txt"
>>= flip (assertOn multilineNeedleHaystack) missing . normalizeWindowsOutput
readFileVerbatim "cabal-missing-package.expect.txt"
>>= flip (assertOn multilineNeedleHaystack) missing . normalizePathSeparators

return ()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ main = cabalTest . recordMode RecordMarked $ do
log "check project configuration with URI imports is listed in full and"
log "check package directories and locations are reported in order"

readVerbatimFile "errors.expect.txt" >>= flip (assertOn multilineNeedleHaystack) out
readFileVerbatim "errors.expect.txt"
>>= flip (assertOn multilineNeedleHaystack) out . normalizePathSeparators

return ()
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ main = cabalTest . recordMode RecordMarked $ do

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

msg <- readVerbatimFile "msg.expect.txt"
msg <- readFileVerbatim "msg.expect.txt"
let msgSingle = lineBreaksToSpaces msg

log "Multiline string marking:"
mapM_ log (lines . decodeLfMarkLines $ encodeLf msg)
mapM_ log (lines . delimitLines $ encodeLf msg)

log "Pseudo multiline string marking:"
mapM_ log (lines . decodeLfMarkLines $ encodeLf msgSingle)
mapM_ log (lines . delimitLines $ encodeLf msgSingle)

assertOn multilineNeedleHaystack msg outElse
assertOn multilineNeedleHaystack{expectNeedleInHaystack = False} msgSingle outElse

assertOutputDoesNotContain msg outElse
assertOutputContains msg outElse
assertOutputDoesNotContain msgSingle outElse

return ()
4 changes: 4 additions & 0 deletions cabal-testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ variants of a command (e.g., `cabal'` rather than `cabal`) and use
`assertOutputContains`. Note that this will search over BOTH stdout
and stderr.

For convenience, paste expected multiline string values verbatim into a text
file and read these with `readFileVerbatim`. The suggested extension for these
files are `.expect.txt`.

**How do I skip running a test in some environments?** Use the
`skipIf` and `skipUnless` combinators. Useful parameters to test
these with include `hasSharedLibraries`, `hasProfiledLibraries`,
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/cabal-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library
, exceptions ^>= 0.10.0
, filepath ^>= 1.3.0.1 || ^>= 1.4.0.0 || ^>= 1.5.0.0
, Glob ^>= 0.10.2
, network-uri >= 2.6.0.2 && < 2.7
, network-wait ^>= 0.1.2.0 || ^>= 0.2.0.0
, optparse-applicative ^>= 0.14.3.0 || ^>=0.15.1.0 || ^>=0.16.0.0 || ^>= 0.17.0.0 || ^>= 0.18.1.0
, process ^>= 1.2.1.0 || ^>= 1.4.2.0 || ^>= 1.6.1.0
Expand Down
Loading

0 comments on commit bef4f89

Please sign in to comment.