MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / captureStderr

Function captureStderr

internal/cli/cli_helpers_test.go:46–67  ·  view source on GitHub ↗

captureStderr replaces os.Stderr for the duration of fn and returns what was written.

(t *testing.T, fn func())

Source from the content-addressed store, hash-verified

44
45// captureStderr replaces os.Stderr for the duration of fn and returns what was written.
46func captureStderr(t *testing.T, fn func()) string {
47 t.Helper()
48
49 r, w, err := os.Pipe()
50 if err != nil {
51 t.Fatalf("os.Pipe: %v", err)
52 }
53
54 old := os.Stderr
55 os.Stderr = w
56
57 fn()
58
59 _ = w.Close()
60 os.Stderr = old
61
62 var buf bytes.Buffer
63
64 _, _ = io.Copy(&buf, r)
65
66 return buf.String()
67}
68
69func TestPrintJSON(t *testing.T) {
70 type payload struct {

Callers 1

TestPrintErrorFunction · 0.85

Calls 2

CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected