MCPcopy Create free account
hub / github.com/JordanCoin/codemap / withStdinInput

Function withStdinInput

cmd/hooks_more_test.go:97–116  ·  view source on GitHub ↗
(t *testing.T, input string, fn func())

Source from the content-addressed store, hash-verified

95}
96
97func withStdinInput(t *testing.T, input string, fn func()) {
98 t.Helper()
99
100 old := os.Stdin
101 r, w, err := os.Pipe()
102 if err != nil {
103 t.Fatal(err)
104 }
105 if _, err := io.WriteString(w, input); err != nil {
106 t.Fatal(err)
107 }
108 _ = w.Close()
109 os.Stdin = r
110 defer func() {
111 os.Stdin = old
112 _ = r.Close()
113 }()
114
115 fn()
116}
117
118func mustJSONInput(t *testing.T, v any) string {
119 t.Helper()

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected