go/analysis/internal/unitchecker: reenable integration test

Fixes golang/go#28676

Change-Id: I361a5d61fb6acc90ff8c0167651a45cb9a433472
Reviewed-on: https://go-review.googlesource.com/c/149697
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This commit is contained in:
Alan Donovan 2018-11-14 22:13:33 -05:00
parent 1a405fd27e
commit 5215be16cd
1 changed files with 32 additions and 26 deletions

View File

@ -15,6 +15,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
"strings"
"testing" "testing"
"golang.org/x/tools/go/analysis/analysistest" "golang.org/x/tools/go/analysis/analysistest"
@ -46,41 +47,46 @@ func main() {
// analysis with facts using unitchecker under "go vet". // analysis with facts using unitchecker under "go vet".
// It fork/execs the main function above. // It fork/execs the main function above.
func TestIntegration(t *testing.T) { func TestIntegration(t *testing.T) {
t.Skip("skipping broken test; golang.org/issue/28676")
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
t.Skipf("skipping fork/exec test on this platform") t.Skipf("skipping fork/exec test on this platform")
} }
testdata := analysistest.TestData() testdata := analysistest.TestData()
cmd := exec.Command("go", "vet", "-vettool="+os.Args[0], "-findcall.name=MyFunc123", "b") const wantA = `# a
cmd.Env = append(os.Environ(),
"UNITCHECKER_CHILD=1",
"GOPATH="+testdata,
)
out, err := cmd.CombinedOutput()
exitcode := -1
if exitErr, ok := err.(*exec.ExitError); ok {
exitcode = exitErr.ExitCode()
}
if exitcode != 2 {
t.Errorf("got exit code %d, want 2", exitcode)
}
want := `
# a
testdata/src/a/a.go:4:11: call of MyFunc123(...) testdata/src/a/a.go:4:11: call of MyFunc123(...)
# b `
const wantB = `# b
testdata/src/b/b.go:6:13: call of MyFunc123(...) testdata/src/b/b.go:6:13: call of MyFunc123(...)
testdata/src/b/b.go:7:11: call of MyFunc123(...) testdata/src/b/b.go:7:11: call of MyFunc123(...)
`[1:] `
if got := string(out); got != want {
t.Errorf("got <<%s>>, want <<%s>>", got, want)
}
if t.Failed() { for _, test := range []struct {
t.Logf("err=%v stderr=<<%s>", err, cmd.Stderr) args string
want string
}{
{args: "a", want: wantA},
{args: "b", want: wantB},
{args: "a b", want: wantA + wantB},
} {
cmd := exec.Command("go", "vet", "-vettool="+os.Args[0], "-findcall.name=MyFunc123")
cmd.Args = append(cmd.Args, strings.Fields(test.args)...)
cmd.Env = append(os.Environ(),
"UNITCHECKER_CHILD=1",
"GOPATH="+testdata,
)
out, err := cmd.CombinedOutput()
exitcode := -1
if exitErr, ok := err.(*exec.ExitError); ok {
exitcode = exitErr.ExitCode()
}
if exitcode != 2 {
t.Errorf("%s: got exit code %d, want 2", test.args, exitcode)
}
if got := string(out); got != test.want {
t.Errorf("%s: got <<%s>>, want <<%s>>", test.args, got, test.want)
}
} }
} }