Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement assert matches with assert on #10735

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

philderbeast
Copy link
Collaborator

A follow on from #10646 that I had to rebase this on top of changes from #10647 that added assertOutputMatches and assertOutputDoesNotMatch to cabal-testsuite/src/Test/Cabal/Prelude.hs. At that time I made this small change but saw that assertOutputMatches and assertOutputDoesNotMatch could be implemented with assertOn. That what this pull request does.

-    unless (concatOutput output =~ regex) $
+    unless (encodeLf output =~ regex) $

Template B: This PR does not modify behaviour or interface

  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

QA Notes

I've moved tests to cabal-testsuite/AssertTests/cabal.test.hs that are only flexing the assert* functions and are not truly package tests. These tests pass but you'll want to see them fail too to see that the output is as expected. To do that you'll need to make a change and rerun the test:

$ git diff
diff --git a/cabal-testsuite/AssertTests/cabal.test.hs b/cabal-testsuite/AssertTests/cabal.test.hs
index d819c99cc..b44acd2e4 100644
--- a/cabal-testsuite/AssertTests/cabal.test.hs
+++ b/cabal-testsuite/AssertTests/cabal.test.hs
@@ -29,7 +29,7 @@ main = cabalTest . recordMode RecordMarked $ do
   assertOutputMatches " errors " out
   assertOutputDoesNotMatch " error " out
 
-  assertOutputMatches "[[:space:]]+errors[[:space:]]+" out
+  assertOutputMatches "[[:space:]]+ewwows[[:space:]]+" out
   assertOutputDoesNotMatch "[[:space:]]+error[[:space:]]+" out
 
   log "Pseudo multiline string marking:"
$ cabal run cabal-testsuite:cabal-tests -- --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.10.1/cabal-install-3.15.0.0/x/cabal/build/cabal/cabal cabal-testsuite/AssertTests/cabal.test.hs
...
# STDERR:
cabal.test.hs: expected:
regex match with '[[:space:]]+ewwows[[:space:]]+'
CallStack (from HasCallStack):
  assertOn, called at src/Test/Cabal/Prelude.hs:835:23 in cabal-testsuite-3-inplace:Test.Cabal.Prelude
  assertOutputMatches, called at cabal-testsuite/AssertTests/cabal.test.hs:32:3 in main:Main

@philderbeast philderbeast force-pushed the test/assert-output-matches branch from 5e476e8 to ff435b7 Compare January 13, 2025 14:44
Copy link
Collaborator

@9999years 9999years left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good. Longer-term, I want better exception-throwing infrastructure that makes it possible to use the normal expect-test and output-marker machinery for these tests.

@philderbeast
Copy link
Collaborator Author

the normal expect-test and output-marker machinery for these tests.

Thanks for the approval @9999years. Could you please link to or describe what you mean by the above?

@9999years
Copy link
Collaborator

@philderbeast I'll put some more details here soon, but here's the general idea:
#10747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants