Skip to content

Commit

Permalink
JACOBIN-592 Captured redirecting stderr in tests for easy future refe…
Browse files Browse the repository at this point in the history
…rence. (We already use this widely in our tests; just placing it here for easy copy/paste.)
  • Loading branch information
platypusguy committed Nov 1, 2024
1 parent 1701959 commit bfcce16
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions notes/StderrInTests.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bfcce16

Please sign in to comment.