From 5215be16cde3bead50519b4e7dd444c15c042b86 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 14 Nov 2018 22:13:33 -0500 Subject: [PATCH] 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 Run-TryBot: Michael Matloob --- go/analysis/unitchecker/unitchecker_test.go | 58 ++++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/go/analysis/unitchecker/unitchecker_test.go b/go/analysis/unitchecker/unitchecker_test.go index 3b8d2370..c6bb2bf6 100644 --- a/go/analysis/unitchecker/unitchecker_test.go +++ b/go/analysis/unitchecker/unitchecker_test.go @@ -15,6 +15,7 @@ import ( "os" "os/exec" "runtime" + "strings" "testing" "golang.org/x/tools/go/analysis/analysistest" @@ -46,41 +47,46 @@ func main() { // analysis with facts using unitchecker under "go vet". // It fork/execs the main function above. func TestIntegration(t *testing.T) { - t.Skip("skipping broken test; golang.org/issue/28676") - if runtime.GOOS != "linux" { t.Skipf("skipping fork/exec test on this platform") } testdata := analysistest.TestData() - cmd := exec.Command("go", "vet", "-vettool="+os.Args[0], "-findcall.name=MyFunc123", "b") - 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 + const wantA = `# a 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:7:11: call of MyFunc123(...) -`[1:] - if got := string(out); got != want { - t.Errorf("got <<%s>>, want <<%s>>", got, want) - } +` - if t.Failed() { - t.Logf("err=%v stderr=<<%s>", err, cmd.Stderr) + for _, test := range []struct { + 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) + } } }