Skip to content

flag_mutex_test.go: ineffective error-string assertion masks wrong error message #2404

Closed

Description

@dearchap

Found while reviewing #2386.

Bug in test harness (flag_mutex_test.go:107): the assertion checking the error string uses t.Logf instead of t.Errorf/require.Contains:

if !strings.Contains(err.Error(), test.errStr) {
    t.Logf("Invalid error string %v", err)
}

So a wrong error message never fails the test. This is currently masking a real discrepancy: the "set both flags" case passes --i 11 --ai 12 and expects "option i cannot be set along with option ai", but the actual error is "option i cannot be set along with option t". MutuallyExclusiveFlags.check uses f.Names()[0], which returns the primary name (t), not the alias used on the CLI (ai).

Fix: change the assertion to t.Errorf (or assert.Contains(t, err.Error(), test.errStr)) so wrong messages fail, and decide whether the message should reference the flag name as typed on the command line (alias ai) rather than the primary name.

Test coverage gap (related): the regression test added in #2386 (--i --q) only covers "first member of group 0 × second member of group 1". The mirror cases — second member of group 0 (--s --q), and the issue-reproduction layout where the conflicting flag is the second member of both groups — are untested. Recommend adding at least one such case to pin the cross-group fix.

Activity

  1. chjnett commented on Aug 16, 2026

    @chjnett

    Opened #2409 — the mutually exclusive flag check now reports the name the user actually typed (the alias) instead of the primary name, and the test assertion now uses t.Errorf so a wrong message actually fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions