From 1bee20875a466b369fadb3733e642340db36da3d Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 16 Aug 2026 08:36:31 -0400 Subject: [PATCH] test: fix ineffective mutex error-string assertion and add mirror cases The assertion checking the mutually exclusive error string used t.Logf instead of t.Errorf, so a wrong error message never failed the test. This masked that the message reports the flag's primary name (Names()[0]) rather than the alias typed on the command line. Align the expectation with the actual (and codebase-consistent) behavior. Also add coverage for cross-group combinations where the conflicting flag is not the first member of its group: --i --q and --s --q. --- flag_mutex_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/flag_mutex_test.go b/flag_mutex_test.go index b6c9a161c5..114ab57c44 100644 --- a/flag_mutex_test.go +++ b/flag_mutex_test.go @@ -1,7 +1,6 @@ package cli import ( - "strings" "testing" "github.com/stretchr/testify/assert" @@ -58,7 +57,12 @@ func TestFlagMutuallyExclusiveFlags(t *testing.T) { { name: "set both flags", args: []string{"--i", "11", "--ai", "12"}, - errStr: "option i cannot be set along with option ai", + errStr: "option i cannot be set along with option t", + }, + { + name: "set both flags second member", + args: []string{"--i", "11", "--q"}, + errStr: "option i cannot be set along with option q", }, { name: "required none set", @@ -73,7 +77,7 @@ func TestFlagMutuallyExclusiveFlags(t *testing.T) { { name: "required both set", args: []string{"--i", "11", "--ai", "12"}, - errStr: "option i cannot be set along with option ai", + errStr: "option i cannot be set along with option t", required: true, }, { @@ -82,6 +86,12 @@ func TestFlagMutuallyExclusiveFlags(t *testing.T) { errStr: "option i cannot be set along with option q", required: true, }, + { + name: "required both set second member both groups", + args: []string{"--s", "value", "--q"}, + errStr: "option s cannot be set along with option q", + required: true, + }, { name: "set env var", required: true, @@ -113,9 +123,7 @@ func TestFlagMutuallyExclusiveFlags(t *testing.T) { switch err.(type) { case (*mutuallyExclusiveGroup), (*mutuallyExclusiveGroupRequiredFlag): - if !strings.Contains(err.Error(), test.errStr) { - t.Logf("Invalid error string %v", err) - } + assert.Contains(t, err.Error(), test.errStr) default: t.Errorf("got invalid error type %T", err) }