Skip to content

Commit

Permalink
Split test into multiple runs to make it more self documenting
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Jul 1, 2024
1 parent f1e1987 commit 890d3ee
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3230,30 +3230,34 @@ func TestCommand_Value(t *testing.T) {
subCmd,
},
}
err := cmd.Run(buildTestContext(t), []string{"main", "--top-flag", "13", "test", "--myflag", "14"})
assert.NoError(t, err)
t.Run("flag name", func(t *testing.T) {
r := require.New(t)
err := cmd.Run(buildTestContext(t), []string{"main", "--top-flag", "13", "test", "--myflag", "14"})

r := require.New(t)
r.Equal(int64(13), cmd.Value("top-flag"))
r.Equal(int64(13), cmd.Value("t"))
r.Equal(int64(13), cmd.Value("tf"))
r.NoError(err)
r.Equal(int64(13), cmd.Value("top-flag"))
r.Equal(int64(13), cmd.Value("t"))
r.Equal(int64(13), cmd.Value("tf"))

r.Equal(int64(14), subCmd.Value("myflag"))
r.Equal(int64(14), subCmd.Value("m"))
r.Equal(int64(14), subCmd.Value("mf"))
r.Equal(int64(14), subCmd.Value("myflag"))
r.Equal(int64(14), subCmd.Value("m"))
r.Equal(int64(14), subCmd.Value("mf"))
})

// use only aliases here
err = cmd.Run(buildTestContext(t), []string{"main", "-tf", "15", "test", "-m", "16"})
assert.NoError(t, err)
t.Run("flag aliases", func(t *testing.T) {
r := require.New(t)
err := cmd.Run(buildTestContext(t), []string{"main", "-tf", "15", "test", "-m", "16"})

r.Equal(int64(15), cmd.Value("top-flag"))
r.Equal(int64(15), cmd.Value("t"))
r.Equal(int64(15), cmd.Value("tf"))
r.NoError(err)
r.Equal(int64(15), cmd.Value("top-flag"))
r.Equal(int64(15), cmd.Value("t"))
r.Equal(int64(15), cmd.Value("tf"))

r.Equal(int64(16), subCmd.Value("myflag"))
r.Equal(int64(16), subCmd.Value("m"))
r.Equal(int64(16), subCmd.Value("mf"))
r.Nil(cmd.Value("unknown-flag"))
r.Equal(int64(16), subCmd.Value("myflag"))
r.Equal(int64(16), subCmd.Value("m"))
r.Equal(int64(16), subCmd.Value("mf"))
r.Nil(cmd.Value("unknown-flag"))
})
}

func TestCommand_Value_InvalidFlagAccessHandler(t *testing.T) {
Expand Down

0 comments on commit 890d3ee

Please sign in to comment.