Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Dependencies to the stdlib #1971

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
53ba75b
add NoError function
asahasrabuddhe Aug 21, 2024
9104ba2
add Error and ErrorContains
asahasrabuddhe Aug 21, 2024
828f5df
move to internal testing package
asahasrabuddhe Aug 21, 2024
46a179e
replace assert.NoError
asahasrabuddhe Aug 21, 2024
4623b15
replace assert.Error
asahasrabuddhe Aug 21, 2024
34b20b3
fix condition failing tests
asahasrabuddhe Aug 21, 2024
ab2796b
replace assert.ErrorContains
asahasrabuddhe Aug 21, 2024
9d1f41c
add ErrorIs
asahasrabuddhe Aug 21, 2024
2011c1d
replace assert.ErrorIs
asahasrabuddhe Aug 21, 2024
3af5fec
add EqualError
asahasrabuddhe Aug 21, 2024
776614c
replace assert.EqualError
asahasrabuddhe Aug 21, 2024
76779f1
add Equal
asahasrabuddhe Aug 21, 2024
c23a2bc
replace assert.Equal
asahasrabuddhe Aug 21, 2024
0d305d2
add Contains
asahasrabuddhe Aug 21, 2024
f3f88f1
replace assert.Contains
asahasrabuddhe Aug 21, 2024
4931f52
add NotContains
asahasrabuddhe Aug 21, 2024
17c29b5
replace assert.NotContains
asahasrabuddhe Aug 21, 2024
91a39cc
add True and False
asahasrabuddhe Aug 21, 2024
62cd975
replace True and False
asahasrabuddhe Aug 21, 2024
94418a1
add Empty and NotEmpty
asahasrabuddhe Aug 21, 2024
318bae9
replace Empty and NotEmpty
asahasrabuddhe Aug 21, 2024
8db507e
fix Empty and NotEmpty
asahasrabuddhe Aug 21, 2024
5b130f5
add Nil
asahasrabuddhe Aug 21, 2024
82fc0ef
replace assert.Nil
asahasrabuddhe Aug 21, 2024
b19dd09
add NotNil
asahasrabuddhe Aug 21, 2024
5685be8
replace assert.NotNil
asahasrabuddhe Aug 21, 2024
30f3f7b
add Zero and NotZero
asahasrabuddhe Aug 21, 2024
a7b859c
replace Zero and NotZero
asahasrabuddhe Aug 21, 2024
b49f176
add Len
asahasrabuddhe Aug 21, 2024
dd33900
replace assert.Len
asahasrabuddhe Aug 21, 2024
d51678a
add JSONEq
asahasrabuddhe Aug 21, 2024
30455cd
replace assert.JSONEq
asahasrabuddhe Aug 21, 2024
19d46bf
add RequireEqual
asahasrabuddhe Aug 21, 2024
33017df
replace require.Equal
asahasrabuddhe Aug 21, 2024
8d1cd69
add RequireEqualf
asahasrabuddhe Aug 21, 2024
4cbf568
replace RequireEqualf
asahasrabuddhe Aug 21, 2024
bf54c90
add RequireErrorEqual
asahasrabuddhe Aug 21, 2024
c48a817
replace require.EqualError
asahasrabuddhe Aug 21, 2024
d39fbf0
add RequireError and RequireNoError
asahasrabuddhe Aug 21, 2024
ebc84f5
replace require.Error and require.NoError
asahasrabuddhe Aug 21, 2024
ae54da9
add RequireLen
asahasrabuddhe Aug 21, 2024
bc7c020
replace require.Len
asahasrabuddhe Aug 21, 2024
c4ee3ff
add RequireErrorContains
asahasrabuddhe Aug 21, 2024
6f051be
replace require.ErrorContains
asahasrabuddhe Aug 21, 2024
bad60dc
add RequireTrue and RequireFalse
asahasrabuddhe Aug 21, 2024
442a0ec
replace require.True and require.False
asahasrabuddhe Aug 21, 2024
46443db
add RequireContains and RequireNotContains
asahasrabuddhe Aug 21, 2024
6121dcf
replace require.Contains
asahasrabuddhe Aug 21, 2024
000d535
add RequireGreaterOrEqual
asahasrabuddhe Aug 22, 2024
aa51478
replace require.GreaterOrEqual
asahasrabuddhe Aug 22, 2024
1c24f3e
add RequireNotNil
asahasrabuddhe Aug 22, 2024
012427e
replace require.NotNil
asahasrabuddhe Aug 22, 2024
f3d1911
add RequireImplements
asahasrabuddhe Aug 22, 2024
88d756b
replace require.Implements
asahasrabuddhe Aug 22, 2024
809144f
add RequireTruef
asahasrabuddhe Aug 22, 2024
13ddfd7
remove require.New pt1
asahasrabuddhe Aug 22, 2024
2225432
add RequireNil
asahasrabuddhe Aug 22, 2024
b50ec9f
remove require.New() pt2
asahasrabuddhe Aug 22, 2024
49e8621
remove require.New() pt3
asahasrabuddhe Aug 22, 2024
05c4667
add RequireContainsf
asahasrabuddhe Aug 22, 2024
abde883
remove require.New() pt4
asahasrabuddhe Aug 22, 2024
a6b1265
zero dependencies!
asahasrabuddhe Aug 22, 2024
854eb7c
update code formatting
asahasrabuddhe Aug 22, 2024
ca564e0
add package comment
asahasrabuddhe Aug 22, 2024
fbc73e0
optimise GreaterOrEqual function
asahasrabuddhe Aug 22, 2024
241e0c6
cleanup Contains and NotContains
asahasrabuddhe Aug 22, 2024
7bf0162
shorten Empty and NotEmpty
asahasrabuddhe Aug 22, 2024
8b394ca
add doc comments for exported functions
asahasrabuddhe Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
itesting "github.com/urfave/cli/v3/internal/testing"
)

func TestArgumentsRootCommand(t *testing.T) {
Expand All @@ -30,20 +30,20 @@ func TestArgumentsRootCommand(t *testing.T) {
},
}

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "10"}))
require.Equal(t, int64(10), ival)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "10"}))
itesting.RequireEqual(t, int64(10), ival)

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "12", "10.1"}))
require.Equal(t, int64(12), ival)
require.Equal(t, []float64{10.1}, fvals)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "12", "10.1"}))
itesting.RequireEqual(t, int64(12), ival)
itesting.RequireEqual(t, []float64{10.1}, fvals)

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "13", "10.1", "11.09"}))
require.Equal(t, int64(13), ival)
require.Equal(t, []float64{10.1, 11.09}, fvals)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "13", "10.1", "11.09"}))
itesting.RequireEqual(t, int64(13), ival)
itesting.RequireEqual(t, []float64{10.1, 11.09}, fvals)

require.Error(t, errors.New("No help topic for '12.1"), cmd.Run(context.Background(), []string{"foo", "13", "10.1", "11.09", "12.1"}))
require.Equal(t, int64(13), ival)
require.Equal(t, []float64{10.1, 11.09}, fvals)
itesting.RequireError(t, errors.New("No help topic for '12.1"), cmd.Run(context.Background(), []string{"foo", "13", "10.1", "11.09", "12.1"}))
itesting.RequireEqual(t, int64(13), ival)
itesting.RequireEqual(t, []float64{10.1, 11.09}, fvals)
}

func TestArgumentsSubcommand(t *testing.T) {
Expand Down Expand Up @@ -81,16 +81,16 @@ func TestArgumentsSubcommand(t *testing.T) {
},
}

require.Error(t, errors.New("sufficient count of arg sa not provided, given 0 expected 1"), cmd.Run(context.Background(), []string{"foo", "subcmd", "2006-01-02T15:04:05Z"}))
itesting.RequireError(t, errors.New("sufficient count of arg sa not provided, given 0 expected 1"), cmd.Run(context.Background(), []string{"foo", "subcmd", "2006-01-02T15:04:05Z"}))

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "subcmd", "2006-01-02T15:04:05Z", "fubar"}))
require.Equal(t, time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC), tval)
require.Equal(t, []string{"fubar"}, svals)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "subcmd", "2006-01-02T15:04:05Z", "fubar"}))
itesting.RequireEqual(t, time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC), tval)
itesting.RequireEqual(t, []string{"fubar"}, svals)

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "subcmd", "--foo", "100", "2006-01-02T15:04:05Z", "fubar", "some"}))
require.Equal(t, int64(100), ifval)
require.Equal(t, time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC), tval)
require.Equal(t, []string{"fubar", "some"}, svals)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "subcmd", "--foo", "100", "2006-01-02T15:04:05Z", "fubar", "some"}))
itesting.RequireEqual(t, int64(100), ifval)
itesting.RequireEqual(t, time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC), tval)
itesting.RequireEqual(t, []string{"fubar", "some"}, svals)
}

func TestArgsUsage(t *testing.T) {
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestArgsUsage(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
arg.Min, arg.Max = test.min, test.max
require.Equal(t, test.expected, arg.Usage())
itesting.RequireEqual(t, test.expected, arg.Usage())
})
}
}
Expand All @@ -162,15 +162,15 @@ func TestSingleOptionalArg(t *testing.T) {
arg,
}

require.NoError(t, cmd.Run(context.Background(), []string{"foo"}))
require.Equal(t, "", s1)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo"}))
itesting.RequireEqual(t, "", s1)

arg.Value = "bar"
require.NoError(t, cmd.Run(context.Background(), []string{"foo"}))
require.Equal(t, "bar", s1)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo"}))
itesting.RequireEqual(t, "bar", s1)

require.NoError(t, cmd.Run(context.Background(), []string{"foo", "zbar"}))
require.Equal(t, "zbar", s1)
itesting.RequireNoError(t, cmd.Run(context.Background(), []string{"foo", "zbar"}))
itesting.RequireEqual(t, "zbar", s1)
}

func TestUnboundedArgs(t *testing.T) {
Expand Down Expand Up @@ -213,8 +213,8 @@ func TestUnboundedArgs(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
arg.Values = &test.values
require.NoError(t, cmd.Run(context.Background(), test.args))
require.Equal(t, test.expected, *arg.Values)
itesting.RequireNoError(t, cmd.Run(context.Background(), test.args))
itesting.RequireEqual(t, test.expected, *arg.Values)
})
}
}
7 changes: 3 additions & 4 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
itesting "github.com/urfave/cli/v3/internal/testing"
)

func expectFileContent(t *testing.T, file, got string) {
data, err := os.ReadFile(file)
// Ignore windows line endings
data = bytes.ReplaceAll(data, []byte("\r\n"), []byte("\n"))

r := require.New(t)
r.NoError(err)
r.Equal(got, string(data))
itesting.RequireNoError(t, err)
itesting.RequireEqual(t, got, string(data))
}

func buildTestContext(t *testing.T) context.Context {
Expand Down
Loading
Loading