-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc.go
40 lines (30 loc) · 980 Bytes
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Package fakeio is a small library to fake stdout/stderr/stdin mainly for
unit testing.
Following example fakes stdout/stderr/stdin. Set 'from stdin!' as stdin and get
output from both stdout and stderr as string.
f := fakeio.Stdout().Stderr().Stdin("from stdin!")
fromInput, err := bufio.NewReader(os.Stdin).ReadString('!')
if err != nil {
f.Restore()
panic(err)
}
fmt.Println("from stdout!")
fmt.Fprintln(os.Stderr, "from stderr!")
fromOutput, err := f.String()
if err != nil {
f.Restore()
panic(err)
}
// 'defer' is better, but here it's unavailable due to output test
f.Restore()
// Output: from stdin!
fmt.Println(fromInput)
// Output:
// from stdout!
// from stderr!
fmt.Println(fromOutput)
Please read example/example_test.go to see live examples.
If you find some bugs, please report it to repository page: https://github.com/rhysd/go-fakeio
*/
package fakeio