Text file src/cmd/go/testdata/script/mod_test_cached.txt

     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  	"os"
    55  	"path/filepath"
    56  	"testing"
    57  )
    58  
    59  func TestWriteTmp(t *testing.T) {
    60  	dir, err := os.MkdirTemp("", "")
    61  	if err != nil {
    62  		t.Fatal(err)
    63  	}
    64  	defer os.RemoveAll(dir)
    65  	err = os.WriteFile(filepath.Join(dir, "x"), nil, 0666)
    66  	if err != nil {
    67  		t.Fatal(err)
    68  	}
    69  }
    70  
    71  func TestReadTestdata(t *testing.T) {
    72  	_, err := os.ReadFile("testdata/foo.txt")
    73  	if err != nil {
    74  		t.Fatal(err)
    75  	}
    76  }
    77  

View as plain text