...

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

Documentation: cmd/go/testdata/script

     1[short] skip
     2
     3env GO111MODULE=on
     4env GOCACHE=$WORK/gocache
     5env GODEBUG=gocachetest=1
     6
     7# The first run of a test should not be cached.
     8# The second run should be.
     9go test -run=WriteTmp .
    10! stdout '(cached)'
    11go test -run=WriteTmp .
    12stdout '(cached)'
    13
    14# 'go test' without arguments should never be cached.
    15go test -run=WriteTmp
    16! stdout '(cached)'
    17go test -run=WriteTmp
    18! stdout '(cached)'
    19
    20# We should never cache a test run from command-line files.
    21go test -run=WriteTmp ./foo_test.go
    22! stdout '(cached)'
    23go 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.
    28exec sleep 2
    29
    30# Touching a file that the test reads from within its testdata should invalidate the cache.
    31go test -run=ReadTestdata .
    32! stdout '(cached)'
    33go test -run=ReadTestdata .
    34stdout '(cached)'
    35cp testdata/bar.txt testdata/foo.txt
    36go test -run=ReadTestdata .
    37! stdout '(cached)'
    38
    39-- go.mod --
    40module golang.org/issue/29111/foo
    41
    42-- foo.go --
    43package foo
    44
    45-- testdata/foo.txt --
    46foo
    47-- testdata/bar.txt --
    48bar
    49
    50-- foo_test.go --
    51package foo_test
    52
    53import (
    54	"os"
    55	"path/filepath"
    56	"testing"
    57)
    58
    59func 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
    71func TestReadTestdata(t *testing.T) {
    72	_, err := os.ReadFile("testdata/foo.txt")
    73	if err != nil {
    74		t.Fatal(err)
    75	}
    76}

View as plain text