From 932b12a65fc5eacfebab0562f24d107f7389e4b5 Mon Sep 17 00:00:00 2001 From: broothie Date: Sat, 28 Jun 2025 22:54:54 -0700 Subject: [PATCH 1/3] Convert tests from broothie/test to testify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace all instances of broothie/test with stretchr/testify - Use assert.* for test assertions and require.* for must-pass conditions - Update go.mod and go.sum to remove broothie/test dependency and add testify - Maintain existing test logic and behavior 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- argument_config_validation_test.go | 9 +-- argument_input_validation_test.go | 9 +-- cli_test.go | 61 ++++++++++---------- command_config_validation_test.go | 4 +- exit_test.go | 8 +-- flag_config_validation_test.go | 9 +-- flag_test.go | 11 ++-- go.mod | 5 +- go.sum | 13 +++-- help_test.go | 21 +++---- options_test.go | 91 +++++++++++++++--------------- 11 files changed, 125 insertions(+), 116 deletions(-) diff --git a/argument_config_validation_test.go b/argument_config_validation_test.go index 7fe9ed7..ed75f0b 100644 --- a/argument_config_validation_test.go +++ b/argument_config_validation_test.go @@ -3,25 +3,26 @@ package cli import ( "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestArgument_validateConfig(t *testing.T) { t.Run("empty name", func(t *testing.T) { arg := &Argument{name: ""} err := arg.validateConfig() - test.ErrorMessageIs(t, err, "argument name cannot be empty") + assert.EqualError(t, err, "argument name cannot be empty") }) t.Run("multiple tokens", func(t *testing.T) { arg := &Argument{name: "invalid argument name"} err := arg.validateConfig() - test.ErrorMessageIs(t, err, `argument name "invalid argument name" must be a single token`) + assert.EqualError(t, err, `argument name "invalid argument name" must be a single token`) }) t.Run("valid name", func(t *testing.T) { arg := &Argument{name: "valid-arg"} err := arg.validateConfig() - test.NoError(t, err) + require.NoError(t, err) }) } diff --git a/argument_input_validation_test.go b/argument_input_validation_test.go index 2cf44a1..787c6f2 100644 --- a/argument_input_validation_test.go +++ b/argument_input_validation_test.go @@ -3,15 +3,16 @@ package cli import ( "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestArgument_validateInput(t *testing.T) { arg, err := newArgument("test-arg", "Test arg.") - test.MustNoError(t, err) + require.NoError(t, err) - test.ErrorMessageIs(t, arg.validateInput(), `argument "test-arg": argument missing value`) + assert.EqualError(t, arg.validateInput(), `argument "test-arg": argument missing value`) arg.value = "something" - test.NoError(t, arg.validateInput()) + require.NoError(t, arg.validateInput()) } diff --git a/cli_test.go b/cli_test.go index 90117d1..c11ab16 100644 --- a/cli_test.go +++ b/cli_test.go @@ -4,13 +4,14 @@ import ( "context" "testing" - "github.com/broothie/test" "github.com/samber/lo" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func ensureCalled(t *testing.T) func() { called := false - t.Cleanup(func() { test.True(t, called) }) + t.Cleanup(func() { assert.True(t, called) }) return func() { called = true } } @@ -42,8 +43,8 @@ func Test_git(t *testing.T) { called() gitDir, err := FlagValue[string](ctx, "git-dir") - test.NoError(t, err) - test.Equal(t, "/path/to/something", gitDir) + require.NoError(t, err) + assert.Equal(t, "/path/to/something", gitDir) return nil } @@ -57,8 +58,8 @@ func Test_git(t *testing.T) { called() gitDir, err := FlagValue[string](ctx, "git-dir") - test.NoError(t, err) - test.Equal(t, "/path/to/something", gitDir) + require.NoError(t, err) + assert.Equal(t, "/path/to/something", gitDir) return nil } @@ -82,8 +83,8 @@ func Test_git(t *testing.T) { called() message, err := FlagValue[string](ctx, "message") - test.NoError(t, err) - test.Equal(t, "a commit message", message) + require.NoError(t, err) + assert.Equal(t, "a commit message", message) return nil } @@ -97,12 +98,12 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - test.NoError(t, err) - test.False(t, isAll) + require.NoError(t, err) + assert.False(t, isAll) message, err := FlagValue[string](ctx, "message") - test.NoError(t, err) - test.Equal(t, "a commit message", message) + require.NoError(t, err) + assert.Equal(t, "a commit message", message) return nil } @@ -116,12 +117,12 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - test.NoError(t, err) - test.False(t, isAll) + require.NoError(t, err) + assert.False(t, isAll) message, err := FlagValue[string](ctx, "message") - test.NoError(t, err) - test.Equal(t, "a commit message", message) + require.NoError(t, err) + assert.Equal(t, "a commit message", message) return nil } @@ -135,12 +136,12 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - test.NoError(t, err) - test.True(t, isAll) + require.NoError(t, err) + assert.True(t, isAll) message, err := FlagValue[string](ctx, "message") - test.NoError(t, err) - test.Equal(t, "a commit message", message) + require.NoError(t, err) + assert.Equal(t, "a commit message", message) return nil } @@ -154,8 +155,8 @@ func Test_git(t *testing.T) { called() branch, err := ArgValue[string](ctx, "branch") - test.NoError(t, err) - test.Equal(t, "some-branch", branch) + require.NoError(t, err) + assert.Equal(t, "some-branch", branch) return nil } @@ -169,12 +170,12 @@ func Test_git(t *testing.T) { called() branch, err := ArgValue[string](ctx, "branch") - test.NoError(t, err) - test.Equal(t, "some-branch", branch) + require.NoError(t, err) + assert.Equal(t, "some-branch", branch) isNewBranch, err := FlagValue[bool](ctx, "new-branch") - test.NoError(t, err) - test.True(t, isNewBranch) + require.NoError(t, err) + assert.True(t, isNewBranch) return nil } @@ -188,8 +189,8 @@ func Test_git(t *testing.T) { called() globalGitignore, err := FlagValue[string](ctx, "global-gitignore") - test.NoError(t, err) - test.Equal(t, globalGitignore, "path/to/some/.gitignore") + require.NoError(t, err) + assert.Equal(t, globalGitignore, "path/to/some/.gitignore") return nil } }, @@ -228,8 +229,8 @@ func Test_git(t *testing.T) { SetHandler(lo.IfF(testCase.gitHandler != nil, func() Handler { return testCase.gitHandler(t) }).Else(nil)), ) - test.NoError(t, err) - test.Nil(t, command.Run(context.TODO(), testCase.rawArgs)) + require.NoError(t, err) + assert.Nil(t, command.Run(context.TODO(), testCase.rawArgs)) }) } } diff --git a/command_config_validation_test.go b/command_config_validation_test.go index c27f01b..0aaf4f3 100644 --- a/command_config_validation_test.go +++ b/command_config_validation_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/broothie/option" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" ) func TestCommand_config_validations(t *testing.T) { @@ -47,7 +47,7 @@ func TestCommand_config_validations(t *testing.T) { for name, testCase := range testCases { t.Run(name, func(t *testing.T) { _, err := NewCommand("test", "test command", testCase.commandOptions...) - test.ErrorMessageIs(t, err, testCase.expectedError) + assert.EqualError(t, err, testCase.expectedError) }) } } diff --git a/exit_test.go b/exit_test.go index 1f07b63..3225d49 100644 --- a/exit_test.go +++ b/exit_test.go @@ -5,17 +5,17 @@ import ( "os/exec" "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" ) func TestExitError_Error(t *testing.T) { err := &ExitError{Code: 2} - test.Equal(t, "exit status 2", err.Error()) + assert.Equal(t, "exit status 2", err.Error()) } func TestExitCode(t *testing.T) { err := ExitCode(3) - test.Equal(t, 3, err.Code) + assert.Equal(t, 3, err.Code) } func TestExitWithError(t *testing.T) { @@ -30,7 +30,7 @@ func TestExitWithError(t *testing.T) { err := cmd.Run() if exitErr, ok := err.(*exec.ExitError); ok { - test.Equal(t, 4, exitErr.ExitCode()) + assert.Equal(t, 4, exitErr.ExitCode()) } else { t.Errorf("expected ExitError, got %v", err) } diff --git a/flag_config_validation_test.go b/flag_config_validation_test.go index 58ec6a0..7a22d2e 100644 --- a/flag_config_validation_test.go +++ b/flag_config_validation_test.go @@ -3,25 +3,26 @@ package cli import ( "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFlag_validateConfig(t *testing.T) { t.Run("empty name", func(t *testing.T) { flag := &Flag{name: ""} err := flag.validateConfig() - test.ErrorMessageIs(t, err, "flag name cannot be empty") + assert.EqualError(t, err, "flag name cannot be empty") }) t.Run("multiple tokens", func(t *testing.T) { flag := &Flag{name: "invalid flag name"} err := flag.validateConfig() - test.ErrorMessageIs(t, err, `flag name "invalid flag name" must be a single token`) + assert.EqualError(t, err, `flag name "invalid flag name" must be a single token`) }) t.Run("valid name", func(t *testing.T) { flag := &Flag{name: "valid-flag"} err := flag.validateConfig() - test.NoError(t, err) + require.NoError(t, err) }) } diff --git a/flag_test.go b/flag_test.go index 74e568c..a99bfa2 100644 --- a/flag_test.go +++ b/flag_test.go @@ -3,7 +3,8 @@ package cli import ( "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/samber/lo" ) @@ -16,11 +17,11 @@ func TestCommand_flagsUpToRoot(t *testing.T) { ), ) - test.NoError(t, err) + require.NoError(t, err) flags := command.subCommands[0].flagsUpToRoot() flagNames := lo.Map(flags, func(flag *Flag, _ int) string { return flag.name }) - test.Contains(t, flagNames, "top-inherited") - test.Contains(t, flagNames, "flag") - test.NotContains(t, flagNames, "top-uninherited") + assert.Contains(t, flagNames, "top-inherited") + assert.Contains(t, flagNames, "flag") + assert.NotContains(t, flagNames, "top-uninherited") } diff --git a/go.mod b/go.mod index 77ba205..4db7e5f 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,13 @@ require ( github.com/MakeNowJust/heredoc/v2 v2.0.1 github.com/bobg/errors v1.1.0 github.com/broothie/option v0.1.0 - github.com/broothie/test v0.1.9 github.com/samber/lo v1.49.1 + github.com/stretchr/testify v1.10.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kylelemons/godebug v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/text v0.21.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8b834be..fed2452 100644 --- a/go.sum +++ b/go.sum @@ -4,21 +4,22 @@ github.com/bobg/errors v1.1.0 h1:gsVanPzJMpZQpwY+27/GQYElZez5CuMYwiIpk2A3RGw= github.com/bobg/errors v1.1.0/go.mod h1:Q4775qBZpnte7EGFJqmvnlB1U4pkI1XmU3qxqdp7Zcc= github.com/broothie/option v0.1.0 h1:5l6qdv9g1Ajxn7821brKVzOZxIjlVB0gA1MU8QbW8Fw= github.com/broothie/option v0.1.0/go.mod h1:doEn1r1TpaaBJRdHLZlsdjvnrnH0u1WW+FZA018hE2g= -github.com/broothie/test v0.1.9 h1:YO+pAEssBJPvJEWSvl2dSjhsUFm9xszqOXFVEfiI33Q= -github.com/broothie/test v0.1.9/go.mod h1:txzDcP9OHro3y7goC+ZznIkASy8NJks4dUcdbwsP0HM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew= github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= -go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/help_test.go b/help_test.go index f556f41..acbdb41 100644 --- a/help_test.go +++ b/help_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/MakeNowJust/heredoc/v2" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type CustomType struct { @@ -37,12 +38,12 @@ func TestCommand_renderHelp(t *testing.T) { ), ) - test.NoError(t, err) + require.NoError(t, err) buffer := new(bytes.Buffer) - test.NoError(t, command.renderHelp(buffer)) + require.NoError(t, command.renderHelp(buffer)) - test.Equal(t, + assert.Equal(t, heredoc.Doc(` test v1.2.3-rc10: test command @@ -74,12 +75,12 @@ func TestCommand_renderHelp(t *testing.T) { AddSubCmd("some-command", "some command"), ) - test.NoError(t, err) + require.NoError(t, err) buffer := new(bytes.Buffer) - test.NoError(t, command.renderHelp(buffer)) + require.NoError(t, command.renderHelp(buffer)) - test.Equal(t, + assert.Equal(t, heredoc.Doc(` test v1.2.3-rc10: test command @@ -109,12 +110,12 @@ func TestCommand_renderHelp(t *testing.T) { ), ) - test.NoError(t, err) + require.NoError(t, err) buffer := new(bytes.Buffer) - test.NoError(t, command.subCommands[0].renderHelp(buffer)) + require.NoError(t, command.subCommands[0].renderHelp(buffer)) - test.Equal(t, + assert.Equal(t, heredoc.Doc(` test v1.2.3-rc10: test command diff --git a/options_test.go b/options_test.go index cbf0da9..1fd2ac7 100644 --- a/options_test.go +++ b/options_test.go @@ -7,7 +7,8 @@ import ( "reflect" "testing" - "github.com/broothie/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_options(t *testing.T) { @@ -29,66 +30,66 @@ func Test_options(t *testing.T) { SetHandler(func(context.Context) error { return nil }), ) - test.NoError(t, err) + require.NoError(t, err) // Command - test.Equal(t, "http", httpCommand.name) - test.Equal(t, "Run http server", httpCommand.description) - test.Equal(t, "v0.1.0", httpCommand.version) - test.Nil(t, httpCommand.parent) - test.Equal(t, httpCommand, httpCommand.root()) - test.True(t, httpCommand.isRoot()) - test.False(t, httpCommand.hasParent()) - test.Equal(t, "http", httpCommand.qualifiedName()) - test.Equal(t, "v0.1.0", httpCommand.findVersion()) + assert.Equal(t, "http", httpCommand.name) + assert.Equal(t, "Run http server", httpCommand.description) + assert.Equal(t, "v0.1.0", httpCommand.version) + assert.Nil(t, httpCommand.parent) + assert.Equal(t, httpCommand, httpCommand.root()) + assert.True(t, httpCommand.isRoot()) + assert.False(t, httpCommand.hasParent()) + assert.Equal(t, "http", httpCommand.qualifiedName()) + assert.Equal(t, "v0.1.0", httpCommand.findVersion()) // Flags - test.NotSliceEmpty(t, httpCommand.flags) + assert.NotEmpty(t, httpCommand.flags) helpFlag := httpCommand.flags[0] - test.Equal(t, "help", helpFlag.name) - test.Equal(t, "Print help.", helpFlag.description) - test.Equal(t, false, helpFlag.defaultValue) - test.Nil(t, helpFlag.value) - test.Equal(t, reflect.ValueOf(BoolParser).Pointer(), reflect.ValueOf(helpFlag.parser).Pointer()) - test.True(t, helpFlag.isBool()) - test.True(t, helpFlag.isHelp) + assert.Equal(t, "help", helpFlag.name) + assert.Equal(t, "Print help.", helpFlag.description) + assert.Equal(t, false, helpFlag.defaultValue) + assert.Nil(t, helpFlag.value) + assert.Equal(t, reflect.ValueOf(BoolParser).Pointer(), reflect.ValueOf(helpFlag.parser).Pointer()) + assert.True(t, helpFlag.isBool()) + assert.True(t, helpFlag.isHelp) portFlag := httpCommand.flags[1] - test.Equal(t, "port", portFlag.name) - test.Equal(t, "Port to run server on", portFlag.description) - test.DeepEqual(t, []string{"addr"}, portFlag.aliases) - test.DeepEqual(t, []rune{'p'}, portFlag.shorts) - test.Equal(t, 3000, portFlag.defaultValue) - test.Equal(t, "PORT", portFlag.defaultEnvName) - test.Nil(t, portFlag.value) - test.Equal(t, reflect.ValueOf(IntParser).Pointer(), reflect.ValueOf(portFlag.parser).Pointer()) - test.False(t, portFlag.isBool()) - test.False(t, portFlag.isHelp) + assert.Equal(t, "port", portFlag.name) + assert.Equal(t, "Port to run server on", portFlag.description) + assert.Equal(t, []string{"addr"}, portFlag.aliases) + assert.Equal(t, []rune{'p'}, portFlag.shorts) + assert.Equal(t, 3000, portFlag.defaultValue) + assert.Equal(t, "PORT", portFlag.defaultEnvName) + assert.Nil(t, portFlag.value) + assert.Equal(t, reflect.ValueOf(IntParser).Pointer(), reflect.ValueOf(portFlag.parser).Pointer()) + assert.False(t, portFlag.isBool()) + assert.False(t, portFlag.isHelp) // Sub-command - test.NotSliceEmpty(t, httpCommand.subCommands) + assert.NotEmpty(t, httpCommand.subCommands) proxySubCommand := httpCommand.subCommands[0] - test.Equal(t, "proxy", proxySubCommand.name) - test.Equal(t, "Proxy requests", proxySubCommand.description) - test.Equal(t, "", proxySubCommand.version) - test.DeepEqual(t, []string{"p", "x"}, proxySubCommand.aliases) - test.NotNil(t, proxySubCommand.parent) - test.Equal(t, httpCommand, proxySubCommand.root()) - test.False(t, proxySubCommand.isRoot()) - test.True(t, proxySubCommand.hasParent()) - test.Equal(t, "http proxy", proxySubCommand.qualifiedName()) - test.Equal(t, "v0.1.0", proxySubCommand.findVersion()) + assert.Equal(t, "proxy", proxySubCommand.name) + assert.Equal(t, "Proxy requests", proxySubCommand.description) + assert.Equal(t, "", proxySubCommand.version) + assert.Equal(t, []string{"p", "x"}, proxySubCommand.aliases) + assert.NotNil(t, proxySubCommand.parent) + assert.Equal(t, httpCommand, proxySubCommand.root()) + assert.False(t, proxySubCommand.isRoot()) + assert.True(t, proxySubCommand.hasParent()) + assert.Equal(t, "http proxy", proxySubCommand.qualifiedName()) + assert.Equal(t, "v0.1.0", proxySubCommand.findVersion()) // Argument - test.NotSliceEmpty(t, proxySubCommand.arguments) + assert.NotEmpty(t, proxySubCommand.arguments) targetArgument := proxySubCommand.arguments[0] - test.Equal(t, "target", targetArgument.name) - test.Equal(t, "Target to proxy requests to", targetArgument.description) - test.Equal(t, reflect.ValueOf(URLParser).Pointer(), reflect.ValueOf(targetArgument.parser).Pointer()) - test.Nil(t, targetArgument.value) + assert.Equal(t, "target", targetArgument.name) + assert.Equal(t, "Target to proxy requests to", targetArgument.description) + assert.Equal(t, reflect.ValueOf(URLParser).Pointer(), reflect.ValueOf(targetArgument.parser).Pointer()) + assert.Nil(t, targetArgument.value) }) } From fcd39f35d90fb9233b9adb18125489d04c73ef1a Mon Sep 17 00:00:00 2001 From: broothie Date: Sat, 28 Jun 2025 23:02:37 -0700 Subject: [PATCH 2/3] Fix testify usage: use assert.* for most assertions, require.* only for Must functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Convert most require.NoError back to assert.NoError - Keep require.NoError only for the original test.MustNoError call - Maintain proper distinction between assertions and requirements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- argument_config_validation_test.go | 2 +- argument_input_validation_test.go | 2 +- cli_test.go | 28 ++++++++++++++-------------- flag_config_validation_test.go | 2 +- flag_test.go | 2 +- help_test.go | 12 ++++++------ options_test.go | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/argument_config_validation_test.go b/argument_config_validation_test.go index ed75f0b..886f1f8 100644 --- a/argument_config_validation_test.go +++ b/argument_config_validation_test.go @@ -23,6 +23,6 @@ func TestArgument_validateConfig(t *testing.T) { t.Run("valid name", func(t *testing.T) { arg := &Argument{name: "valid-arg"} err := arg.validateConfig() - require.NoError(t, err) + assert.NoError(t, err) }) } diff --git a/argument_input_validation_test.go b/argument_input_validation_test.go index 787c6f2..760269e 100644 --- a/argument_input_validation_test.go +++ b/argument_input_validation_test.go @@ -14,5 +14,5 @@ func TestArgument_validateInput(t *testing.T) { assert.EqualError(t, arg.validateInput(), `argument "test-arg": argument missing value`) arg.value = "something" - require.NoError(t, arg.validateInput()) + assert.NoError(t, arg.validateInput()) } diff --git a/cli_test.go b/cli_test.go index c11ab16..b0faef6 100644 --- a/cli_test.go +++ b/cli_test.go @@ -43,7 +43,7 @@ func Test_git(t *testing.T) { called() gitDir, err := FlagValue[string](ctx, "git-dir") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "/path/to/something", gitDir) return nil @@ -58,7 +58,7 @@ func Test_git(t *testing.T) { called() gitDir, err := FlagValue[string](ctx, "git-dir") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "/path/to/something", gitDir) return nil @@ -83,7 +83,7 @@ func Test_git(t *testing.T) { called() message, err := FlagValue[string](ctx, "message") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "a commit message", message) return nil @@ -98,11 +98,11 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - require.NoError(t, err) + assert.NoError(t, err) assert.False(t, isAll) message, err := FlagValue[string](ctx, "message") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "a commit message", message) return nil @@ -117,11 +117,11 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - require.NoError(t, err) + assert.NoError(t, err) assert.False(t, isAll) message, err := FlagValue[string](ctx, "message") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "a commit message", message) return nil @@ -136,11 +136,11 @@ func Test_git(t *testing.T) { called() isAll, err := FlagValue[bool](ctx, "all") - require.NoError(t, err) + assert.NoError(t, err) assert.True(t, isAll) message, err := FlagValue[string](ctx, "message") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "a commit message", message) return nil @@ -155,7 +155,7 @@ func Test_git(t *testing.T) { called() branch, err := ArgValue[string](ctx, "branch") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "some-branch", branch) return nil @@ -170,11 +170,11 @@ func Test_git(t *testing.T) { called() branch, err := ArgValue[string](ctx, "branch") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, "some-branch", branch) isNewBranch, err := FlagValue[bool](ctx, "new-branch") - require.NoError(t, err) + assert.NoError(t, err) assert.True(t, isNewBranch) return nil @@ -189,7 +189,7 @@ func Test_git(t *testing.T) { called() globalGitignore, err := FlagValue[string](ctx, "global-gitignore") - require.NoError(t, err) + assert.NoError(t, err) assert.Equal(t, globalGitignore, "path/to/some/.gitignore") return nil } @@ -229,7 +229,7 @@ func Test_git(t *testing.T) { SetHandler(lo.IfF(testCase.gitHandler != nil, func() Handler { return testCase.gitHandler(t) }).Else(nil)), ) - require.NoError(t, err) + assert.NoError(t, err) assert.Nil(t, command.Run(context.TODO(), testCase.rawArgs)) }) } diff --git a/flag_config_validation_test.go b/flag_config_validation_test.go index 7a22d2e..f35f562 100644 --- a/flag_config_validation_test.go +++ b/flag_config_validation_test.go @@ -23,6 +23,6 @@ func TestFlag_validateConfig(t *testing.T) { t.Run("valid name", func(t *testing.T) { flag := &Flag{name: "valid-flag"} err := flag.validateConfig() - require.NoError(t, err) + assert.NoError(t, err) }) } diff --git a/flag_test.go b/flag_test.go index a99bfa2..f91cef1 100644 --- a/flag_test.go +++ b/flag_test.go @@ -17,7 +17,7 @@ func TestCommand_flagsUpToRoot(t *testing.T) { ), ) - require.NoError(t, err) + assert.NoError(t, err) flags := command.subCommands[0].flagsUpToRoot() flagNames := lo.Map(flags, func(flag *Flag, _ int) string { return flag.name }) diff --git a/help_test.go b/help_test.go index acbdb41..a43c212 100644 --- a/help_test.go +++ b/help_test.go @@ -38,10 +38,10 @@ func TestCommand_renderHelp(t *testing.T) { ), ) - require.NoError(t, err) + assert.NoError(t, err) buffer := new(bytes.Buffer) - require.NoError(t, command.renderHelp(buffer)) + assert.NoError(t, command.renderHelp(buffer)) assert.Equal(t, heredoc.Doc(` @@ -75,10 +75,10 @@ func TestCommand_renderHelp(t *testing.T) { AddSubCmd("some-command", "some command"), ) - require.NoError(t, err) + assert.NoError(t, err) buffer := new(bytes.Buffer) - require.NoError(t, command.renderHelp(buffer)) + assert.NoError(t, command.renderHelp(buffer)) assert.Equal(t, heredoc.Doc(` @@ -110,10 +110,10 @@ func TestCommand_renderHelp(t *testing.T) { ), ) - require.NoError(t, err) + assert.NoError(t, err) buffer := new(bytes.Buffer) - require.NoError(t, command.subCommands[0].renderHelp(buffer)) + assert.NoError(t, command.subCommands[0].renderHelp(buffer)) assert.Equal(t, heredoc.Doc(` diff --git a/options_test.go b/options_test.go index 1fd2ac7..24f22cd 100644 --- a/options_test.go +++ b/options_test.go @@ -30,7 +30,7 @@ func Test_options(t *testing.T) { SetHandler(func(context.Context) error { return nil }), ) - require.NoError(t, err) + assert.NoError(t, err) // Command assert.Equal(t, "http", httpCommand.name) From ba41ae78858f68d8b4123dd09ad9bff07f1eecb2 Mon Sep 17 00:00:00 2001 From: broothie Date: Sat, 28 Jun 2025 23:05:36 -0700 Subject: [PATCH 3/3] Remove unused require imports from test files --- argument_config_validation_test.go | 1 - cli_test.go | 1 - flag_config_validation_test.go | 1 - flag_test.go | 1 - help_test.go | 1 - options_test.go | 1 - 6 files changed, 6 deletions(-) diff --git a/argument_config_validation_test.go b/argument_config_validation_test.go index 886f1f8..6e7dabb 100644 --- a/argument_config_validation_test.go +++ b/argument_config_validation_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestArgument_validateConfig(t *testing.T) { diff --git a/cli_test.go b/cli_test.go index b0faef6..3795f3f 100644 --- a/cli_test.go +++ b/cli_test.go @@ -6,7 +6,6 @@ import ( "github.com/samber/lo" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func ensureCalled(t *testing.T) func() { diff --git a/flag_config_validation_test.go b/flag_config_validation_test.go index f35f562..c50d74e 100644 --- a/flag_config_validation_test.go +++ b/flag_config_validation_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestFlag_validateConfig(t *testing.T) { diff --git a/flag_test.go b/flag_test.go index f91cef1..b922b52 100644 --- a/flag_test.go +++ b/flag_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/samber/lo" ) diff --git a/help_test.go b/help_test.go index a43c212..13bc127 100644 --- a/help_test.go +++ b/help_test.go @@ -8,7 +8,6 @@ import ( "github.com/MakeNowJust/heredoc/v2" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type CustomType struct { diff --git a/options_test.go b/options_test.go index 24f22cd..0fd8eb9 100644 --- a/options_test.go +++ b/options_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func Test_options(t *testing.T) {