diff --git a/unison-cli/src/Unison/Codebase/Transcript/Runner.hs b/unison-cli/src/Unison/Codebase/Transcript/Runner.hs index ee2530a68c..97082cfab5 100644 --- a/unison-cli/src/Unison/Codebase/Transcript/Runner.hs +++ b/unison-cli/src/Unison/Codebase/Transcript/Runner.hs @@ -210,18 +210,19 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL liftIO $ writeIORef hasErrors True liftIO (liftA2 (,) (readIORef allowErrors) (readIORef expectFailure)) >>= \case (False, False) -> liftIO . dieWithMsg $ Pretty.toPlain terminalWidth msg - (True, True) -> - transcriptFailure - out - ( Text.pack . Pretty.toPlain terminalWidth $ - Pretty.lines - [ "The stanza above marked with `:error :bug` is now failing with", - Pretty.border 2 msg, - "so you can remove `:bug` and close any appropriate Github issues. If the error message is \ - \different from the expected error message, open a new issue and reference it in this transcript." - ] - ) - Nothing + (True, True) -> do + appendFailingStanza + fixedBug out $ + Text.unlines + [ "The stanza above marked with `:error :bug` is now failing with", + "", + "```", + Text.pack $ Pretty.toPlain terminalWidth msg, + "```", + "", + "so you can remove `:bug` and close any appropriate Github issues. If the error message is different \ + \from the expected error message, open a new issue and reference it in this transcript." + ] (_, _) -> pure () apiRequest :: APIRequest -> IO [APIRequest] @@ -467,12 +468,10 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL "The transcript was expecting an error in the stanza above, but did not encounter one." Nothing (False, True, False) -> do - appendFailingStanza - transcriptFailure + fixedBug out "The stanza above with `:bug` is now passing! You can remove `:bug` and close any appropriate Github \ \issues." - Nothing (_, _, _) -> pure () authenticatedHTTPClient <- AuthN.newAuthenticatedHTTPClient tokenProvider ucmVersion @@ -528,6 +527,22 @@ transcriptFailure out heading mbody = do <> foldr ((:) . CMarkCodeBlock Nothing "") [] mbody ) +fixedBug :: IORef (Seq Stanza) -> Text -> IO b +fixedBug out body = do + texts <- readIORef out + -- `CMark.commonmarkToNode` returns a @DOCUMENT@, which won’t be rendered inside another document, so we strip the + -- outer `CMark.Node`. + let CMark.Node _ _DOCUMENT bodyNodes = CMark.commonmarkToNode [CMark.optNormalize] body + UnliftIO.throwIO . RunFailure $ + texts + <> Seq.fromList + ( Left + <$> [ CMark.Node Nothing CMark.PARAGRAPH [CMark.Node Nothing (CMark.TEXT "🎉") []], + CMark.Node Nothing (CMark.HEADING 2) [CMark.Node Nothing (CMark.TEXT "You fixed a bug!") []] + ] + <> bodyNodes + ) + data Error = ParseError (P.ParseErrorBundle Text Void) | RunFailure (Seq Stanza) diff --git a/unison-src/transcripts/errors/obsolete-bug.md b/unison-src/transcripts/errors/obsolete-bug.md new file mode 100644 index 0000000000..6f2a9641eb --- /dev/null +++ b/unison-src/transcripts/errors/obsolete-bug.md @@ -0,0 +1,5 @@ +This transcript will error, because we’re claiming that the stanza has a bug, but `help` works as expected. + +``` ucm :bug +scratch/main> help edit +``` diff --git a/unison-src/transcripts/errors/obsolete-bug.output.md b/unison-src/transcripts/errors/obsolete-bug.output.md new file mode 100644 index 0000000000..b88fe47b32 --- /dev/null +++ b/unison-src/transcripts/errors/obsolete-bug.output.md @@ -0,0 +1,15 @@ +This transcript will error, because we’re claiming that the stanza has a bug, but `help` works as expected. + +``` ucm :bug +scratch/main> help edit + + edit + `edit foo` prepends the definition of `foo` to the top of the most recently saved file. + `edit` without arguments invokes a search to select a definition for editing, which requires that `fzf` can be found within your PATH. +``` + +🎉 + +## You fixed a bug\! + +The stanza above with `:bug` is now passing\! You can remove `:bug` and close any appropriate Github issues. diff --git a/unison-src/transcripts/errors/obsolete-error-bug.md b/unison-src/transcripts/errors/obsolete-error-bug.md new file mode 100644 index 0000000000..39b6f667ad --- /dev/null +++ b/unison-src/transcripts/errors/obsolete-error-bug.md @@ -0,0 +1,5 @@ +This transcript will fail, because we’re claiming that the stanza has a bug, but `do.something` errors as expected. + +``` ucm :error :bug +scratch/main> do.something +``` diff --git a/unison-src/transcripts/errors/obsolete-error-bug.output.md b/unison-src/transcripts/errors/obsolete-error-bug.output.md new file mode 100644 index 0000000000..7a3a16789b --- /dev/null +++ b/unison-src/transcripts/errors/obsolete-error-bug.output.md @@ -0,0 +1,19 @@ +This transcript will fail, because we’re claiming that the stanza has a bug, but `do.something` errors as expected. + +``` ucm :error :bug +scratch/main> do.something +``` + +🎉 + +## You fixed a bug\! + +The stanza above marked with `:error :bug` is now failing with + +``` +⚠️ +I don't know how to do.something. Type `help` or `?` to get +help. +``` + +so you can remove `:bug` and close any appropriate Github issues. If the error message is different from the expected error message, open a new issue and reference it in this transcript. diff --git a/unison-src/transcripts/idempotent/bug.md b/unison-src/transcripts/idempotent/bug.md new file mode 100644 index 0000000000..9469b77067 --- /dev/null +++ b/unison-src/transcripts/idempotent/bug.md @@ -0,0 +1,19 @@ +This tests that `:bug` behaves similarly to `:error` when the stanza fails. + +``` ucm :bug +scratch/main> do.something + + ⚠️ + I don't know how to do.something. Type `help` or `?` to get + help. +``` + +And when combined with `:error`, it should expect a successful result. + +``` ucm :error :bug +scratch/main> help edit + + edit + `edit foo` prepends the definition of `foo` to the top of the most recently saved file. + `edit` without arguments invokes a search to select a definition for editing, which requires that `fzf` can be found within your PATH. +```