@@ -524,32 +524,43 @@ func (tg *testgoData) wantArchive(path string) {
524
524
}
525
525
}
526
526
527
- // isStale returns whether pkg is stale.
528
- func (tg * testgoData ) isStale (pkg string ) bool {
529
- tg .run ("list" , "-f" , "{{.Stale}}" , pkg )
530
- switch v := strings .TrimSpace (tg .getStdout ()); v {
531
- case "true" :
532
- return true
533
- case "false" :
534
- return false
535
- default :
536
- tg .t .Fatalf ("unexpected output checking staleness of package %v: %v" , pkg , v )
537
- panic ("unreachable" )
527
+ // isStale reports whether pkg is stale, and why
528
+ func (tg * testgoData ) isStale (pkg string ) (bool , string ) {
529
+ tg .run ("list" , "-f" , "{{.Stale}}:{{.StaleReason}}" , pkg )
530
+ v := strings .TrimSpace (tg .getStdout ())
531
+ f := strings .SplitN (v , ":" , 2 )
532
+ if len (f ) == 2 {
533
+ switch f [0 ] {
534
+ case "true" :
535
+ return true , f [1 ]
536
+ case "false" :
537
+ return false , f [1 ]
538
+ }
538
539
}
540
+ tg .t .Fatalf ("unexpected output checking staleness of package %v: %v" , pkg , v )
541
+ panic ("unreachable" )
539
542
}
540
543
541
544
// wantStale fails with msg if pkg is not stale.
542
- func (tg * testgoData ) wantStale (pkg , msg string ) {
543
- if ! tg .isStale (pkg ) {
545
+ func (tg * testgoData ) wantStale (pkg , reason , msg string ) {
546
+ stale , why := tg .isStale (pkg )
547
+ if ! stale {
544
548
tg .t .Fatal (msg )
545
549
}
550
+ if reason == "" && why != "" || ! strings .Contains (why , reason ) {
551
+ tg .t .Errorf ("wrong reason for Stale=true: %q, want %q" , why , reason )
552
+ }
546
553
}
547
554
548
555
// wantNotStale fails with msg if pkg is stale.
549
- func (tg * testgoData ) wantNotStale (pkg , msg string ) {
550
- if tg .isStale (pkg ) {
556
+ func (tg * testgoData ) wantNotStale (pkg , reason , msg string ) {
557
+ stale , why := tg .isStale (pkg )
558
+ if stale {
551
559
tg .t .Fatal (msg )
552
560
}
561
+ if reason == "" && why != "" || ! strings .Contains (why , reason ) {
562
+ tg .t .Errorf ("wrong reason for Stale=false: %q, want %q" , why , reason )
563
+ }
553
564
}
554
565
555
566
// cleanup cleans up a test that runs testgo.
@@ -708,7 +719,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
708
719
tg .tempFile ("d1/src/p1/p1.go" , `package p1` )
709
720
tg .setenv ("GOPATH" , tg .path ("d1" ))
710
721
tg .run ("install" , "-a" , "p1" )
711
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale, incorrectly" )
722
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale, incorrectly" )
712
723
tg .sleep ()
713
724
714
725
// Changing mtime and content of runtime/internal/sys/sys.go
@@ -717,28 +728,28 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
717
728
sys := runtime .GOROOT () + "/src/runtime/internal/sys/sys.go"
718
729
restore := addNL (sys )
719
730
defer restore ()
720
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale, incorrectly, after updating runtime/internal/sys/sys.go" )
731
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale, incorrectly, after updating runtime/internal/sys/sys.go" )
721
732
restore ()
722
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale, incorrectly, after restoring runtime/internal/sys/sys.go" )
733
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale, incorrectly, after restoring runtime/internal/sys/sys.go" )
723
734
724
735
// But changing runtime/internal/sys/zversion.go should have an effect:
725
736
// that's how we tell when we flip from one release to another.
726
737
zversion := runtime .GOROOT () + "/src/runtime/internal/sys/zversion.go"
727
738
restore = addNL (zversion )
728
739
defer restore ()
729
- tg .wantStale ("p1" , "./testgo list claims p1 is NOT stale, incorrectly, after changing to new release" )
740
+ tg .wantStale ("p1" , "build ID mismatch" , " ./testgo list claims p1 is NOT stale, incorrectly, after changing to new release" )
730
741
restore ()
731
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale, incorrectly, after changing back to old release" )
742
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale, incorrectly, after changing back to old release" )
732
743
addNL (zversion )
733
- tg .wantStale ("p1" , "./testgo list claims p1 is NOT stale, incorrectly, after changing again to new release" )
744
+ tg .wantStale ("p1" , "build ID mismatch" , " ./testgo list claims p1 is NOT stale, incorrectly, after changing again to new release" )
734
745
tg .run ("install" , "p1" )
735
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale after building with new release" )
746
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale after building with new release" )
736
747
737
748
// Restore to "old" release.
738
749
restore ()
739
- tg .wantStale ("p1" , "./testgo list claims p1 is NOT stale, incorrectly, after changing to old release after new build" )
750
+ tg .wantStale ("p1" , "build ID mismatch" , " ./testgo list claims p1 is NOT stale, incorrectly, after changing to old release after new build" )
740
751
tg .run ("install" , "p1" )
741
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale after building with old release" )
752
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale after building with old release" )
742
753
743
754
// Everything is out of date. Rebuild to leave things in a better state.
744
755
tg .run ("install" , "std" )
@@ -821,8 +832,8 @@ func TestGoInstallRebuildsStalePackagesInOtherGOPATH(t *testing.T) {
821
832
sep := string (filepath .ListSeparator )
822
833
tg .setenv ("GOPATH" , tg .path ("d1" )+ sep + tg .path ("d2" ))
823
834
tg .run ("install" , "p1" )
824
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale, incorrectly" )
825
- tg .wantNotStale ("p2" , "./testgo list claims p2 is stale, incorrectly" )
835
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale, incorrectly" )
836
+ tg .wantNotStale ("p2" , "" , " ./testgo list claims p2 is stale, incorrectly" )
826
837
tg .sleep ()
827
838
if f , err := os .OpenFile (tg .path ("d2/src/p2/p2.go" ), os .O_WRONLY | os .O_APPEND , 0 ); err != nil {
828
839
t .Fatal (err )
@@ -831,12 +842,12 @@ func TestGoInstallRebuildsStalePackagesInOtherGOPATH(t *testing.T) {
831
842
} else {
832
843
tg .must (f .Close ())
833
844
}
834
- tg .wantStale ("p2" , "./testgo list claims p2 is NOT stale, incorrectly" )
835
- tg .wantStale ("p1" , "./testgo list claims p1 is NOT stale, incorrectly" )
845
+ tg .wantStale ("p2" , "newer source file" , " ./testgo list claims p2 is NOT stale, incorrectly" )
846
+ tg .wantStale ("p1" , "stale dependency" , " ./testgo list claims p1 is NOT stale, incorrectly" )
836
847
837
848
tg .run ("install" , "p1" )
838
- tg .wantNotStale ("p2" , "./testgo list claims p2 is stale after reinstall, incorrectly" )
839
- tg .wantNotStale ("p1" , "./testgo list claims p1 is stale after reinstall, incorrectly" )
849
+ tg .wantNotStale ("p2" , "" , " ./testgo list claims p2 is stale after reinstall, incorrectly" )
850
+ tg .wantNotStale ("p1" , "" , " ./testgo list claims p1 is stale after reinstall, incorrectly" )
840
851
}
841
852
842
853
func TestGoInstallDetectsRemovedFiles (t * testing.T ) {
@@ -850,13 +861,13 @@ func TestGoInstallDetectsRemovedFiles(t *testing.T) {
850
861
package mypkg` )
851
862
tg .setenv ("GOPATH" , tg .path ("." ))
852
863
tg .run ("install" , "mypkg" )
853
- tg .wantNotStale ("mypkg" , "./testgo list mypkg claims mypkg is stale, incorrectly" )
864
+ tg .wantNotStale ("mypkg" , "" , " ./testgo list mypkg claims mypkg is stale, incorrectly" )
854
865
// z.go was not part of the build; removing it is okay.
855
866
tg .must (os .Remove (tg .path ("src/mypkg/z.go" )))
856
- tg .wantNotStale ("mypkg" , "./testgo list mypkg claims mypkg is stale after removing z.go; should not be stale" )
867
+ tg .wantNotStale ("mypkg" , "" , " ./testgo list mypkg claims mypkg is stale after removing z.go; should not be stale" )
857
868
// y.go was part of the package; removing it should be detected.
858
869
tg .must (os .Remove (tg .path ("src/mypkg/y.go" )))
859
- tg .wantStale ("mypkg" , "./testgo list mypkg claims mypkg is NOT stale after removing y.go; should be stale" )
870
+ tg .wantStale ("mypkg" , "build ID mismatch" , " ./testgo list mypkg claims mypkg is NOT stale after removing y.go; should be stale" )
860
871
}
861
872
862
873
func TestWildcardMatchesSyntaxErrorDirs (t * testing.T ) {
@@ -919,13 +930,13 @@ func TestGoInstallDetectsRemovedFilesInPackageMain(t *testing.T) {
919
930
package main` )
920
931
tg .setenv ("GOPATH" , tg .path ("." ))
921
932
tg .run ("install" , "mycmd" )
922
- tg .wantNotStale ("mycmd" , "./testgo list mypkg claims mycmd is stale, incorrectly" )
933
+ tg .wantNotStale ("mycmd" , "" , " ./testgo list mypkg claims mycmd is stale, incorrectly" )
923
934
// z.go was not part of the build; removing it is okay.
924
935
tg .must (os .Remove (tg .path ("src/mycmd/z.go" )))
925
- tg .wantNotStale ("mycmd" , "./testgo list mycmd claims mycmd is stale after removing z.go; should not be stale" )
936
+ tg .wantNotStale ("mycmd" , "" , " ./testgo list mycmd claims mycmd is stale after removing z.go; should not be stale" )
926
937
// y.go was part of the package; removing it should be detected.
927
938
tg .must (os .Remove (tg .path ("src/mycmd/y.go" )))
928
- tg .wantStale ("mycmd" , "./testgo list mycmd claims mycmd is NOT stale after removing y.go; should be stale" )
939
+ tg .wantStale ("mycmd" , "build ID mismatch" , " ./testgo list mycmd claims mycmd is NOT stale after removing y.go; should be stale" )
929
940
}
930
941
931
942
func testLocalRun (tg * testgoData , exepath , local , match string ) {
@@ -1317,7 +1328,7 @@ func TestPackageMainTestImportsArchiveNotBinary(t *testing.T) {
1317
1328
tg .sleep ()
1318
1329
tg .run ("test" , "main_test" )
1319
1330
tg .run ("install" , "main_test" )
1320
- tg .wantNotStale ("main_test" , "after go install, main listed as stale" )
1331
+ tg .wantNotStale ("main_test" , "" , " after go install, main listed as stale" )
1321
1332
tg .run ("test" , "main_test" )
1322
1333
}
1323
1334
@@ -1327,9 +1338,9 @@ func TestPackageNotStaleWithTrailingSlash(t *testing.T) {
1327
1338
defer tg .cleanup ()
1328
1339
goroot := runtime .GOROOT ()
1329
1340
tg .setenv ("GOROOT" , goroot + "/" )
1330
- tg .wantNotStale ("runtime" , "with trailing slash in GOROOT, runtime listed as stale" )
1331
- tg .wantNotStale ("os" , "with trailing slash in GOROOT, os listed as stale" )
1332
- tg .wantNotStale ("io" , "with trailing slash in GOROOT, io listed as stale" )
1341
+ tg .wantNotStale ("runtime" , "" , " with trailing slash in GOROOT, runtime listed as stale" )
1342
+ tg .wantNotStale ("os" , "" , " with trailing slash in GOROOT, os listed as stale" )
1343
+ tg .wantNotStale ("io" , "" , " with trailing slash in GOROOT, io listed as stale" )
1333
1344
}
1334
1345
1335
1346
// With $GOBIN set, binaries get installed to $GOBIN.
0 commit comments