-
Notifications
You must be signed in to change notification settings - Fork 140
/
test_test.go
58 lines (47 loc) · 1.26 KB
/
test_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
package sh_test
import (
"testing"
"github.com/codeskyblue/go-sh"
)
var s = sh.NewSession()
type T struct{ *testing.T }
func NewT(t *testing.T) *T {
return &T{t}
}
func (t *T) checkTest(exp string, arg string, result bool) {
r := s.Test(exp, arg)
if r != result {
t.Errorf("test -%s %s, %v != %v", exp, arg, r, result)
}
}
func TestTest(i *testing.T) {
t := NewT(i)
t.checkTest("d", "../go-sh", true)
t.checkTest("d", "./yymm", false)
// file test
t.checkTest("f", "testdata/hello.txt", true)
t.checkTest("f", "testdata/xxxxx", false)
t.checkTest("f", "testdata/yymm", false)
// link test
t.checkTest("link", "testdata/linkfile", true)
t.checkTest("link", "testdata/xxxxxlinkfile", false)
t.checkTest("link", "testdata/hello.txt", false)
// executable test
t.checkTest("x", "testdata/executable", true)
t.checkTest("x", "testdata/xxxxx", false)
t.checkTest("x", "testdata/hello.txt", false)
}
func ExampleShellTest(t *testing.T) {
// test -L
sh.Test("link", "testdata/linkfile")
sh.Test("L", "testdata/linkfile")
// test -f
sh.Test("file", "testdata/file")
sh.Test("f", "testdata/file")
// test -x
sh.Test("executable", "testdata/binfile")
sh.Test("x", "testdata/binfile")
// test -d
sh.Test("dir", "testdata/dir")
sh.Test("d", "testdata/dir")
}