aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_test_cached.txt
blob: 3da4358fa1435ddb38ee4d5b57e7116935bda861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[short] skip

env GO111MODULE=on
env GOCACHE=$WORK/gocache
env GODEBUG=gocachetest=1

# The first run of a test should not be cached.
# The second run should be.
go test -run=WriteTmp .
! stdout '(cached)'
go test -run=WriteTmp .
stdout '(cached)'

# 'go test' without arguments should never be cached.
go test -run=WriteTmp
! stdout '(cached)'
go test -run=WriteTmp
! stdout '(cached)'

# We should never cache a test run from command-line files.
go test -run=WriteTmp ./foo_test.go
! stdout '(cached)'
go test -run=WriteTmp ./foo_test.go
! stdout '(cached)'

[!exec:sleep] stop
# The go command refuses to cache access to files younger than 2s, so sleep that long.
exec sleep 2

# Touching a file that the test reads from within its testdata should invalidate the cache.
go test -run=ReadTestdata .
! stdout '(cached)'
go test -run=ReadTestdata .
stdout '(cached)'
cp testdata/bar.txt testdata/foo.txt
go test -run=ReadTestdata .
! stdout '(cached)'

-- go.mod --
module golang.org/issue/29111/foo

-- foo.go --
package foo

-- testdata/foo.txt --
foo
-- testdata/bar.txt --
bar

-- foo_test.go --
package foo_test

import (
	"os"
	"path/filepath"
	"testing"
)

func TestWriteTmp(t *testing.T) {
	dir, err := os.MkdirTemp("", "")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(dir)
	err = os.WriteFile(filepath.Join(dir, "x"), nil, 0666)
	if err != nil {
		t.Fatal(err)
	}
}

func TestReadTestdata(t *testing.T) {
	_, err := os.ReadFile("testdata/foo.txt")
	if err != nil {
		t.Fatal(err)
	}
}