Skip to content

Commit 8a62d15

Browse files
committed
fix tests running on Mac OS X
1 parent c04006d commit 8a62d15

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

revgrep_test.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestChangesWriter(t *testing.T) {
9898
// From a commit+unstaged, all changes should be shown
9999
"8-unstaged": {"", []string{"main.go:6:", "main.go:7:"}, "HEAD~1", ""},
100100
// From a commit+unstaged+untracked, all changes should be shown
101-
"9-untracked": {"", []string{"main.go:6:", "main.go:7:", "main2.go:2:"}, "HEAD~1", ""},
101+
"9-untracked": {"", []string{"main.go:6:", "main.go:7:", "main2.go:3:"}, "HEAD~1", ""},
102102
// From a commit to last commit, all changes should be shown except recent unstaged, untracked
103103
"10-committed": {"", []string{"main.go:6:"}, "HEAD~1", "HEAD~0"},
104104
// static analysis tools with absolute paths should be handled
@@ -108,38 +108,39 @@ func TestChangesWriter(t *testing.T) {
108108
}
109109

110110
for stage, test := range tests {
111-
prevwd, sample := setup(t, stage, test.subdir)
112-
113-
reader := bytes.NewBuffer(sample)
114-
var out bytes.Buffer
115-
116-
c := Checker{
117-
RevisionFrom: test.revFrom,
118-
RevisionTo: test.revTo,
119-
}
120-
_, err := c.Check(reader, &out)
121-
if err != nil {
122-
t.Errorf("%v: unexpected error: %v", stage, err)
123-
}
124-
125-
scanner := bufio.NewScanner(&out)
126-
var i int
127-
for i = 0; scanner.Scan(); i++ {
128-
// Rewrite abs paths to for simpler matching
129-
line := rewriteAbs(scanner.Text())
130-
131-
if i > len(test.exp)-1 {
132-
t.Errorf("%v: unexpected line: %q", stage, line)
133-
} else {
134-
if !strings.HasPrefix(line, test.exp[i]) {
135-
t.Errorf("%v: line does not have prefix: %q line: %q", stage, test.exp[i], line)
111+
t.Run(stage, func(t *testing.T) {
112+
prevwd, sample := setup(t, stage, test.subdir)
113+
reader := bytes.NewBuffer(sample)
114+
var out bytes.Buffer
115+
116+
c := Checker{
117+
RevisionFrom: test.revFrom,
118+
RevisionTo: test.revTo,
119+
}
120+
_, err := c.Check(reader, &out)
121+
if err != nil {
122+
t.Errorf("%v: unexpected error: %v", stage, err)
123+
}
124+
scanner := bufio.NewScanner(&out)
125+
var i int
126+
for i = 0; scanner.Scan(); i++ {
127+
// Rewrite abs paths to for simpler matching
128+
line := rewriteAbs(scanner.Text())
129+
line = strings.TrimPrefix(line, "./")
130+
131+
if i > len(test.exp)-1 {
132+
t.Errorf("%v: unexpected line: %q", stage, line)
133+
} else {
134+
if !strings.HasPrefix(line, test.exp[i]) {
135+
t.Errorf("%v: line does not have prefix: %q line: %q", stage, test.exp[i], line)
136+
}
136137
}
137138
}
138-
}
139-
if i != len(test.exp) {
140-
t.Errorf("%v: i %v, expected %v", stage, i, len(test.exp))
141-
}
142-
teardown(t, prevwd)
139+
if i != len(test.exp) {
140+
t.Errorf("%v: i %v, expected %v", stage, i, len(test.exp))
141+
}
142+
teardown(t, prevwd)
143+
})
143144
}
144145
}
145146

testdata/make.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [[ "$(basename $(pwd))" != "testdata" ]]; then
77
fi
88

99
function close() {
10-
go vet ./...
10+
go tool vet .
1111
exit 0
1212
}
1313

@@ -87,6 +87,7 @@ EOF
8787

8888
cat > main2.go <<EOF
8989
package main
90+
import "fmt"
9091
var _ = fmt.Sprintf("9-untracked %s")
9192
EOF
9293

@@ -99,7 +100,7 @@ EOF
99100
# Display absolute path
100101

101102
if [[ "$1" == "11-abs-path" ]]; then
102-
go vet |& sed -r "s:(.*\.go):$(pwd)/\1:g"
103+
go tool vet . 2>&1 | sed -E "s:(.*\.go):$(pwd)/\1:g"
103104
exit
104105
fi
105106

0 commit comments

Comments
 (0)