-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathre_test.go
87 lines (63 loc) · 1.86 KB
/
re_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
package main
import (
"errors"
"reflect"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/AnuchitO/re/runner"
)
func TestSplitArguments(t *testing.T) {
t.Run("arguments have less than two element should be error", func(t *testing.T) {
args := []string{"re"}
_, _, err := splitCommand(args)
eErr := errors.New("you should add command after re [command], e.g. 're go test -v .'")
if eErr.Error() != err.Error() {
t.Errorf("expect error is '%v' but got '%v'", eErr, err)
}
})
t.Run("arguments should have two element at least", func(t *testing.T) {
args := []string{"re", "go"}
_, _, err := splitCommand(args)
if err != nil {
t.Errorf("expect with out any error but got %v", err)
}
})
t.Run("arguments should have two element at least", func(t *testing.T) {
args := []string{"re", "go"}
_, _, err := splitCommand(args)
if err != nil {
t.Errorf("expect with out any error but got %v", err)
}
})
t.Run("arguments index 1 should be command", func(t *testing.T) {
args := []string{"re", "go", "test", "-v", "."}
prog, _, _ := splitCommand(args)
if "go" != prog {
t.Errorf("expect prog is %q but got %q", "go", prog)
}
})
t.Run("arguments index 2 until the end should be params of the command", func(t *testing.T) {
args := []string{"re", "go", "test", "-v", "."}
_, params, _ := splitCommand(args)
eParams := []string{"test", "-v", "."}
if !reflect.DeepEqual(eParams, params) {
t.Errorf("expect params is %q but got %q", eParams, params)
}
})
}
func TestRerun(t *testing.T) {
t.Run("example testing", func(t *testing.T) {
task := runner.New("go", []string{"version"}...)
stop := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
time.AfterFunc(2*time.Second, func() {
close(stop)
})
run(".", task, stop, &wg)
wg.Wait()
assert.True(t, true, "should be pass")
})
}