Skip to content

Commit

Permalink
Rename to TxFwdBwd
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Jan 9, 2025
1 parent cf1f12a commit 9b7ecbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/CheckSetup/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main = cabalTest $ do

-- 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}}
let lineBreakBlind = needleHaystack{txHaystack = txFwdBwdId{txFwd = lineBreaksToSpaces}}

-- Asserts for the desired check messages after configure.
assertOn lineBreakBlind libError1 checkResult
Expand Down
20 changes: 10 additions & 10 deletions cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
-- for the strings to search in and the search strings such as re-encoding line
-- breaks or delimiting lines. Both LF and CRLF line breaks are recognized.
module Test.Cabal.NeedleHaystack
( TxContains(..)
, txContainsId
( TxFwdBwd(..)
, txFwdBwdId
, NeedleHaystack(..)
, NeedleHaystackCompare
, symNeedleHaystack
Expand Down Expand Up @@ -131,8 +131,8 @@ or isn't found in the test output.
type NeedleHaystackCompare = String -> String -> Bool

-- | Transformations for the search strings and the text to search in.
data TxContains =
TxContains
data TxFwdBwd =
TxFwdBwd
{
-- | Reverse conversion for display, applied to the forward converted value.
txBwd :: (String -> String),
Expand All @@ -142,8 +142,8 @@ data TxContains =

-- | Identity transformation for the search strings and the text to search in,
-- leaves them unchanged.
txContainsId :: TxContains
txContainsId = TxContains id id
txFwdBwdId :: TxFwdBwd
txFwdBwdId = TxFwdBwd id id

-- | Conversions of the needle and haystack strings, the seach string and the
-- text to search in.
Expand All @@ -152,14 +152,14 @@ data NeedleHaystack =
{
expectNeedleInHaystack :: Bool,
displayHaystack :: Bool,
txNeedle :: TxContains,
txHaystack :: TxContains
txNeedle :: TxFwdBwd,
txHaystack :: TxFwdBwd
}

-- | Symmetric needle and haystack functions, the same conversion for each going
-- forward and the same coversion for each going backward.
symNeedleHaystack :: (String -> String) -> (String -> String) -> NeedleHaystack
symNeedleHaystack bwd fwd = let tx = TxContains bwd fwd in NeedleHaystack True False tx tx
symNeedleHaystack bwd fwd = let tx = TxFwdBwd bwd fwd in NeedleHaystack True False tx tx

-- | Multiline needle and haystack functions with symmetric conversions. Going
-- forward converts line breaks to @"\\n"@. Going backward adds visible
Expand All @@ -170,7 +170,7 @@ multilineNeedleHaystack = symNeedleHaystack delimitLines encodeLf
-- | Minimal set up for finding the needle in the haystack. Doesn't change the
-- strings and doesn't display the haystack in any assertion failure message.
needleHaystack :: NeedleHaystack
needleHaystack = NeedleHaystack True False txContainsId txContainsId
needleHaystack = NeedleHaystack True False txFwdBwdId txFwdBwdId

-- | Replace line breaks with spaces, correctly handling @"\\r\\n"@.
--
Expand Down
12 changes: 6 additions & 6 deletions cabal-testsuite/src/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,12 @@ recordMode mode = withReaderT (\env -> env {
-- See Note [Multiline Needles]
assertOutputContains :: MonadIO m => WithCallStack (String -> Result -> m ())
assertOutputContains = assertOn isInfixOf needleHaystack
{txHaystack = TxContains{txBwd = delimitLines, txFwd = encodeLf}}
{txHaystack = TxFwdBwd{txBwd = delimitLines, txFwd = encodeLf}}

assertOutputDoesNotContain :: MonadIO m => WithCallStack (String -> Result -> m ())
assertOutputDoesNotContain = assertOn isInfixOf needleHaystack
{ expectNeedleInHaystack = False
, txHaystack = TxContains{txBwd = delimitLines, txFwd = encodeLf}
, txHaystack = TxFwdBwd{txBwd = delimitLines, txFwd = encodeLf}
}

-- See Note [Multiline Needles]
Expand All @@ -833,15 +833,15 @@ assertOn isIn NeedleHaystack{..} (txFwd txNeedle -> needle) (txFwd txHaystack. r

assertOutputMatches :: MonadIO m => WithCallStack (String -> Result -> m ())
assertOutputMatches = assertOn (flip (=~)) needleHaystack
{ txNeedle = TxContains{txBwd = ("regex match with '" ++) . (++ "'"), txFwd = id}
, txHaystack = TxContains{txBwd = delimitLines, txFwd = encodeLf}
{ txNeedle = TxFwdBwd{txBwd = ("regex match with '" ++) . (++ "'"), txFwd = id}
, txHaystack = TxFwdBwd{txBwd = delimitLines, txFwd = encodeLf}
}

assertOutputDoesNotMatch :: MonadIO m => WithCallStack (String -> Result -> m ())
assertOutputDoesNotMatch = assertOn (flip (=~)) needleHaystack
{ expectNeedleInHaystack = False
, txNeedle = TxContains{txBwd = ("regex match with '" ++) . (++ "'"), txFwd = id}
, txHaystack = TxContains{txBwd = delimitLines, txFwd = encodeLf}
, txNeedle = TxFwdBwd{txBwd = ("regex match with '" ++) . (++ "'"), txFwd = id}
, txHaystack = TxFwdBwd{txBwd = delimitLines, txFwd = encodeLf}
}

assertFindInFile :: MonadIO m => WithCallStack (String -> FilePath -> m ())
Expand Down

0 comments on commit 9b7ecbd

Please sign in to comment.