mirror of
https://github.com/golang/go
synced 2024-11-07 13:46:19 -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:
parent
3fcfb1f573
commit
b323709a5c
@ -751,7 +751,11 @@ func (tg *testgoData) wantStale(pkg, reason, msg string) {
|
||||
if !stale {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -881,13 +885,13 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
|
||||
addNL := func(name string) (restore func()) {
|
||||
addVar := func(name string, idx int) (restore func()) {
|
||||
data, err := ioutil.ReadFile(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -911,19 +915,19 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
|
||||
// In fact this should be true even outside a release branch.
|
||||
sys := runtime.GOROOT() + "/src/runtime/internal/sys/sys.go"
|
||||
tg.sleep()
|
||||
restore := addNL(sys)
|
||||
restore := addVar(sys, 0)
|
||||
restore()
|
||||
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.
|
||||
// Previously zversion.go was the only one that mattered;
|
||||
// now they all matter, so keep using sys.go.
|
||||
restore = addNL(sys)
|
||||
restore = addVar(sys, 1)
|
||||
defer restore()
|
||||
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go")
|
||||
restore()
|
||||
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.run("install", "-i", "p1")
|
||||
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")
|
||||
|
Loading…
Reference in New Issue
Block a user