From 905a0c69a9308761190963849ecd49d82bf3a177 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 28 Oct 2021 02:19:43 +0100 Subject: [PATCH] fix(helper): call t.Helper() from all test helper functions --- .golangci.yml | 1 + golden.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 92e57d7..bee01fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -49,6 +49,7 @@ linters: - misspell - nakedret - nilerr + - nlreturn - noctx - nolintlint - prealloc diff --git a/golden.go b/golden.go index 8d9fc96..948d369 100644 --- a/golden.go +++ b/golden.go @@ -144,6 +144,8 @@ var global = New() // File returns the filename of the golden file for the given *testing.T // instance as determined by t.Name(). func File(t *testing.T) string { + t.Helper() + return global.File(t) } @@ -151,6 +153,8 @@ func File(t *testing.T) string { // as determined by t.Name(). If no golden file can be found/read, it will fail // the test by calling t.Fatal(). func Get(t *testing.T) []byte { + t.Helper() + return global.Get(t) } @@ -158,12 +162,16 @@ func Get(t *testing.T) []byte { // determined by t.Name(). If writing fails it will fail the test by calling // t.Fatal() with error details. func Set(t *testing.T, data []byte) { + t.Helper() + global.Set(t, data) } // FileP returns the filename of the specifically named golden file for the // given *testing.T instance as determined by t.Name(). func FileP(t *testing.T, name string) string { + t.Helper() + return global.FileP(t, name) } @@ -174,6 +182,8 @@ func FileP(t *testing.T, name string) string { // This is very similar to Get(), but it allows multiple different golden files // to be used within the same one *testing.T instance. func GetP(t *testing.T, name string) []byte { + t.Helper() + return global.GetP(t, name) } @@ -184,6 +194,8 @@ func GetP(t *testing.T, name string) []byte { // This is very similar to Set(), but it allows multiple different golden files // to be used within the same one *testing.T instance. func SetP(t *testing.T, name string, data []byte) { + t.Helper() + global.SetP(t, name, data) } @@ -262,6 +274,7 @@ func (s *Golden) FileP(t *testing.T, name string) string { if t != nil { t.Fatal("golden: name cannot be empty") } + return "" } @@ -277,6 +290,7 @@ func (s *Golden) FileP(t *testing.T, name string) string { func (s *Golden) GetP(t *testing.T, name string) []byte { if name == "" { t.Fatal("golden: name cannot be empty") + return nil } @@ -300,6 +314,7 @@ func (s *Golden) SetP(t *testing.T, name string, data []byte) { func (s *Golden) file(t *testing.T, name string) string { if t.Name() == "" { t.Fatalf("golden: could not determine filename for: %+v", t) + return "" } @@ -339,6 +354,7 @@ func (s *Golden) set(t *testing.T, name string, data []byte) { err := os.MkdirAll(dir, s.DirMode) if err != nil { t.Fatalf("golden: failed to create directory: %s", err.Error()) + return }