From fb9b6314a0439999079a511d83427744de973f60 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 6 Apr 2021 15:20:36 +1000 Subject: [PATCH] ensure we're passing the right testing struct pointer around --- pkg/gui/gui_test.go | 6 +++--- pkg/integration/integration.go | 9 +++++---- test/runner/main.go | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index 43c426e53..b44f04513 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -43,16 +43,16 @@ func Test(t *testing.T) { err := integration.RunTests( t.Logf, runCmdHeadless, - func(test *integration.Test, f func() error) { + func(test *integration.Test, f func(*testing.T) error) { t.Run(test.Name, func(t *testing.T) { - err := f() + err := f(t) assert.NoError(t, err) }) }, updateSnapshots, record, speedEnv, - func(expected string, actual string) { + func(t *testing.T, expected string, actual string) { assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual)) }, ) diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index cf65386e8..ddb20cc5b 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strconv" "strings" + "testing" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/secureexec" @@ -27,11 +28,11 @@ type Test struct { func RunTests( logf func(format string, formatArgs ...interface{}), runCmd func(cmd *exec.Cmd) error, - fnWrapper func(test *Test, f func() error), + fnWrapper func(test *Test, f func(*testing.T) error), updateSnapshots bool, record bool, speedEnv string, - onFail func(expected string, actual string), + onFail func(t *testing.T, expected string, actual string), ) error { rootDir := GetRootDirectory() err := os.Chdir(rootDir) @@ -55,7 +56,7 @@ func RunTests( for _, test := range tests { test := test - fnWrapper(test, func() error { + fnWrapper(test, func(t *testing.T) error { speeds := getTestSpeeds(test.Speed, updateSnapshots, speedEnv) testPath := filepath.Join(testDir, test.Name) actualDir := filepath.Join(testPath, "actual") @@ -118,7 +119,7 @@ func RunTests( return err } logf("%s", string(bytes)) - onFail(expected, actual) + onFail(t, expected, actual) } } diff --git a/test/runner/main.go b/test/runner/main.go index 54e163c48..2b1c96aea 100644 --- a/test/runner/main.go +++ b/test/runner/main.go @@ -5,6 +5,7 @@ import ( "log" "os" "os/exec" + "testing" "github.com/jesseduffield/lazygit/pkg/integration" "github.com/stretchr/testify/assert" @@ -27,18 +28,18 @@ func main() { err := integration.RunTests( log.Printf, runCmdInTerminal, - func(test *integration.Test, f func() error) { + func(test *integration.Test, f func(*testing.T) error) { if selectedTestName != "" && test.Name != selectedTestName { return } - if err := f(); err != nil { + if err := f(nil); err != nil { log.Print(err.Error()) } }, updateSnapshots, record, speedEnv, - func(expected string, actual string) { + func(_t *testing.T, expected string, actual string) { assert.Equal(MockTestingT{}, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual)) }, )