From a68fd497b0572d5dcf9027148804b74371d8ab5e Mon Sep 17 00:00:00 2001 From: tkrop Date: Tue, 14 Nov 2023 13:36:11 +0100 Subject: [PATCH] fix: tempdir delegate (#57) Signed-off-by: tkrop --- test/caller_test.go | 2 +- test/testing.go | 6 +++++- test/testing_test.go | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/test/caller_test.go b/test/caller_test.go index 3113256..3910eb9 100644 --- a/test/caller_test.go +++ b/test/caller_test.go @@ -94,7 +94,7 @@ var ( }() // CallerTestErrorf provides the file with the line number of the `Errorf` // call in testing. - CallerTestErrorf = path.Join(SourceDir, "testing.go:176") + CallerTestErrorf = path.Join(SourceDir, "testing.go:180") // CallerGomockErrorf provides the file with the line number of the // `Errorf` call in gomock. CallerGomockErrorf = path.Join(SourceDir, "gomock.go:61") diff --git a/test/testing.go b/test/testing.go index 13fca0b..21888fd 100644 --- a/test/testing.go +++ b/test/testing.go @@ -105,7 +105,6 @@ type Cleanuper interface { // can be used as a drop in replacement for `testing.T` in various libraries // to check for expected test failures. type Tester struct { - Test sync.Synchronizer t Test wg sync.WaitGroup @@ -159,6 +158,11 @@ func (t *Tester) Name() string { return t.t.Name() } +// TempDir delegates the request to the parent test context. +func (t *Tester) TempDir() string { + return t.t.TempDir() +} + // Helper delegates request to the parent test context. func (t *Tester) Helper() { t.t.Helper() diff --git a/test/testing_test.go b/test/testing_test.go index 890e565..2d6150e 100644 --- a/test/testing_test.go +++ b/test/testing_test.go @@ -252,6 +252,13 @@ type ParamParam struct { expect bool } +func TestTempDir(t *testing.T) { + test.New[ParamParam](t, ParamParam{expect: true}). + Run(func(t test.Test, param ParamParam) { + assert.NotEmpty(t, t.TempDir()) + }) +} + func TestNameCastFallback(t *testing.T) { test.New[ParamParam](t, ParamParam{name: "value"}). Run(func(t test.Test, param ParamParam) {