Skip to content

Commit b323709

Browse files
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í <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 3fcfb1f commit b323709

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cmd/go/go_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,11 @@ func (tg *testgoData) wantStale(pkg, reason, msg string) {
751751
if !stale {
752752
tg.t.Fatal(msg)
753753
}
754-
if reason == "" && why != "" || !strings.Contains(why, reason) {
754+
// We always accept the reason as being "not installed but
755+
// available in build cache", because when that is the case go
756+
// list doesn't try to sort out the underlying reason why the
757+
// package is not installed.
758+
if reason == "" && why != "" || !strings.Contains(why, reason) && !strings.Contains(why, "not installed but available in build cache") {
755759
tg.t.Errorf("wrong reason for Stale=true: %q, want %q", why, reason)
756760
}
757761
}
@@ -881,13 +885,13 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
881885
tg := testgo(t)
882886
defer tg.cleanup()
883887

884-
addNL := func(name string) (restore func()) {
888+
addVar := func(name string, idx int) (restore func()) {
885889
data, err := ioutil.ReadFile(name)
886890
if err != nil {
887891
t.Fatal(err)
888892
}
889893
old := data
890-
data = append(data, '\n')
894+
data = append(data, fmt.Sprintf("var DummyUnusedVar%d bool\n", idx)...)
891895
if err := ioutil.WriteFile(name, append(data, '\n'), 0666); err != nil {
892896
t.Fatal(err)
893897
}
@@ -911,19 +915,19 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
911915
// In fact this should be true even outside a release branch.
912916
sys := runtime.GOROOT() + "/src/runtime/internal/sys/sys.go"
913917
tg.sleep()
914-
restore := addNL(sys)
918+
restore := addVar(sys, 0)
915919
restore()
916920
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after updating mtime of runtime/internal/sys/sys.go")
917921

918922
// But changing content of any file should have an effect.
919923
// Previously zversion.go was the only one that mattered;
920924
// now they all matter, so keep using sys.go.
921-
restore = addNL(sys)
925+
restore = addVar(sys, 1)
922926
defer restore()
923927
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go")
924928
restore()
925929
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release")
926-
addNL(sys)
930+
addVar(sys, 2)
927931
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
928932
tg.run("install", "-i", "p1")
929933
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")

0 commit comments

Comments
 (0)