case "linux", "darwin", "freebsd", "windows":
// The race detector doesn't work on Alpine Linux:
// golang.org/issue/14481
- canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux()
+ canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux() && runtime.Compiler != "gccgo"
}
}
// Don't let these environment variables confuse the test.
stdout, stderr bytes.Buffer
}
+// skipIfGccgo skips the test if using gccgo.
+func skipIfGccgo(t *testing.T, msg string) {
+ if runtime.Compiler == "gccgo" {
+ t.Skipf("skipping test not supported on gccgo: %s", msg)
+ }
+}
+
// testgo sets up for a test that runs testgo.
func testgo(t *testing.T) *testgoData {
t.Helper()
}
func TestProgramNameInCrashMessages(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not use cmd/link")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
}
func TestGoListStandard(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not have GOROOT")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestInternalPackagesInGOROOTAreRespected(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not have GOROOT")
tg := testgo(t)
defer tg.cleanup()
tg.runFail("build", "-v", "./testdata/testinternal")
tg.tempFile("src/p1/p1.go", "package main\n")
tg.tempFile("src/p1/p1_test.go", "package main\nimport \"testing\"\nfunc Test(t *testing.T){}\n")
tg.run("test", "-c", "-n", "p1")
- tg.grepBothNot(`[\\/]compile.* -p main.*p1\.go`, "should not have run compile -p main p1.go")
- tg.grepStderr(`[\\/]compile.* -p p1.*p1\.go`, "should have run compile -p p1 p1.go")
+ tg.grepBothNot(`([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go`, "should not have run compile -p main p1.go")
+ tg.grepStderr(`([\\/]compile|gccgo).* (-p p1|-fgo-pkgpath=p1).*p1\.go`, "should have run compile -p p1 p1.go")
}
// The runtime version string takes one of two forms:
// Issue 12690
func TestPackageNotStaleWithTrailingSlash(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not have GOROOT")
tg := testgo(t)
defer tg.cleanup()
}
func TestGoListCmdOnlyShowsCommands(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not have GOROOT")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestLdflagsArgumentsWithSpacesIssue3941(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not support -ldflags -X")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoTestCpuprofileLeavesBinaryBehind(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoTestMutexprofileLeavesBinaryBehind(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoTestMutexprofileDashOControlsBinaryLocation(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoTestDashCDashOControlsBinaryLocation(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoTestDashIDashOWritesBinary(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestShadowingLogic(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tg := testgo(t)
defer tg.cleanup()
pwd := tg.pwd()
// "go test -c" should also appear to write a new binary every time,
// even if it's really just updating the mtime on an existing up-to-date binary.
func TestIssue6480(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
}
func TestGoInstallPkgdir(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
}
func TestGoBuildOutput(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
func TestLinkXImportPathEscape(t *testing.T) {
// golang.org/issue/16710
+ skipIfGccgo(t, "gccgo does not support -ldflags -X")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
// Issue 18225.
// This is really a cmd/asm issue but this is a convenient place to test it.
func TestConcurrentAsm(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not use cmd/asm")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
// Issue 19198.
// This is really a cmd/link issue but this is a convenient place to test it.
func TestDuplicateGlobalAsmSymbols(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not use cmd/asm")
tooSlow(t)
if runtime.GOARCH != "386" && runtime.GOARCH != "amd64" {
t.Skipf("skipping test on %s", runtime.GOARCH)
}
func TestBuildTagsNoComma(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
}
func TestExecutableGOROOT(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no GOROOT")
if runtime.GOOS == "openbsd" {
t.Skipf("test case does not work on %s, missing os.Executable", runtime.GOOS)
}
}
func TestNeedVersion(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not use cmd/compile")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
// Test that user can override default code generation flags.
func TestUserOverrideFlags(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not use -gcflags")
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
if testing.Short() && testenv.Builder() == "" {
t.Skipf("skipping in -short mode on non-builder")
}
- if runtime.Compiler == "gccgo" {
- t.Skipf("skipping test because buildmode=pie is not supported on gccgo")
- }
platform := fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
switch platform {
}
func TestWrongGOOSErrorBeforeLoadError(t *testing.T) {
+ skipIfGccgo(t, "gccgo assumes cross-compilation is always possible")
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.setenv("GOPATH", tg.tempdir)
tg.setenv("GOCACHE", tg.path("cache"))
- // timeout here should not affect result being cached
- // or being retrieved later.
- tg.run("test", "-x", "-timeout=10s", "errors")
- tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler")
- tg.grepStderr(`[\\/]link|gccgo`, "did not run linker")
- tg.grepStderr(`errors\.test`, "did not run test")
+ if runtime.Compiler != "gccgo" {
+ // timeout here should not affect result being cached
+ // or being retrieved later.
+ tg.run("test", "-x", "-timeout=10s", "errors")
+ tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler")
+ tg.grepStderr(`[\\/]link|gccgo`, "did not run linker")
+ tg.grepStderr(`errors\.test`, "did not run test")
- tg.run("test", "-x", "errors")
- tg.grepStdout(`ok \terrors\t\(cached\)`, "did not report cached result")
- tg.grepStderrNot(`[\\/]compile|gccgo`, "incorrectly ran compiler")
- tg.grepStderrNot(`[\\/]link|gccgo`, "incorrectly ran linker")
- tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
- tg.grepStderrNot("DO NOT USE", "poisoned action status leaked")
+ tg.run("test", "-x", "errors")
+ tg.grepStdout(`ok \terrors\t\(cached\)`, "did not report cached result")
+ tg.grepStderrNot(`[\\/]compile|gccgo`, "incorrectly ran compiler")
+ tg.grepStderrNot(`[\\/]link|gccgo`, "incorrectly ran linker")
+ tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
+ tg.grepStderrNot("DO NOT USE", "poisoned action status leaked")
- // Even very low timeouts do not disqualify cached entries.
- tg.run("test", "-timeout=1ns", "-x", "errors")
- tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
+ // Even very low timeouts do not disqualify cached entries.
+ tg.run("test", "-timeout=1ns", "-x", "errors")
+ tg.grepStderrNot(`errors\.test`, "incorrectly ran test")
- tg.run("clean", "-testcache")
- tg.run("test", "-x", "errors")
- tg.grepStderr(`errors\.test`, "did not run test")
+ tg.run("clean", "-testcache")
+ tg.run("test", "-x", "errors")
+ tg.grepStderr(`errors\.test`, "did not run test")
+ }
// The -p=1 in the commands below just makes the -x output easier to read.
tg.grepStdout(`ok \tt/t2\t\(cached\)`, "did not cache t2")
tg.grepStdout(`ok \tt/t3\t\(cached\)`, "did not cache t3")
tg.grepStdout(`ok \tt/t4\t\(cached\)`, "did not cache t4")
- tg.grepStderrNot(`[\\/]compile|gccgo`, "incorrectly ran compiler")
- tg.grepStderrNot(`[\\/]link|gccgo`, "incorrectly ran linker")
+ tg.grepStderrNot(`[\\/](compile|gccgo) `, "incorrectly ran compiler")
+ tg.grepStderrNot(`[\\/](link|gccgo) `, "incorrectly ran linker")
tg.grepStderrNot(`p[0-9]\.test`, "incorrectly ran test")
t.Log("\n\nCOMMENT\n\n")
tg.grepStdout(`ok \tt/t2\t\(cached\)`, "did not cache t2")
tg.grepStdout(`ok \tt/t3\t\(cached\)`, "did not cache t3")
tg.grepStdout(`ok \tt/t4\t\(cached\)`, "did not cache t4")
- tg.grepStderrNot(`([\\/]compile|gccgo).*t[0-9]_test\.go`, "incorrectly ran compiler")
- tg.grepStderrNot(`[\\/]link|gccgo`, "incorrectly ran linker")
+ tg.grepStderrNot(`([\\/](compile|gccgo) ).*t[0-9]_test\.go`, "incorrectly ran compiler")
+ tg.grepStderrNot(`[\\/](link|gccgo) `, "incorrectly ran linker")
tg.grepStderrNot(`t[0-9]\.test.*test\.short`, "incorrectly ran test")
t.Log("\n\nCHANGE\n\n")
// so the test should not have been rerun.
tg.grepStderr(`([\\/]compile|gccgo).*t2_test.go`, "did not recompile t2")
tg.grepStderr(`([\\/]link|gccgo).*t2\.test`, "did not relink t2_test")
- tg.grepStdout(`ok \tt/t2\t\(cached\)`, "did not cache t/t2")
+ // This check does not currently work with gccgo, as garbage
+ // collection of unused variables is not turned on by default.
+ if runtime.Compiler != "gccgo" {
+ tg.grepStdout(`ok \tt/t2\t\(cached\)`, "did not cache t/t2")
+ }
// t3 imports p1, and changing X changes t3's test binary.
tg.grepStderr(`([\\/]compile|gccgo).*t3_test.go`, "did not recompile t3")
// and not rerun.
tg.grepStderrNot(`([\\/]compile|gccgo).*t4_test.go`, "incorrectly recompiled t4")
tg.grepStderr(`([\\/]link|gccgo).*t4\.test`, "did not relink t4_test")
- tg.grepStdout(`ok \tt/t4\t\(cached\)`, "did not cache t/t4")
+ // This check does not currently work with gccgo, as garbage
+ // collection of unused variables is not turned on by default.
+ if runtime.Compiler != "gccgo" {
+ tg.grepStdout(`ok \tt/t4\t\(cached\)`, "did not cache t/t4")
+ }
}
func TestTestCacheInputs(t *testing.T) {
}
func TestGcflagsPatterns(t *testing.T) {
+ skipIfGccgo(t, "gccgo has no standard packages")
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", "")
}
func TestGoTestJSON(t *testing.T) {
+ skipIfGccgo(t, "gccgo does not have standard packages")
tooSlow(t)
tg := testgo(t)
tg.grepStderr("invalid input file name \"-y.go\"", "did not reject -y.go")
tg.must(os.Remove(tg.path("src/x/-y.go")))
- tg.runFail("build", "-gcflags=all=@x", "x")
+ if runtime.Compiler == "gccgo" {
+ tg.runFail("build", "-gccgoflags=all=@x", "x")
+ } else {
+ tg.runFail("build", "-gcflags=all=@x", "x")
+ }
tg.grepStderr("invalid command-line argument @x in command", "did not reject @x during exec")
tg.tempFile("src/@x/x.go", "package x\n")
tg.tempFile("src/x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
- tg.tempFile("src/x/x.go", `package x
+ if runtime.Compiler == "gc" {
+ tg.tempFile("src/x/x.go", `package x
- //go:cgo_ldflag "-fplugin=foo.so"
+ //go:cgo_ldflag "-fplugin=foo.so"
- import "C"
- `)
- tg.runFail("build", "x")
- tg.grepStderr("//go:cgo_ldflag .* only allowed in cgo-generated code", "did not reject //go:cgo_ldflag directive")
+ import "C"
+ `)
+ tg.runFail("build", "x")
+ tg.grepStderr("//go:cgo_ldflag .* only allowed in cgo-generated code", "did not reject //go:cgo_ldflag directive")
+ }
tg.must(os.Remove(tg.path("src/x/x.go")))
tg.runFail("build", "x")
tg.runFail("build", "x")
tg.grepStderr("no Go files", "did not report missing source code") // _* files are ignored...
- tg.runFail("build", tg.path("src/x/_cgo_yy.go")) // ... but if forced, the comment is rejected
- // Actually, today there is a separate issue that _ files named
- // on the command-line are ignored. Once that is fixed,
- // we want to see the cgo_ldflag error.
- tg.grepStderr("//go:cgo_ldflag only allowed in cgo-generated code|no Go files", "did not reject //go:cgo_ldflag directive")
+ if runtime.Compiler == "gc" {
+ tg.runFail("build", tg.path("src/x/_cgo_yy.go")) // ... but if forced, the comment is rejected
+ // Actually, today there is a separate issue that _ files named
+ // on the command-line are ignored. Once that is fixed,
+ // we want to see the cgo_ldflag error.
+ tg.grepStderr("//go:cgo_ldflag only allowed in cgo-generated code|no Go files", "did not reject //go:cgo_ldflag directive")
+ }
+
tg.must(os.Remove(tg.path("src/x/_cgo_yy.go")))
tg.tempFile("src/x/x.go", "package x\n")