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

     1  # The test binary skips inputs it has already written to its test log
     2  # since the last change of directory (testing/internal/testdeps).
     3  # Check that inputs read many times, before and after a chdir, still
     4  # invalidate the cache.
     5  
     6  [short] skip
     7  [!exec:sleep] skip
     8  
     9  env GOCACHE=$WORK/gocache
    10  env TESTKEY=1
    11  
    12  # The go command refuses to cache access to files younger than 2s.
    13  exec sleep 2
    14  
    15  go test .
    16  ! stdout '(cached)'
    17  go test .
    18  stdout '(cached)'
    19  
    20  # a.txt read before the chdir.
    21  cp new.txt a.txt
    22  exec sleep 2
    23  go test .
    24  ! stdout '(cached)'
    25  go test .
    26  stdout '(cached)'
    27  
    28  # The same name read after the chdir is a different file.
    29  cp new.txt sub/a.txt
    30  exec sleep 2
    31  go test .
    32  ! stdout '(cached)'
    33  go test .
    34  stdout '(cached)'
    35  
    36  # An environment variable read more than once.
    37  env TESTKEY=2
    38  go test .
    39  ! stdout '(cached)'
    40  
    41  -- go.mod --
    42  module example.com/repeat
    43  
    44  go 1.26
    45  -- repeat_test.go --
    46  package repeat
    47  
    48  import (
    49  	"os"
    50  	"testing"
    51  )
    52  
    53  func read(t *testing.T, name string) {
    54  	for range 3 {
    55  		if _, err := os.ReadFile(name); err != nil {
    56  			t.Fatal(err)
    57  		}
    58  	}
    59  }
    60  
    61  func TestRepeat(t *testing.T) {
    62  	read(t, "a.txt")
    63  	os.Getenv("TESTKEY")
    64  	os.Getenv("TESTKEY")
    65  	t.Chdir("sub")
    66  	read(t, "a.txt")
    67  }
    68  -- a.txt --
    69  a
    70  -- sub/a.txt --
    71  sub a
    72  -- new.txt --
    73  new
    74  

View as plain text