testutil: If testing.T is nil panic with error (#4725)

This commit is contained in:
James Hartig 2018-10-26 15:13:40 -04:00 committed by Jack Pearkes
parent 7742aec226
commit 0934940f4e
1 changed files with 6 additions and 0 deletions

View File

@ -39,6 +39,9 @@ func TempDir(t *testing.T, name string) string {
name = strings.Replace(name, "/", "_", -1)
d, err := ioutil.TempDir(tmpdir, name)
if err != nil {
if t == nil {
panic(err)
}
t.Fatalf("err: %s", err)
}
return d
@ -55,6 +58,9 @@ func TempFile(t *testing.T, name string) *os.File {
}
f, err := ioutil.TempFile(tmpdir, name)
if err != nil {
if t == nil {
panic(err)
}
t.Fatalf("err: %s", err)
}
return f