-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff_test.go
67 lines (62 loc) · 1.29 KB
/
diff_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
package reviewdog
import (
"context"
"os"
"os/exec"
"strings"
"sync"
"testing"
)
func TestDiffString(t *testing.T) {
difftext := `diff --git a/golint.old.go b/golint.new.go
index 34cacb9..a727dd3 100644
--- a/golint.old.go
+++ b/golint.new.go
@@ -2,6 +2,12 @@ package test
var V int
+var NewError1 int
+
// invalid func comment
func F() {
}
+
+// invalid func comment2
+func F2() {
+}
`
d := NewDiffString(difftext, 1)
b, err := d.Diff(context.Background())
if err != nil {
t.Error(err)
}
got := string(b)
if got != difftext {
t.Errorf("got:\n%v\nwant:\n%v", got, difftext)
}
}
func TestDiffCmd(t *testing.T) {
wantb, err := os.ReadFile("./diff/testdata/golint.diff")
if err != nil {
t.Fatal(err)
}
want := strings.SplitN(string(wantb), "\n", 5)[4] // strip extended header
cmd := exec.Command("git", "diff", "--no-index", "./diff/testdata/golint.old.go", "./diff/testdata/golint.new.go")
d := NewDiffCmd(cmd, 1)
// ensure it supports multiple use
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
wg.Add(1)
go func() {
defer wg.Done()
b, err := d.Diff(context.Background())
if err != nil {
t.Error(string(b), err)
}
got := strings.SplitN(string(b), "\n", 5)[4]
if got != want {
t.Errorf("got:\n%v\nwant:\n%v", got, want)
}
}()
}
wg.Wait()
}