]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert some generate tests to the script framework
authorMichael Matloob <matloob@golang.org>
Mon, 6 Jan 2020 18:30:37 +0000 (13:30 -0500)
committerMichael Matloob <matloob@golang.org>
Wed, 19 Feb 2020 20:40:36 +0000 (20:40 +0000)
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I7110e460e18542aff90a7ae078b996ec45816d81
Reviewed-on: https://go-review.googlesource.com/c/go/+/213424
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/generate/test1.go [deleted file]
src/cmd/go/testdata/generate/test2.go [deleted file]
src/cmd/go/testdata/generate/test3.go [deleted file]
src/cmd/go/testdata/generate/test4.go [deleted file]
src/cmd/go/testdata/script/generate.txt [new file with mode: 0644]
src/cmd/go/testdata/script/generate_env.txt [new file with mode: 0644]

index 67b94860d28bbf629ce29f2d5c026b9fc4c6859b..eea833ec0176856a727c4988da493a6d9fcca21c 100644 (file)
@@ -2428,82 +2428,6 @@ func TestGoTestBuildsAnXtestContainingOnlyNonRunnableExamples(t *testing.T) {
        tg.grepStdout("File with non-runnable example was built.", "file with non-runnable example was not built")
 }
 
-func TestGoGenerateHandlesSimpleCommand(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("skipping because windows has no echo command")
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("generate", "./testdata/generate/test1.go")
-       tg.grepStdout("Success", "go generate ./testdata/generate/test1.go generated wrong output")
-}
-
-func TestGoGenerateHandlesCommandAlias(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("skipping because windows has no echo command")
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("generate", "./testdata/generate/test2.go")
-       tg.grepStdout("Now is the time for all good men", "go generate ./testdata/generate/test2.go generated wrong output")
-}
-
-func TestGoGenerateVariableSubstitution(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("skipping because windows has no echo command")
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("generate", "./testdata/generate/test3.go")
-       tg.grepStdout(runtime.GOARCH+" test3.go:7 pabc xyzp/test3.go/123", "go generate ./testdata/generate/test3.go generated wrong output")
-}
-
-func TestGoGenerateRunFlag(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("skipping because windows has no echo command")
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("generate", "-run", "y.s", "./testdata/generate/test4.go")
-       tg.grepStdout("yes", "go generate -run yes ./testdata/generate/test4.go did not select yes")
-       tg.grepStdoutNot("no", "go generate -run yes ./testdata/generate/test4.go selected no")
-}
-
-func TestGoGenerateEnv(t *testing.T) {
-       switch runtime.GOOS {
-       case "plan9", "windows":
-               t.Skipf("skipping because %s does not have the env command", runtime.GOOS)
-       }
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.parallel()
-       tg.tempFile("env.go", "package main\n\n//go:generate env")
-       tg.run("generate", tg.path("env.go"))
-       for _, v := range []string{"GOARCH", "GOOS", "GOFILE", "GOLINE", "GOPACKAGE", "DOLLAR"} {
-               tg.grepStdout("^"+v+"=", "go generate environment missing "+v)
-       }
-}
-
-func TestGoGenerateXTestPkgName(t *testing.T) {
-       if runtime.GOOS == "windows" {
-               t.Skip("skipping because windows has no echo command")
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.parallel()
-       tg.tempFile("env_test.go", "package main_test\n\n//go:generate echo $GOPACKAGE")
-       tg.run("generate", tg.path("env_test.go"))
-       want := "main_test"
-       if got := strings.TrimSpace(tg.getStdout()); got != want {
-               t.Errorf("go generate in XTest file got package name %q; want %q", got, want)
-       }
-}
-
 func TestGoGetCustomDomainWildcard(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
        testenv.MustHaveExecPath(t, "git")
diff --git a/src/cmd/go/testdata/generate/test1.go b/src/cmd/go/testdata/generate/test1.go
deleted file mode 100644 (file)
index 168cfb7..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Simple test for go generate.
-
-// We include a build tag that go generate should ignore.
-
-// +build ignore
-
-//go:generate echo Success
-
-package p
diff --git a/src/cmd/go/testdata/generate/test2.go b/src/cmd/go/testdata/generate/test2.go
deleted file mode 100644 (file)
index 829244a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Test that go generate handles command aliases.
-
-//go:generate -command run echo Now is the time
-//go:generate run for all good men
-
-package p
diff --git a/src/cmd/go/testdata/generate/test3.go b/src/cmd/go/testdata/generate/test3.go
deleted file mode 100644 (file)
index e950da5..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Test go generate variable substitution.
-
-//go:generate echo $GOARCH $GOFILE:$GOLINE ${GOPACKAGE}abc xyz$GOPACKAGE/$GOFILE/123
-
-package p
diff --git a/src/cmd/go/testdata/generate/test4.go b/src/cmd/go/testdata/generate/test4.go
deleted file mode 100644 (file)
index 6dae048..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Test -run flag
-
-//go:generate echo oh yes my man
-//go:generate echo no, no, a thousand times no
-
-package p
diff --git a/src/cmd/go/testdata/script/generate.txt b/src/cmd/go/testdata/script/generate.txt
new file mode 100644 (file)
index 0000000..c3c563e
--- /dev/null
@@ -0,0 +1,91 @@
+[short] skip
+
+# Install an echo command because Windows doesn't have it.
+env GOBIN=$WORK/tmp/bin
+go install echo.go
+env PATH=$GOBIN${:}$PATH
+
+# Test go generate handles a simple command
+go generate ./generate/simple.go
+stdout 'Success'
+
+# Test go generate handles a command alias
+go generate './generate/alias.go'
+stdout 'Now is the time for all good men'
+
+# Test go generate's variable substitution
+go generate './generate/substitution.go'
+stdout $GOARCH' substitution.go:7 pabc xyzp/substitution.go/123'
+
+# Test go generate's run flag
+go generate -run y.s './generate/flag.go'
+stdout 'yes' # flag.go should select yes
+! stdout 'no' # flag.go should not select no
+
+# Test go generate provides the right "$GOPACKAGE" name in an x_test
+go generate './generate/env_test.go'
+stdout 'main_test'
+
+-- echo.go --
+package main
+
+import (
+       "fmt"
+       "os"
+       "strings"
+)
+
+func main() {
+       fmt.Println(strings.Join(os.Args[1:], " "))
+       fmt.Println()
+}
+-- generate/simple.go --
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Simple test for go generate.
+
+// We include a build tag that go generate should ignore.
+
+// +build ignore
+
+//go:generate echo Success
+
+package p
+-- generate/alias.go --
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that go generate handles command aliases.
+
+//go:generate -command run echo Now is the time
+//go:generate run for all good men
+
+package p
+-- generate/substitution.go --
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test go generate variable substitution.
+
+//go:generate echo $GOARCH $GOFILE:$GOLINE ${GOPACKAGE}abc xyz$GOPACKAGE/$GOFILE/123
+
+package p
+-- generate/flag.go --
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test -run flag
+
+//go:generate echo oh yes my man
+//go:generate echo no, no, a thousand times no
+
+package p
+-- generate/env_test.go --
+package main_test
+
+//go:generate echo $GOPACKAGE
\ No newline at end of file
diff --git a/src/cmd/go/testdata/script/generate_env.txt b/src/cmd/go/testdata/script/generate_env.txt
new file mode 100644 (file)
index 0000000..0d3693f
--- /dev/null
@@ -0,0 +1,31 @@
+# Install an env command because Windows and plan9 don't have it.
+env GOBIN=$WORK/tmp/bin
+go install env.go
+env PATH=$GOBIN${:}$PATH
+
+# Test generators have access to the environment
+go generate ./printenv.go
+stdout '^GOARCH='$GOARCH
+stdout '^GOOS='$GOOS
+stdout '^GOFILE='
+stdout '^GOLINE='
+stdout '^GOPACKAGE='
+stdout '^DOLLAR='
+
+-- env.go --
+package main
+
+import (
+       "fmt"
+       "os"
+)
+
+func main() {
+       for _, v := range os.Environ() {
+               fmt.Println(v)
+       }
+}
+-- printenv.go --
+package main
+
+//go:generate env
\ No newline at end of file