-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.go
99 lines (76 loc) · 1.72 KB
/
run_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package run_test
import (
"fmt"
"github.com/rwxrob/run-go"
)
func ExampleExecAll() {
err, n := run.ExecAll(run.Cmds{{`ls`, `-d`, `/tmp`}, {`true`}, {`echo`, `wow`}})
fmt.Println(err, n)
// Output:
// /tmp
// wow
// <nil> 2
}
func ExampleExecAll_mid_Fail() {
err, n := run.ExecAll(run.Cmds{{`ls`, `-d`, `/tmp`}, {`false`}, {`echo`, `it works`}})
fmt.Println(err, n)
// Output:
// /tmp
// exit status 1 1
}
func ExampleExecAll_first_Fail() {
err, n := run.ExecAll(run.Cmds{{`ls`, `notme`}, {`true`}, {`echo`, `it works`}})
fmt.Println(err, n)
// Output:
// exit status 2 0
}
func ExampleExecAll_last_Fail() {
err, n := run.ExecAll(run.Cmds{{`ls`, `-d`, `/tmp`}, {`true`}, {`ls`, `bork`}})
fmt.Println(err, n)
// Output:
// /tmp
// exit status 2 2
}
func ExampleOutErr() {
out, err := run.OutErr(`ls`, `-d`, `/tmp`)
fmt.Printf("%q %v", out, err)
// Output:
// "/tmp\n" <nil>
}
func ExampleOutErr_with_Error() {
out, err := run.OutErr(`ls`, `-d`, `/nopenothear`)
fmt.Printf("%q %v", out, err)
// Output:
// "" exit status 2
}
func ExampleOut() {
out := run.Out(`ls`, `-d`, `/tmp`)
fmt.Printf("%q", out)
// Output:
// "/tmp\n"
}
func ExampleOut_with_Error() {
out := run.Out(`ls`, `-d`, `/nopenothear`)
// note the output to stderr
fmt.Printf("%q", out)
// Output:
// ""
}
func ExampleOutQuiet() {
out := run.OutQuiet(`ls`, `-d`, `/tmp`)
fmt.Printf("%q", out)
// Output:
// "/tmp\n"
}
func ExampleOutQuiet_with_Error() {
out := run.OutQuiet(`ls`, `-d`, `/nopenothear`)
fmt.Printf("%q", out)
// Output:
// ""
}
func ExampleOutAll() {
buf, err, n := run.OutAll(run.Cmds{{`ls`, `-d`, `/tmp`}, {`true`}, {`echo`, `wow`}})
fmt.Printf("%q %v %v", buf, err, n)
// Output:
// "/tmp\nwow\n" <nil> 2
}