1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package analysisflags_test
15 "golang.org/x/tools/go/analysis"
16 "golang.org/x/tools/go/analysis/internal/analysisflags"
20 fmt.Println(analysisflags.Parse([]*analysis.Analyzer{
21 {Name: "a1", Doc: "a1"},
22 {Name: "a2", Doc: "a2"},
23 {Name: "a3", Doc: "a3"},
28 // This test fork/execs the main function above.
29 func TestExec(t *testing.T) {
30 if runtime.GOOS != "linux" {
31 t.Skipf("skipping fork/exec test on this platform")
34 progname := os.Args[0]
36 if os.Getenv("ANALYSISFLAGS_CHILD") == "1" {
38 os.Args = strings.Fields(progname + " " + os.Getenv("FLAGS"))
43 for _, test := range []struct {
51 {"-a1=1 -a3=1", "[a1 a3]"},
52 {"-a1=1 -a3=0", "[a1]"},
54 cmd := exec.Command(progname, "-test.run=TestExec")
55 cmd.Env = append(os.Environ(), "ANALYSISFLAGS_CHILD=1", "FLAGS="+test.flags)
57 output, err := cmd.CombinedOutput()
59 t.Fatalf("exec failed: %v; output=<<%s>>", err, output)
62 got := strings.TrimSpace(string(output))
64 t.Errorf("got %s, want %s", got, test.want)