From bfcce169d893957c7fdbb7ee73a756633e3612e6 Mon Sep 17 00:00:00 2001 From: Andrew Binstock <920630+platypusguy@users.noreply.github.com> Date: Thu, 31 Oct 2024 23:10:55 -0700 Subject: [PATCH] JACOBIN-592 Captured redirecting stderr in tests for easy future reference. (We already use this widely in our tests; just placing it here for easy copy/paste.) --- notes/StderrInTests.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 notes/StderrInTests.txt diff --git a/notes/StderrInTests.txt b/notes/StderrInTests.txt new file mode 100644 index 00000000..8feab9cd --- /dev/null +++ b/notes/StderrInTests.txt @@ -0,0 +1,22 @@ +This code will trap output to stderr for later examination. It's +used extensively in unit tests + + + globals.InitGlobals("test") + + normalStderr := os.Stderr + r, w, _ := os.Pipe() + os.Stderr = w + + + // run test here + + + + _ = w.Close() + msg, _ := io.ReadAll(r) + os.Stderr = normalStderr + + errMsg := string(msg) + + // test content of errMsg