MCPcopy
hub / github.com/spf13/pflag / parseReturnStderr

Function parseReturnStderr

flag_test.go:1156–1176  ·  view source on GitHub ↗
(t *testing.T, f *FlagSet, args []string)

Source from the content-addressed store, hash-verified

1154}
1155
1156func parseReturnStderr(t *testing.T, f *FlagSet, args []string) (string, error) {
1157 oldStderr := os.Stderr
1158 r, w, _ := os.Pipe()
1159 os.Stderr = w
1160
1161 err := f.Parse(args)
1162
1163 outC := make(chan string)
1164 // copy the output in a separate goroutine so printing can't block indefinitely
1165 go func() {
1166 var buf bytes.Buffer
1167 io.Copy(&buf, r)
1168 outC <- buf.String()
1169 }()
1170
1171 w.Close()
1172 os.Stderr = oldStderr
1173 out := <-outC
1174
1175 return out, err
1176}
1177
1178func TestDeprecatedFlagUsage(t *testing.T) {
1179 f := NewFlagSet("bob", ContinueOnError)

Callers 4

TestDeprecatedFlagUsageFunction · 0.85
TestHiddenFlagUsageFunction · 0.85

Calls 2

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected