@@ -2479,7 +2479,7 @@ func TestCoveragePattern(t *testing.T) {
2479
2479
// (as opposed to pattern matching on deps)
2480
2480
// then it will try to load sleepybad, which does not compile,
2481
2481
// and the test command will fail.
2482
- tg .run ("test" , "-coverprofile=" + filepath . Join ( tg .tempdir , "cover.out" ), "-coverpkg=sleepy..." , "-run=^$" , "sleepy1" )
2482
+ tg .run ("test" , "-coverprofile=" + tg .path ( "cover.out" ), "-coverpkg=sleepy..." , "-run=^$" , "sleepy1" )
2483
2483
}
2484
2484
2485
2485
func TestCoverageErrorLine (t * testing.T ) {
@@ -2530,7 +2530,7 @@ func TestCoverageFunc(t *testing.T) {
2530
2530
tg .setenv ("GOPATH" , filepath .Join (tg .pwd (), "testdata" ))
2531
2531
2532
2532
tg .run ("test" , "-outputdir=" + tg .tempdir , "-coverprofile=cover.out" , "coverasm" )
2533
- tg .run ("tool" , "cover" , "-func=" + filepath . Join ( tg .tempdir , "cover.out" ))
2533
+ tg .run ("tool" , "cover" , "-func=" + tg .path ( "cover.out" ))
2534
2534
tg .grepStdout (`\tg\t*100.0%` , "did not find g 100% covered" )
2535
2535
tg .grepStdoutNot (`\tf\t*[0-9]` , "reported coverage for assembly function f" )
2536
2536
}
@@ -4344,7 +4344,7 @@ func main() {
4344
4344
}
4345
4345
` )
4346
4346
tg .setenv ("GOPATH" , tg .path ("go" ))
4347
- exe := filepath . Join ( tg .tempdir , "p.exe" )
4347
+ exe := tg .path ( "p.exe" )
4348
4348
tg .creatingTemp (exe )
4349
4349
tg .run ("build" , "-o" , exe , "p" )
4350
4350
}
@@ -4958,7 +4958,7 @@ func TestCacheCoverage(t *testing.T) {
4958
4958
tg .setenv ("GOPATH" , filepath .Join (tg .pwd (), "testdata" ))
4959
4959
tg .makeTempdir ()
4960
4960
4961
- tg .setenv ("GOCACHE" , filepath . Join ( tg .tempdir , "c1" ))
4961
+ tg .setenv ("GOCACHE" , tg .path ( "c1" ))
4962
4962
tg .run ("test" , "-cover" , "strings" )
4963
4963
tg .run ("test" , "-cover" , "math" , "strings" )
4964
4964
}
@@ -4987,12 +4987,12 @@ func TestIssue22531(t *testing.T) {
4987
4987
tg .parallel ()
4988
4988
tg .makeTempdir ()
4989
4989
tg .setenv ("GOPATH" , tg .tempdir )
4990
- tg .setenv ("GOCACHE" , filepath . Join ( tg .tempdir , "cache" ))
4990
+ tg .setenv ("GOCACHE" , tg .path ( "cache" ))
4991
4991
tg .tempFile ("src/m/main.go" , "package main /* c1 */; func main() {}\n " )
4992
4992
tg .run ("install" , "-x" , "m" )
4993
4993
tg .run ("list" , "-f" , "{{.Stale}}" , "m" )
4994
4994
tg .grepStdout ("false" , "reported m as stale after install" )
4995
- tg .run ("tool" , "buildid" , filepath . Join ( tg .tempdir , "bin/m" + exeSuffix ))
4995
+ tg .run ("tool" , "buildid" , tg .path ( "bin/m" + exeSuffix ))
4996
4996
4997
4997
// The link action ID did not include the full main build ID,
4998
4998
// even though the full main build ID is written into the
@@ -5003,7 +5003,7 @@ func TestIssue22531(t *testing.T) {
5003
5003
tg .run ("install" , "-x" , "m" )
5004
5004
tg .run ("list" , "-f" , "{{.Stale}}" , "m" )
5005
5005
tg .grepStdout ("false" , "reported m as stale after reinstall" )
5006
- tg .run ("tool" , "buildid" , filepath . Join ( tg .tempdir , "bin/m" + exeSuffix ))
5006
+ tg .run ("tool" , "buildid" , tg .path ( "bin/m" + exeSuffix ))
5007
5007
}
5008
5008
5009
5009
func TestIssue22596 (t * testing.T ) {
@@ -5014,17 +5014,17 @@ func TestIssue22596(t *testing.T) {
5014
5014
defer tg .cleanup ()
5015
5015
tg .parallel ()
5016
5016
tg .makeTempdir ()
5017
- tg .setenv ("GOCACHE" , filepath . Join ( tg .tempdir , "cache" ))
5017
+ tg .setenv ("GOCACHE" , tg .path ( "cache" ))
5018
5018
tg .tempFile ("gopath1/src/p/p.go" , "package p; func F(){}\n " )
5019
5019
tg .tempFile ("gopath2/src/p/p.go" , "package p; func F(){}\n " )
5020
5020
5021
- tg .setenv ("GOPATH" , filepath . Join ( tg .tempdir , "gopath1" ))
5021
+ tg .setenv ("GOPATH" , tg .path ( "gopath1" ))
5022
5022
tg .run ("list" , "-f={{.Target}}" , "p" )
5023
5023
target1 := strings .TrimSpace (tg .getStdout ())
5024
5024
tg .run ("install" , "p" )
5025
5025
tg .wantNotStale ("p" , "" , "p stale after install" )
5026
5026
5027
- tg .setenv ("GOPATH" , filepath . Join ( tg .tempdir , "gopath2" ))
5027
+ tg .setenv ("GOPATH" , tg .path ( "gopath2" ))
5028
5028
tg .run ("list" , "-f={{.Target}}" , "p" )
5029
5029
target2 := strings .TrimSpace (tg .getStdout ())
5030
5030
tg .must (os .MkdirAll (filepath .Dir (target2 ), 0777 ))
@@ -5043,7 +5043,7 @@ func TestTestCache(t *testing.T) {
5043
5043
tg .parallel ()
5044
5044
tg .makeTempdir ()
5045
5045
tg .setenv ("GOPATH" , tg .tempdir )
5046
- tg .setenv ("GOCACHE" , filepath . Join ( tg .tempdir , "cache" ))
5046
+ tg .setenv ("GOCACHE" , tg .path ( "cache" ))
5047
5047
5048
5048
// timeout here should not affect result being cached
5049
5049
// or being retrieved later.
@@ -5138,6 +5138,95 @@ func TestTestCache(t *testing.T) {
5138
5138
tg .grepStdout (`ok \tt/t4\t\(cached\)` , "did not cache t/t4" )
5139
5139
}
5140
5140
5141
+ func TestTestCacheInputs (t * testing.T ) {
5142
+ if strings .Contains (os .Getenv ("GODEBUG" ), "gocacheverify" ) {
5143
+ t .Skip ("GODEBUG gocacheverify" )
5144
+ }
5145
+ tg := testgo (t )
5146
+ defer tg .cleanup ()
5147
+ tg .parallel ()
5148
+ tg .makeTempdir ()
5149
+ tg .setenv ("GOPATH" , filepath .Join (tg .pwd (), "testdata" ))
5150
+ tg .setenv ("GOCACHE" , tg .path ("cache" ))
5151
+
5152
+ defer os .Remove (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ))
5153
+ tg .must (ioutil .WriteFile (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), []byte ("x" ), 0644 ))
5154
+ old := time .Now ().Add (- 1 * time .Minute )
5155
+ tg .must (os .Chtimes (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), old , old ))
5156
+ info , err := os .Stat (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ))
5157
+ if err != nil {
5158
+ t .Fatal (err )
5159
+ }
5160
+ t .Logf ("file.txt: old=%v, info.ModTime=%v" , old , info .ModTime ()) // help debug when Chtimes lies about succeeding
5161
+ tg .setenv ("TESTKEY" , "x" )
5162
+
5163
+ tg .must (ioutil .WriteFile (filepath .Join (tg .pwd (), "testdata/src/testcache/script.sh" ), []byte ("#!/bin/sh\n exit 0\n " ), 0755 ))
5164
+ tg .must (os .Chtimes (filepath .Join (tg .pwd (), "testdata/src/testcache/script.sh" ), old , old ))
5165
+
5166
+ tg .run ("test" , "testcache" )
5167
+ tg .run ("test" , "testcache" )
5168
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5169
+
5170
+ tg .setenv ("TESTKEY" , "y" )
5171
+ tg .run ("test" , "testcache" )
5172
+ tg .grepStdoutNot (`\(cached\)` , "did not notice env var change" )
5173
+ tg .run ("test" , "testcache" )
5174
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5175
+
5176
+ tg .run ("test" , "testcache" , "-run=FileSize" )
5177
+ tg .run ("test" , "testcache" , "-run=FileSize" )
5178
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5179
+ tg .must (ioutil .WriteFile (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), []byte ("xxx" ), 0644 ))
5180
+ tg .run ("test" , "testcache" , "-run=FileSize" )
5181
+ tg .grepStdoutNot (`\(cached\)` , "did not notice file size change" )
5182
+ tg .run ("test" , "testcache" , "-run=FileSize" )
5183
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5184
+
5185
+ tg .run ("test" , "testcache" , "-run=Chdir" )
5186
+ tg .run ("test" , "testcache" , "-run=Chdir" )
5187
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5188
+ tg .must (ioutil .WriteFile (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), []byte ("xxxxx" ), 0644 ))
5189
+ tg .run ("test" , "testcache" , "-run=Chdir" )
5190
+ tg .grepStdoutNot (`\(cached\)` , "did not notice file size change" )
5191
+ tg .run ("test" , "testcache" , "-run=Chdir" )
5192
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5193
+
5194
+ tg .must (os .Chtimes (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), old , old ))
5195
+ tg .run ("test" , "testcache" , "-run=FileContent" )
5196
+ tg .run ("test" , "testcache" , "-run=FileContent" )
5197
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5198
+ tg .must (ioutil .WriteFile (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), []byte ("yyy" ), 0644 ))
5199
+ old2 := old .Add (10 * time .Second )
5200
+ tg .must (os .Chtimes (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" ), old2 , old2 ))
5201
+ tg .run ("test" , "testcache" , "-run=FileContent" )
5202
+ tg .grepStdoutNot (`\(cached\)` , "did not notice file content change" )
5203
+ tg .run ("test" , "testcache" , "-run=FileContent" )
5204
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5205
+
5206
+ tg .run ("test" , "testcache" , "-run=DirList" )
5207
+ tg .run ("test" , "testcache" , "-run=DirList" )
5208
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5209
+ tg .must (os .Remove (filepath .Join (tg .pwd (), "testdata/src/testcache/file.txt" )))
5210
+ tg .run ("test" , "testcache" , "-run=DirList" )
5211
+ tg .grepStdoutNot (`\(cached\)` , "did not notice directory change" )
5212
+ tg .run ("test" , "testcache" , "-run=DirList" )
5213
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5214
+
5215
+ switch runtime .GOOS {
5216
+ case "nacl" , "plan9" , "windows" :
5217
+ // no shell scripts
5218
+ default :
5219
+ tg .run ("test" , "testcache" , "-run=Exec" )
5220
+ tg .run ("test" , "testcache" , "-run=Exec" )
5221
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5222
+ tg .must (os .Chtimes (filepath .Join (tg .pwd (), "testdata/src/testcache/script.sh" ), old2 , old2 ))
5223
+ tg .run ("test" , "testcache" , "-run=Exec" )
5224
+ tg .grepStdoutNot (`\(cached\)` , "did not notice script change" )
5225
+ tg .run ("test" , "testcache" , "-run=Exec" )
5226
+ tg .grepStdout (`\(cached\)` , "did not cache" )
5227
+ }
5228
+ }
5229
+
5141
5230
func TestTestVet (t * testing.T ) {
5142
5231
tg := testgo (t )
5143
5232
defer tg .cleanup ()
@@ -5151,9 +5240,9 @@ func TestTestVet(t *testing.T) {
5151
5240
}
5152
5241
` )
5153
5242
5154
- tg .runFail ("test" , filepath . Join ( tg .tempdir , "p1_test.go" ))
5243
+ tg .runFail ("test" , tg .path ( "p1_test.go" ))
5155
5244
tg .grepStderr (`Logf format %d` , "did not diagnose bad Logf" )
5156
- tg .run ("test" , "-vet=off" , filepath . Join ( tg .tempdir , "p1_test.go" ))
5245
+ tg .run ("test" , "-vet=off" , tg .path ( "p1_test.go" ))
5157
5246
tg .grepStdout (`^ok` , "did not print test summary" )
5158
5247
5159
5248
tg .tempFile ("p1.go" , `
@@ -5163,12 +5252,12 @@ func TestTestVet(t *testing.T) {
5163
5252
fmt.Printf("%d") // oops
5164
5253
}
5165
5254
` )
5166
- tg .runFail ("test" , filepath . Join ( tg .tempdir , "p1.go" ))
5255
+ tg .runFail ("test" , tg .path ( "p1.go" ))
5167
5256
tg .grepStderr (`Printf format %d` , "did not diagnose bad Printf" )
5168
- tg .run ("test" , "-x" , "-vet=shift" , filepath . Join ( tg .tempdir , "p1.go" ))
5257
+ tg .run ("test" , "-x" , "-vet=shift" , tg .path ( "p1.go" ))
5169
5258
tg .grepStderr (`[\\/]vet.*-shift` , "did not run vet with -shift" )
5170
5259
tg .grepStdout (`\[no test files\]` , "did not print test summary" )
5171
- tg .run ("test" , "-vet=off" , filepath . Join ( tg .tempdir , "p1.go" ))
5260
+ tg .run ("test" , "-vet=off" , tg .path ( "p1.go" ))
5172
5261
tg .grepStdout (`\[no test files\]` , "did not print test summary" )
5173
5262
5174
5263
tg .setenv ("GOPATH" , filepath .Join (tg .pwd (), "testdata" ))
@@ -5293,8 +5382,8 @@ func TestGoTestJSON(t *testing.T) {
5293
5382
tg .grepStdout (`"Package":"errors"` , "did not see JSON output" )
5294
5383
tg .grepStdout (`"Action":"run"` , "did not see JSON output" )
5295
5384
5296
- tg .run ("test" , "-o" , filepath . Join ( tg .tempdir , "errors.test.exe" ), "-c" , "errors" )
5297
- tg .run ("tool" , "test2json" , "-p" , "errors" , filepath . Join ( tg .tempdir , "errors.test.exe" ), "-test.v" , "-test.short" )
5385
+ tg .run ("test" , "-o" , tg .path ( "errors.test.exe" ), "-c" , "errors" )
5386
+ tg .run ("tool" , "test2json" , "-p" , "errors" , tg .path ( "errors.test.exe" ), "-test.v" , "-test.short" )
5298
5387
tg .grepStdout (`"Package":"errors"` , "did not see JSON output" )
5299
5388
tg .grepStdout (`"Action":"run"` , "did not see JSON output" )
5300
5389
tg .grepStdout (`\{"Action":"pass","Package":"errors"\}` , "did not see final pass" )
0 commit comments