diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-07-01 16:21:39 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-07-09 19:50:55 +0000 |
commit | e33c0f29343b9eb40ed8cf4df39b73c2db31729b (patch) | |
tree | 275f5e95811f0a5eec5b988b2ef55b44fb4b3eff /go/packages/packages_test.go | |
parent | 8e32e9f144bc0fca3fc5c250127f11a540c06345 (diff) | |
download | golang-x-tools-e33c0f29343b9eb40ed8cf4df39b73c2db31729b.tar.gz |
go/packages: skip tests that link binaries in short mode
These tests together account for about 1s of running time on my
workstation. I expect that they are even slower on platforms that
require external linking, and likely more memory-intensive than most
of the other tests.
For golang/go#46764
Change-Id: Ic9607ac71bcfd617581c58cfffe3775e23cd3422
Reviewed-on: https://go-review.googlesource.com/c/tools/+/332351
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Diffstat (limited to 'go/packages/packages_test.go')
-rw-r--r-- | go/packages/packages_test.go | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 61cd38471..6549fd610 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -54,9 +54,15 @@ func TestMain(m *testing.M) { os.Exit(m.Run()) } -// testAllOrModules tests f against all packagestest exporters in long mode, -// but only against the Modules exporter in short mode. -func testAllOrModules(t *testing.T, f func(*testing.T, packagestest.Exporter)) { +func skipIfShort(t *testing.T, reason string) { + if testing.Short() { + t.Skipf("skipping slow test in short mode: %s", reason) + } +} + +// testAllOrModulesParallel tests f, in parallel, against all packagestest +// exporters in long mode, but only against the Modules exporter in short mode. +func testAllOrModulesParallel(t *testing.T, f func(*testing.T, packagestest.Exporter)) { t.Parallel() packagestest.TestAll(t, func(t *testing.T, exporter packagestest.Exporter) { t.Helper() @@ -116,7 +122,7 @@ func TestLoadZeroConfig(t *testing.T) { } } -func TestLoadImportsGraph(t *testing.T) { testAllOrModules(t, testLoadImportsGraph) } +func TestLoadImportsGraph(t *testing.T) { testAllOrModulesParallel(t, testLoadImportsGraph) } func testLoadImportsGraph(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -290,7 +296,9 @@ func testLoadImportsGraph(t *testing.T, exporter packagestest.Exporter) { } } -func TestLoadImportsTestVariants(t *testing.T) { testAllOrModules(t, testLoadImportsTestVariants) } +func TestLoadImportsTestVariants(t *testing.T) { + testAllOrModulesParallel(t, testLoadImportsTestVariants) +} func testLoadImportsTestVariants(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -422,7 +430,7 @@ func imports(p *packages.Package) []string { return keys } -func TestConfigDir(t *testing.T) { testAllOrModules(t, testConfigDir) } +func TestConfigDir(t *testing.T) { testAllOrModulesParallel(t, testConfigDir) } func testConfigDir(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -485,7 +493,7 @@ func testConfigDir(t *testing.T, exporter packagestest.Exporter) { } } -func TestConfigFlags(t *testing.T) { testAllOrModules(t, testConfigFlags) } +func TestConfigFlags(t *testing.T) { testAllOrModulesParallel(t, testConfigFlags) } func testConfigFlags(t *testing.T, exporter packagestest.Exporter) { // Test satisfying +build line tags, with -tags flag. exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -546,7 +554,7 @@ package b`, } } -func TestLoadTypes(t *testing.T) { testAllOrModules(t, testLoadTypes) } +func TestLoadTypes(t *testing.T) { testAllOrModulesParallel(t, testLoadTypes) } func testLoadTypes(t *testing.T, exporter packagestest.Exporter) { // In LoadTypes and LoadSyntax modes, the compiler will // fail to generate an export data file for c, because it has @@ -604,7 +612,7 @@ func testLoadTypes(t *testing.T, exporter packagestest.Exporter) { // TestLoadTypesBits is equivalent to TestLoadTypes except that it only requests // the types using the NeedTypes bit. -func TestLoadTypesBits(t *testing.T) { testAllOrModules(t, testLoadTypesBits) } +func TestLoadTypesBits(t *testing.T) { testAllOrModulesParallel(t, testLoadTypesBits) } func testLoadTypesBits(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -680,7 +688,7 @@ func testLoadTypesBits(t *testing.T, exporter packagestest.Exporter) { } } -func TestLoadSyntaxOK(t *testing.T) { testAllOrModules(t, testLoadSyntaxOK) } +func TestLoadSyntaxOK(t *testing.T) { testAllOrModulesParallel(t, testLoadSyntaxOK) } func testLoadSyntaxOK(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -770,7 +778,7 @@ func testLoadSyntaxOK(t *testing.T, exporter packagestest.Exporter) { } } -func TestLoadDiamondTypes(t *testing.T) { testAllOrModules(t, testLoadDiamondTypes) } +func TestLoadDiamondTypes(t *testing.T) { testAllOrModulesParallel(t, testLoadDiamondTypes) } func testLoadDiamondTypes(t *testing.T, exporter packagestest.Exporter) { // We make a diamond dependency and check the type d.D is the same through both paths exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -810,7 +818,7 @@ func testLoadDiamondTypes(t *testing.T, exporter packagestest.Exporter) { } } -func TestLoadSyntaxError(t *testing.T) { testAllOrModules(t, testLoadSyntaxError) } +func TestLoadSyntaxError(t *testing.T) { testAllOrModulesParallel(t, testLoadSyntaxError) } func testLoadSyntaxError(t *testing.T, exporter packagestest.Exporter) { // A type error in a lower-level package (e) prevents go list // from producing export data for all packages that depend on it @@ -886,7 +894,7 @@ func testLoadSyntaxError(t *testing.T, exporter packagestest.Exporter) { // This function tests use of the ParseFile hook to modify // the AST after parsing. -func TestParseFileModifyAST(t *testing.T) { testAllOrModules(t, testParseFileModifyAST) } +func TestParseFileModifyAST(t *testing.T) { testAllOrModulesParallel(t, testParseFileModifyAST) } func testParseFileModifyAST(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -968,7 +976,7 @@ const A = 1 } func TestLoadAllSyntaxImportErrors(t *testing.T) { - testAllOrModules(t, testLoadAllSyntaxImportErrors) + testAllOrModulesParallel(t, testLoadAllSyntaxImportErrors) } func testLoadAllSyntaxImportErrors(t *testing.T, exporter packagestest.Exporter) { // TODO(matloob): Remove this once go list -e -compiled is fixed. @@ -1053,7 +1061,7 @@ import ( } } -func TestAbsoluteFilenames(t *testing.T) { testAllOrModules(t, testAbsoluteFilenames) } +func TestAbsoluteFilenames(t *testing.T) { testAllOrModulesParallel(t, testAbsoluteFilenames) } func testAbsoluteFilenames(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1132,7 +1140,7 @@ func testAbsoluteFilenames(t *testing.T, exporter packagestest.Exporter) { } } -func TestContains(t *testing.T) { testAllOrModules(t, testContains) } +func TestContains(t *testing.T) { testAllOrModulesParallel(t, testContains) } func testContains(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1164,7 +1172,7 @@ func testContains(t *testing.T, exporter packagestest.Exporter) { // application determines the Sizes function used by the type checker. // This behavior is a stop-gap until we make the build system's query // tool report the correct sizes function for the actual configuration. -func TestSizes(t *testing.T) { testAllOrModules(t, testSizes) } +func TestSizes(t *testing.T) { testAllOrModulesParallel(t, testSizes) } func testSizes(t *testing.T, exporter packagestest.Exporter) { // Only run this test on operating systems that have both an amd64 and 386 port. switch runtime.GOOS { @@ -1201,7 +1209,9 @@ func testSizes(t *testing.T, exporter packagestest.Exporter) { // TestContainsFallbackSticks ensures that when there are both contains and non-contains queries // the decision whether to fallback to the pre-1.11 go list sticks across both sets of calls to // go list. -func TestContainsFallbackSticks(t *testing.T) { testAllOrModules(t, testContainsFallbackSticks) } +func TestContainsFallbackSticks(t *testing.T) { + testAllOrModulesParallel(t, testContainsFallbackSticks) +} func testContainsFallbackSticks(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1234,7 +1244,7 @@ func testContainsFallbackSticks(t *testing.T, exporter packagestest.Exporter) { // Test that Load with no patterns is equivalent to loading "." via the golist // driver. -func TestNoPatterns(t *testing.T) { testAllOrModules(t, testNoPatterns) } +func TestNoPatterns(t *testing.T) { testAllOrModulesParallel(t, testNoPatterns) } func testNoPatterns(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1256,7 +1266,7 @@ func testNoPatterns(t *testing.T, exporter packagestest.Exporter) { } } -func TestJSON(t *testing.T) { testAllOrModules(t, testJSON) } +func TestJSON(t *testing.T) { testAllOrModulesParallel(t, testJSON) } func testJSON(t *testing.T, exporter packagestest.Exporter) { //TODO: add in some errors exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1424,7 +1434,7 @@ func TestRejectInvalidQueries(t *testing.T) { } } -func TestPatternPassthrough(t *testing.T) { testAllOrModules(t, testPatternPassthrough) } +func TestPatternPassthrough(t *testing.T) { testAllOrModulesParallel(t, testPatternPassthrough) } func testPatternPassthrough(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1560,7 +1570,7 @@ EOF // list. This would then cause a nil pointer crash. // This bug was triggered by the simple package layout below, and thus this // test will make sure the bug remains fixed. -func TestBasicXTest(t *testing.T) { testAllOrModules(t, testBasicXTest) } +func TestBasicXTest(t *testing.T) { testAllOrModulesParallel(t, testBasicXTest) } func testBasicXTest(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1578,7 +1588,7 @@ func testBasicXTest(t *testing.T, exporter packagestest.Exporter) { } } -func TestErrorMissingFile(t *testing.T) { testAllOrModules(t, testErrorMissingFile) } +func TestErrorMissingFile(t *testing.T) { testAllOrModulesParallel(t, testErrorMissingFile) } func testErrorMissingFile(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1605,7 +1615,7 @@ func testErrorMissingFile(t *testing.T, exporter packagestest.Exporter) { } func TestReturnErrorWhenUsingNonGoFiles(t *testing.T) { - testAllOrModules(t, testReturnErrorWhenUsingNonGoFiles) + testAllOrModulesParallel(t, testReturnErrorWhenUsingNonGoFiles) } func testReturnErrorWhenUsingNonGoFiles(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1633,7 +1643,7 @@ func testReturnErrorWhenUsingNonGoFiles(t *testing.T, exporter packagestest.Expo } func TestReturnErrorWhenUsingGoFilesInMultipleDirectories(t *testing.T) { - testAllOrModules(t, testReturnErrorWhenUsingGoFilesInMultipleDirectories) + testAllOrModulesParallel(t, testReturnErrorWhenUsingGoFilesInMultipleDirectories) } func testReturnErrorWhenUsingGoFilesInMultipleDirectories(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1665,7 +1675,7 @@ func testReturnErrorWhenUsingGoFilesInMultipleDirectories(t *testing.T, exporter } func TestReturnErrorForUnexpectedDirectoryLayout(t *testing.T) { - testAllOrModules(t, testReturnErrorForUnexpectedDirectoryLayout) + testAllOrModulesParallel(t, testReturnErrorForUnexpectedDirectoryLayout) } func testReturnErrorForUnexpectedDirectoryLayout(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1695,7 +1705,7 @@ func testReturnErrorForUnexpectedDirectoryLayout(t *testing.T, exporter packages } } -func TestMissingDependency(t *testing.T) { testAllOrModules(t, testMissingDependency) } +func TestMissingDependency(t *testing.T) { testAllOrModulesParallel(t, testMissingDependency) } func testMissingDependency(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1717,7 +1727,7 @@ func testMissingDependency(t *testing.T, exporter packagestest.Exporter) { } } -func TestAdHocContains(t *testing.T) { testAllOrModules(t, testAdHocContains) } +func TestAdHocContains(t *testing.T) { testAllOrModulesParallel(t, testAdHocContains) } func testAdHocContains(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -1759,7 +1769,7 @@ func testAdHocContains(t *testing.T, exporter packagestest.Exporter) { } } -func TestCgoNoCcompiler(t *testing.T) { testAllOrModules(t, testCgoNoCcompiler) } +func TestCgoNoCcompiler(t *testing.T) { testAllOrModulesParallel(t, testCgoNoCcompiler) } func testCgoNoCcompiler(t *testing.T, exporter packagestest.Exporter) { testenv.NeedsTool(t, "cgo") exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1793,7 +1803,7 @@ const A = http.MethodGet } } -func TestCgoMissingFile(t *testing.T) { testAllOrModules(t, testCgoMissingFile) } +func TestCgoMissingFile(t *testing.T) { testAllOrModulesParallel(t, testCgoMissingFile) } func testCgoMissingFile(t *testing.T, exporter packagestest.Exporter) { testenv.NeedsTool(t, "cgo") exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1880,7 +1890,7 @@ func TestLoadImportsC(t *testing.T) { } func TestCgoNoSyntax(t *testing.T) { - testAllOrModules(t, testCgoNoSyntax) + testAllOrModulesParallel(t, testCgoNoSyntax) } func testCgoNoSyntax(t *testing.T, exporter packagestest.Exporter) { testenv.NeedsTool(t, "cgo") @@ -1922,9 +1932,10 @@ func testCgoNoSyntax(t *testing.T, exporter packagestest.Exporter) { } func TestCgoBadPkgConfig(t *testing.T) { - testAllOrModules(t, testCgoBadPkgConfig) + testAllOrModulesParallel(t, testCgoBadPkgConfig) } func testCgoBadPkgConfig(t *testing.T, exporter packagestest.Exporter) { + skipIfShort(t, "builds and links a fake pkgconfig binary") testenv.NeedsTool(t, "cgo") exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -1994,7 +2005,7 @@ func main() { return tmpdir } -func TestIssue32814(t *testing.T) { testAllOrModules(t, testIssue32814) } +func TestIssue32814(t *testing.T) { testAllOrModulesParallel(t, testIssue32814) } func testIssue32814(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ Name: "golang.org/fake", @@ -2022,7 +2033,7 @@ func testIssue32814(t *testing.T, exporter packagestest.Exporter) { } func TestLoadTypesInfoWithoutNeedDeps(t *testing.T) { - testAllOrModules(t, testLoadTypesInfoWithoutNeedDeps) + testAllOrModulesParallel(t, testLoadTypesInfoWithoutNeedDeps) } func testLoadTypesInfoWithoutNeedDeps(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2049,7 +2060,7 @@ func testLoadTypesInfoWithoutNeedDeps(t *testing.T, exporter packagestest.Export } func TestLoadWithNeedDeps(t *testing.T) { - testAllOrModules(t, testLoadWithNeedDeps) + testAllOrModulesParallel(t, testLoadWithNeedDeps) } func testLoadWithNeedDeps(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2093,7 +2104,7 @@ func testLoadWithNeedDeps(t *testing.T, exporter packagestest.Exporter) { } func TestImpliedLoadMode(t *testing.T) { - testAllOrModules(t, testImpliedLoadMode) + testAllOrModulesParallel(t, testImpliedLoadMode) } func testImpliedLoadMode(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2131,7 +2142,7 @@ func testImpliedLoadMode(t *testing.T, exporter packagestest.Exporter) { } func TestIssue35331(t *testing.T) { - testAllOrModules(t, testIssue35331) + testAllOrModulesParallel(t, testIssue35331) } func testIssue35331(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2161,7 +2172,7 @@ func testIssue35331(t *testing.T, exporter packagestest.Exporter) { } func TestMultiplePackageVersionsIssue36188(t *testing.T) { - testAllOrModules(t, testMultiplePackageVersionsIssue36188) + testAllOrModulesParallel(t, testMultiplePackageVersionsIssue36188) } func testMultiplePackageVersionsIssue36188(t *testing.T, exporter packagestest.Exporter) { @@ -2270,7 +2281,7 @@ func TestLoadModeStrings(t *testing.T) { } func TestCycleImportStack(t *testing.T) { - testAllOrModules(t, testCycleImportStack) + testAllOrModulesParallel(t, testCycleImportStack) } func testCycleImportStack(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2300,7 +2311,7 @@ func testCycleImportStack(t *testing.T, exporter packagestest.Exporter) { } func TestForTestField(t *testing.T) { - testAllOrModules(t, testForTestField) + testAllOrModulesParallel(t, testForTestField) } func testForTestField(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2346,7 +2357,7 @@ func testForTestField(t *testing.T, exporter packagestest.Exporter) { } func TestIssue37529(t *testing.T) { - testAllOrModules(t, testIssue37529) + testAllOrModulesParallel(t, testIssue37529) } func testIssue37529(t *testing.T, exporter packagestest.Exporter) { // Tests #37529. When automatic vendoring is triggered, and we try to determine @@ -2386,7 +2397,7 @@ func testIssue37529(t *testing.T, exporter packagestest.Exporter) { } } -func TestIssue37098(t *testing.T) { testAllOrModules(t, testIssue37098) } +func TestIssue37098(t *testing.T) { testAllOrModulesParallel(t, testIssue37098) } func testIssue37098(t *testing.T, exporter packagestest.Exporter) { // packages.Load should only return Go sources in // (*Package).CompiledGoFiles. This tests #37098, where using SWIG to @@ -2450,7 +2461,7 @@ func testIssue37098(t *testing.T, exporter packagestest.Exporter) { } // TestInvalidFilesInXTest checks the fix for golang/go#37971 in Go 1.15. -func TestInvalidFilesInXTest(t *testing.T) { testAllOrModules(t, testInvalidFilesInXTest) } +func TestInvalidFilesInXTest(t *testing.T) { testAllOrModulesParallel(t, testInvalidFilesInXTest) } func testInvalidFilesInXTest(t *testing.T, exporter packagestest.Exporter) { testenv.NeedsGo1Point(t, 15) exported := packagestest.Export(t, exporter, []packagestest.Module{ @@ -2477,7 +2488,7 @@ func testInvalidFilesInXTest(t *testing.T, exporter packagestest.Exporter) { } } -func TestTypecheckCgo(t *testing.T) { testAllOrModules(t, testTypecheckCgo) } +func TestTypecheckCgo(t *testing.T) { testAllOrModulesParallel(t, testTypecheckCgo) } func testTypecheckCgo(t *testing.T, exporter packagestest.Exporter) { testenv.NeedsGo1Point(t, 15) testenv.NeedsTool(t, "cgo") @@ -2520,7 +2531,7 @@ func testTypecheckCgo(t *testing.T, exporter packagestest.Exporter) { } func TestModule(t *testing.T) { - testAllOrModules(t, testModule) + testAllOrModulesParallel(t, testModule) } func testModule(t *testing.T, exporter packagestest.Exporter) { exported := packagestest.Export(t, exporter, []packagestest.Module{{ @@ -2560,9 +2571,10 @@ func testModule(t *testing.T, exporter packagestest.Exporter) { } func TestExternal_NotHandled(t *testing.T) { - testAllOrModules(t, testExternal_NotHandled) + testAllOrModulesParallel(t, testExternal_NotHandled) } func testExternal_NotHandled(t *testing.T, exporter packagestest.Exporter) { + skipIfShort(t, "builds and links fake driver binaries") testenv.NeedsGoBuild(t) tempdir, err := ioutil.TempDir("", "testexternal") @@ -2646,7 +2658,7 @@ func main() { } func TestInvalidPackageName(t *testing.T) { - testAllOrModules(t, testInvalidPackageName) + testAllOrModulesParallel(t, testInvalidPackageName) } func testInvalidPackageName(t *testing.T, exporter packagestest.Exporter) { |