Skip to content

Commit

Permalink
Merge pull request #178 from icholy/cleanup
Browse files Browse the repository at this point in the history
Add support for Go 1.14 testing Cleanup function
  • Loading branch information
dnephin authored Dec 20, 2019
2 parents 8fc03ff + b3c6267 commit 3dcccba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type helperT interface {
Helper()
}

type cleanupT interface {
Cleanup(f func())
}

// NewFile creates a new file in a temporary directory using prefix as part of
// the filename. The PathOps are applied to the before returning the File.
func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
Expand All @@ -50,6 +54,9 @@ func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(file.Remove)
}
if ct, ok := t.(cleanupT); ok {
ct.Cleanup(file.Remove)
}
return file
}

Expand Down Expand Up @@ -90,6 +97,9 @@ func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(dir.Remove)
}
if ct, ok := t.(cleanupT); ok {
ct.Cleanup(dir.Remove)
}
return dir
}

Expand Down

0 comments on commit 3dcccba

Please sign in to comment.