|
| 1 | +//golangcitest:args -Ettempdir |
| 2 | +package testdata |
| 3 | + |
| 4 | +import ( |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + "path/filepath" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +var ( |
| 12 | + tdir = os.TempDir() // never seen |
| 13 | +) |
| 14 | + |
| 15 | +func testsetup() { |
| 16 | + os.TempDir() // if -all = true, want "os\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup" |
| 17 | + dir := os.TempDir() // if -all = true, want "os\\.TempDir\\(\\) should be replaced by `testing\\.TempDir\\(\\)` in testsetup" |
| 18 | + _ = dir |
| 19 | + _ = os.TempDir() // if -all = true, "func setup is not using testing.TempDir" |
| 20 | +} |
| 21 | + |
| 22 | +func TestF(t *testing.T) { |
| 23 | + testsetup() |
| 24 | + os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF" |
| 25 | + _ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF" |
| 26 | + if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestF" |
| 27 | + _ = dir |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func BenchmarkF(b *testing.B) { |
| 32 | + TB(b) |
| 33 | + os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF" |
| 34 | + _ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF" |
| 35 | + if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `b\\.TempDir\\(\\)` in BenchmarkF" |
| 36 | + _ = dir |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TB(tb testing.TB) { |
| 41 | + os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB" |
| 42 | + _ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB" |
| 43 | + if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `tb\\.TempDir\\(\\)` in TB" |
| 44 | + _ = dir |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func FuzzF(f *testing.F) { |
| 49 | + os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF" |
| 50 | + _ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF" |
| 51 | + if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `f\\.TempDir\\(\\)` in FuzzF" |
| 52 | + _ = dir |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +func TestFunctionLiteral(t *testing.T) { |
| 57 | + testsetup() |
| 58 | + t.Run("test", func(t *testing.T) { |
| 59 | + os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function" |
| 60 | + _ = os.TempDir() // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function" |
| 61 | + if dir = os.TempDir(); dir != "" { // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in anonymous function" |
| 62 | + _ = dir |
| 63 | + } |
| 64 | + }) |
| 65 | +} |
| 66 | + |
| 67 | +func TestEmpty(t *testing.T) { |
| 68 | + t.Run("test", func(*testing.T) {}) |
| 69 | +} |
| 70 | + |
| 71 | +func TestEmptyTB(t *testing.T) { |
| 72 | + func(testing.TB) {}(t) |
| 73 | +} |
| 74 | + |
| 75 | +func TestRecursive(t *testing.T) { |
| 76 | + t.Log( // recursion level 1 |
| 77 | + os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive" |
| 78 | + ) |
| 79 | + t.Log( // recursion level 1 |
| 80 | + fmt.Sprintf("%s", // recursion level 2 |
| 81 | + os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive" |
| 82 | + ), |
| 83 | + ) |
| 84 | + t.Log( // recursion level 1 |
| 85 | + filepath.Clean( // recursion level 2 |
| 86 | + fmt.Sprintf("%s", // recursion level 3 |
| 87 | + os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive" |
| 88 | + ), |
| 89 | + ), |
| 90 | + ) |
| 91 | + t.Log( // recursion level 1 |
| 92 | + filepath.Join( // recursion level 2 |
| 93 | + filepath.Clean( // recursion level 3 |
| 94 | + fmt.Sprintf("%s", // recursion level 4 |
| 95 | + os.TempDir(), // want "os\\.TempDir\\(\\) should be replaced by `t\\.TempDir\\(\\)` in TestRecursive" |
| 96 | + ), |
| 97 | + ), |
| 98 | + "test", |
| 99 | + ), |
| 100 | + ) |
| 101 | + t.Log( // recursion level 1 |
| 102 | + fmt.Sprintf("%s/foo-%d", // recursion level 2 |
| 103 | + filepath.Join( // recursion level 3 |
| 104 | + filepath.Clean( // recursion level 4 |
| 105 | + fmt.Sprintf("%s", // recursion level 5 |
| 106 | + os.TempDir(), // max recursion level reached. |
| 107 | + ), |
| 108 | + ), |
| 109 | + "test", |
| 110 | + ), |
| 111 | + 1024, |
| 112 | + ), |
| 113 | + ) |
| 114 | +} |
0 commit comments