github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_test_cached.txt (about) 1 [short] skip 2 3 env GO111MODULE=on 4 env GOCACHE=$WORK/gocache 5 env GODEBUG=gocachetest=1 6 7 # The first run of a test should not be cached. 8 # The second run should be. 9 go test -run=WriteTmp . 10 ! stdout '(cached)' 11 go test -run=WriteTmp . 12 stdout '(cached)' 13 14 # 'go test' without arguments should never be cached. 15 go test -run=WriteTmp 16 ! stdout '(cached)' 17 go test -run=WriteTmp 18 ! stdout '(cached)' 19 20 # We should never cache a test run from command-line files. 21 go test -run=WriteTmp ./foo_test.go 22 ! stdout '(cached)' 23 go test -run=WriteTmp ./foo_test.go 24 ! stdout '(cached)' 25 26 [!exec:sleep] stop 27 # The go command refuses to cache access to files younger than 2s, so sleep that long. 28 exec sleep 2 29 30 # Touching a file that the test reads from within its testdata should invalidate the cache. 31 go test -run=ReadTestdata . 32 ! stdout '(cached)' 33 go test -run=ReadTestdata . 34 stdout '(cached)' 35 cp testdata/bar.txt testdata/foo.txt 36 go test -run=ReadTestdata . 37 ! stdout '(cached)' 38 39 -- go.mod -- 40 module golang.org/issue/29111/foo 41 42 -- foo.go -- 43 package foo 44 45 -- testdata/foo.txt -- 46 foo 47 -- testdata/bar.txt -- 48 bar 49 50 -- foo_test.go -- 51 package foo_test 52 53 import ( 54 "io/ioutil" 55 "os" 56 "path/filepath" 57 "testing" 58 ) 59 60 func TestWriteTmp(t *testing.T) { 61 dir, err := ioutil.TempDir("", "") 62 if err != nil { 63 t.Fatal(err) 64 } 65 defer os.RemoveAll(dir) 66 err = ioutil.WriteFile(filepath.Join(dir, "x"), nil, 0666) 67 if err != nil { 68 t.Fatal(err) 69 } 70 } 71 72 func TestReadTestdata(t *testing.T) { 73 _, err := ioutil.ReadFile("testdata/foo.txt") 74 if err != nil { 75 t.Fatal(err) 76 } 77 }