From 43d3a2ca2ae9254f234e12d17ebdc2cf0921b495 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 4 Oct 2019 16:04:12 -0400 Subject: [PATCH] go/packages: update tests to reflect changes in golang.org/cl/198459 That change changes the name of an ad-hoc package go list produces to contain the names of the files instead of just being called "command-line-arguments". It also means go list will report multiple packages for an ad-hoc package that's not saved on disk that contains multiple sources. Update test cases that depend on this behavior. One thing to be aware of: the change in go list (without additional changes in go/packages) will break users depending on ad-hoc packages with multiple files, when the any of the files don't exist on disk. We're not adding a work-around in this cl because overlays aren't guaranteed to be 100% correct and the LSP doesn't need this functionality. If this turns out to be a problem we can fix it. Change-Id: I342cd3cb54bf35992186ee02ddd9ac316ff1db4f Reviewed-on: https://go-review.googlesource.com/c/tools/+/199097 Run-TryBot: Michael Matloob TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- go/packages/packages_test.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 4d10d4162b..e5a1b52077 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -2039,8 +2039,8 @@ func testErrorMissingFile(t *testing.T, exporter packagestest.Exporter) { if len(pkgs) == 0 && runtime.GOOS == "windows" { t.Skip("Issue #31344: the ad-hoc command-line-arguments package isn't created on windows") } - if len(pkgs) != 1 || pkgs[0].PkgPath != "command-line-arguments" { - t.Fatalf("packages.Load: want [command-line-arguments], got %v", pkgs) + if len(pkgs) != 1 || (pkgs[0].PkgPath != "command-line-arguments" && pkgs[0].PkgPath != "missing.go") { + t.Fatalf("packages.Load: want [command-line-arguments] or [missing.go], got %v", pkgs) } if len(pkgs[0].Errors) == 0 { t.Errorf("result of Load: want package with errors, got none: %+v", pkgs[0]) @@ -2062,25 +2062,17 @@ func testReturnErrorWhenUsingNonGoFiles(t *testing.T, exporter packagestest.Expo }}}) defer exported.Cleanup() config := packages.Config{Env: append(os.Environ(), "GOPACKAGESDRIVER=off")} - want := "named files must be .go files" - pkgs, err := packages.Load(&config, "a/a.go", "b/b.c") + pkgs, err := packages.Load(&config, "b/b.c") if err != nil { - // Check if the error returned is the one we expected. - if !strings.Contains(err.Error(), want) { - t.Fatalf("want error message: %s, got: %s", want, err.Error()) - } return } - if len(pkgs) != 1 || pkgs[0].PkgPath != "command-line-arguments" { - t.Fatalf("packages.Load: want [command-line-arguments], got %v", pkgs) + // Go <1.14 calls the package command-line-arguments while Go 1.14+ uses the file names. + if len(pkgs) != 1 || (pkgs[0].PkgPath != "command-line-arguments" && pkgs[0].PkgPath != "b/b.c") { + t.Fatalf("packages.Load: want [command-line-arguments] or [b/b.c], got %v", pkgs) } if len(pkgs[0].Errors) != 1 { t.Fatalf("result of Load: want package with one error, got: %+v", pkgs[0]) } - got := pkgs[0].Errors[0].Error() - if !strings.Contains(got, want) { - t.Fatalf("want error message: %s, got: %s", want, got) - } } func TestReturnErrorWhenUsingGoFilesInMultipleDirectories(t *testing.T) {