From 8fa21197199806ed65bb635a82334b99562defa1 Mon Sep 17 00:00:00 2001 From: Andreas Gruhler Date: Sun, 19 Jan 2025 13:59:24 +0100 Subject: [PATCH] doc(cookbook): add specific case shell_output stderr Document the specific case, where your program writes an error to stderr that needs to be checked in a test (e.g., using `assert_match` and `shell_output`): * https://github.com/Homebrew/brew/issues/5149 Co-authored-by: Mike McQuaid --- docs/Formula-Cookbook.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index b62706023446d..9b2de44654978 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -334,6 +334,14 @@ test do end ``` +* If the binary only writes to `stderr`, you can redirect `stderr` to `stdout` for assertions with `shell_output`. For example: + +```ruby +test do + assert_match "Output on stderr", shell_output("#{bin}/formula-program 2>&1", 2) +end +``` + ### Manuals Homebrew expects to find manual pages in `#{prefix}/share/man/...`, and not in `#{prefix}/man/...`.