1
0
mirror of https://github.com/golang/go synced 2024-11-07 13:26:10 -07:00

cmd/go: make TestNewReleaseRebuildsStalePackagesInGOPATH pass again

The test TestNewReleaseRebuildsStalePackagesInGOPATH is not run in
short mode, so people tend to not notice when it fails. It was failing
due to the build cache. Make it pass again by 1) changing it to modify
the package in a way visible to the compiler, so that the change is
not hidden by caching; 2) accepting "not installed but available in
build cache" as always being a valid reason for a stale package, as go
list does not try to figure out an underlying reason for why a package
is stale when it finds it in the build cache but not installed.

Updates #24436

Change-Id: Iaeaa298f153451ec913a653dd4e6da79a33055bb
Reviewed-on: https://go-review.googlesource.com/123815
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Ian Lance Taylor 2018-07-13 09:57:17 -07:00
parent 3fcfb1f573
commit b323709a5c

View File

@ -751,7 +751,11 @@ func (tg *testgoData) wantStale(pkg, reason, msg string) {
if !stale { if !stale {
tg.t.Fatal(msg) tg.t.Fatal(msg)
} }
if reason == "" && why != "" || !strings.Contains(why, reason) { // We always accept the reason as being "not installed but
// available in build cache", because when that is the case go
// list doesn't try to sort out the underlying reason why the
// package is not installed.
if reason == "" && why != "" || !strings.Contains(why, reason) && !strings.Contains(why, "not installed but available in build cache") {
tg.t.Errorf("wrong reason for Stale=true: %q, want %q", why, reason) tg.t.Errorf("wrong reason for Stale=true: %q, want %q", why, reason)
} }
} }
@ -881,13 +885,13 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
addNL := func(name string) (restore func()) { addVar := func(name string, idx int) (restore func()) {
data, err := ioutil.ReadFile(name) data, err := ioutil.ReadFile(name)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
old := data old := data
data = append(data, '\n') data = append(data, fmt.Sprintf("var DummyUnusedVar%d bool\n", idx)...)
if err := ioutil.WriteFile(name, append(data, '\n'), 0666); err != nil { if err := ioutil.WriteFile(name, append(data, '\n'), 0666); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -911,19 +915,19 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
// In fact this should be true even outside a release branch. // In fact this should be true even outside a release branch.
sys := runtime.GOROOT() + "/src/runtime/internal/sys/sys.go" sys := runtime.GOROOT() + "/src/runtime/internal/sys/sys.go"
tg.sleep() tg.sleep()
restore := addNL(sys) restore := addVar(sys, 0)
restore() restore()
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after updating mtime of runtime/internal/sys/sys.go") tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after updating mtime of runtime/internal/sys/sys.go")
// But changing content of any file should have an effect. // But changing content of any file should have an effect.
// Previously zversion.go was the only one that mattered; // Previously zversion.go was the only one that mattered;
// now they all matter, so keep using sys.go. // now they all matter, so keep using sys.go.
restore = addNL(sys) restore = addVar(sys, 1)
defer restore() defer restore()
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go") tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go")
restore() restore()
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release") tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release")
addNL(sys) addVar(sys, 2)
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again") tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
tg.run("install", "-i", "p1") tg.run("install", "-i", "p1")
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release") tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")