...
1 package sh_test
2
3 import (
4 "testing"
5
6 "github.com/codeskyblue/go-sh"
7 )
8
9 var s = sh.NewSession()
10
11 type T struct{ *testing.T }
12
13 func NewT(t *testing.T) *T {
14 return &T{t}
15 }
16
17 func (t *T) checkTest(exp string, arg string, result bool) {
18 r := s.Test(exp, arg)
19 if r != result {
20 t.Errorf("test -%s %s, %v != %v", exp, arg, r, result)
21 }
22 }
23
24 func TestTest(i *testing.T) {
25 t := NewT(i)
26 t.checkTest("d", "../go-sh", true)
27 t.checkTest("d", "./yymm", false)
28
29
30 t.checkTest("f", "testdata/hello.txt", true)
31 t.checkTest("f", "testdata/xxxxx", false)
32 t.checkTest("f", "testdata/yymm", false)
33
34
35 t.checkTest("link", "testdata/linkfile", true)
36 t.checkTest("link", "testdata/xxxxxlinkfile", false)
37 t.checkTest("link", "testdata/hello.txt", false)
38
39
40 t.checkTest("x", "testdata/executable", true)
41 t.checkTest("x", "testdata/xxxxx", false)
42 t.checkTest("x", "testdata/hello.txt", false)
43 }
44
45 func ExampleShellTest(t *testing.T) {
46
47 sh.Test("link", "testdata/linkfile")
48 sh.Test("L", "testdata/linkfile")
49
50 sh.Test("file", "testdata/file")
51 sh.Test("f", "testdata/file")
52
53 sh.Test("executable", "testdata/binfile")
54 sh.Test("x", "testdata/binfile")
55
56 sh.Test("dir", "testdata/dir")
57 sh.Test("d", "testdata/dir")
58 }
59
View as plain text