mirror of https://github.com/golang/go.git
cmd/go: convert some generate tests to the script framework
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>
This commit is contained in:
parent
2200b4fda2
commit
f74e21c150
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue