Skip to content

Commit

Permalink
fix tests running on Mac OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
golangcidev committed May 8, 2018
1 parent c04006d commit 8a62d15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
63 changes: 32 additions & 31 deletions revgrep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestChangesWriter(t *testing.T) {
// From a commit+unstaged, all changes should be shown
"8-unstaged": {"", []string{"main.go:6:", "main.go:7:"}, "HEAD~1", ""},
// From a commit+unstaged+untracked, all changes should be shown
"9-untracked": {"", []string{"main.go:6:", "main.go:7:", "main2.go:2:"}, "HEAD~1", ""},
"9-untracked": {"", []string{"main.go:6:", "main.go:7:", "main2.go:3:"}, "HEAD~1", ""},
// From a commit to last commit, all changes should be shown except recent unstaged, untracked
"10-committed": {"", []string{"main.go:6:"}, "HEAD~1", "HEAD~0"},
// static analysis tools with absolute paths should be handled
Expand All @@ -108,38 +108,39 @@ func TestChangesWriter(t *testing.T) {
}

for stage, test := range tests {
prevwd, sample := setup(t, stage, test.subdir)

reader := bytes.NewBuffer(sample)
var out bytes.Buffer

c := Checker{
RevisionFrom: test.revFrom,
RevisionTo: test.revTo,
}
_, err := c.Check(reader, &out)
if err != nil {
t.Errorf("%v: unexpected error: %v", stage, err)
}

scanner := bufio.NewScanner(&out)
var i int
for i = 0; scanner.Scan(); i++ {
// Rewrite abs paths to for simpler matching
line := rewriteAbs(scanner.Text())

if i > len(test.exp)-1 {
t.Errorf("%v: unexpected line: %q", stage, line)
} else {
if !strings.HasPrefix(line, test.exp[i]) {
t.Errorf("%v: line does not have prefix: %q line: %q", stage, test.exp[i], line)
t.Run(stage, func(t *testing.T) {
prevwd, sample := setup(t, stage, test.subdir)
reader := bytes.NewBuffer(sample)
var out bytes.Buffer

c := Checker{
RevisionFrom: test.revFrom,
RevisionTo: test.revTo,
}
_, err := c.Check(reader, &out)
if err != nil {
t.Errorf("%v: unexpected error: %v", stage, err)
}
scanner := bufio.NewScanner(&out)
var i int
for i = 0; scanner.Scan(); i++ {
// Rewrite abs paths to for simpler matching
line := rewriteAbs(scanner.Text())
line = strings.TrimPrefix(line, "./")

if i > len(test.exp)-1 {
t.Errorf("%v: unexpected line: %q", stage, line)
} else {
if !strings.HasPrefix(line, test.exp[i]) {
t.Errorf("%v: line does not have prefix: %q line: %q", stage, test.exp[i], line)
}
}
}
}
if i != len(test.exp) {
t.Errorf("%v: i %v, expected %v", stage, i, len(test.exp))
}
teardown(t, prevwd)
if i != len(test.exp) {
t.Errorf("%v: i %v, expected %v", stage, i, len(test.exp))
}
teardown(t, prevwd)
})
}
}

Expand Down
5 changes: 3 additions & 2 deletions testdata/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [[ "$(basename $(pwd))" != "testdata" ]]; then
fi

function close() {
go vet ./...
go tool vet .
exit 0
}

Expand Down Expand Up @@ -87,6 +87,7 @@ EOF

cat > main2.go <<EOF
package main
import "fmt"
var _ = fmt.Sprintf("9-untracked %s")
EOF

Expand All @@ -99,7 +100,7 @@ EOF
# Display absolute path

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

Expand Down

0 comments on commit 8a62d15

Please sign in to comment.