cmd/vet: add subtestnames analyzer; fix all existing violations

Add a new vet analyzer that checks t.Run subtest names don't contain
characters requiring quoting when re-running via "go test -run". This
enforces the style guide rule: don't use spaces or punctuation in
subtest names.

The analyzer flags:
- Direct t.Run calls with string literal names containing spaces,
  regex metacharacters, quotes, or other problematic characters
- Table-driven t.Run(tt.name, ...) calls where tt ranges over a
  slice/map literal with bad name field values

Also fix all 978 existing violations across 81 test files, replacing
spaces with hyphens and shortening long sentence-like names to concise
hyphenated forms.

Updates #19242

Change-Id: Ib0ad96a111bd8e764582d1d4902fe2599454ab65
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2026-04-04 21:32:14 +00:00
committed by Brad Fitzpatrick
parent 0f02c20c5e
commit 5ef3713c9f
87 changed files with 1405 additions and 982 deletions
+65 -65
View File
@@ -22,7 +22,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms",
name: "increment-ms",
start: time.Unix(12345, 1000),
step: 1000,
wants: []time.Time{
@@ -33,7 +33,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
},
},
{
name: "increment second",
name: "increment-second",
start: time.Unix(12345, 1000),
step: time.Second,
wants: []time.Time{
@@ -44,7 +44,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
},
},
{
name: "no increment",
name: "no-increment",
start: time.Unix(12345, 1000),
wants: []time.Time{
time.Unix(12345, 1000),
@@ -91,7 +91,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
wants []time.Duration // The return values of sequential calls to Now() after added to Start()
}{
{
name: "increment ms",
name: "increment-ms",
step: 1000,
wants: []time.Duration{
0,
@@ -101,7 +101,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
},
},
{
name: "increment second",
name: "increment-second",
step: time.Second,
wants: []time.Duration{
0 * time.Second,
@@ -111,7 +111,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
},
},
{
name: "no increment",
name: "no-increment",
wants: []time.Duration{0, 0, 0, 0},
},
}
@@ -177,7 +177,7 @@ func TestClockSetStep(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then s",
name: "increment-ms-then-s",
start: time.Unix(12345, 1000),
step: 1000,
stepChanges: []stepInfo{
@@ -198,7 +198,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "multiple changes over time",
name: "multiple-changes-over-time",
start: time.Unix(12345, 1000),
step: 1,
stepChanges: []stepInfo{
@@ -227,7 +227,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "multiple changes at once",
name: "multiple-changes-at-once",
start: time.Unix(12345, 1000),
step: 1,
stepChanges: []stepInfo{
@@ -252,7 +252,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
step: 0,
stepChanges: []stepInfo{
@@ -325,7 +325,7 @@ func TestClockAdvance(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then advance 1s",
name: "increment-ms-then-advance-1s",
start: time.Unix(12345, 1000),
step: 1000,
advances: []advanceInfo{
@@ -346,7 +346,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "multiple advances over time",
name: "multiple-advances-over-time",
start: time.Unix(12345, 1000),
step: 1,
advances: []advanceInfo{
@@ -375,7 +375,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "multiple advances at once",
name: "multiple-advances-at-once",
start: time.Unix(12345, 1000),
step: 1,
advances: []advanceInfo{
@@ -400,7 +400,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
step: 5,
advances: []advanceInfo{
@@ -489,7 +489,7 @@ func TestSingleTicker(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -500,7 +500,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
period: time.Second,
@@ -514,7 +514,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -526,7 +526,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -538,7 +538,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
period: time.Second,
@@ -553,7 +553,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
period: time.Second,
@@ -568,7 +568,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick per advance",
name: "single-tick-per-advance",
start: time.Unix(12345, 0),
period: 3 * time.Second,
steps: []testStep{
@@ -597,7 +597,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick per step",
name: "single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
period: 3 * time.Second,
@@ -626,7 +626,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "multiple tick per advance",
name: "multiple-tick-per-advance",
start: time.Unix(12345, 0),
period: time.Second,
channelSize: 3,
@@ -655,7 +655,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "multiple tick per step",
name: "multiple-tick-per-step",
start: time.Unix(12345, 0),
step: 3 * time.Second,
period: 2 * time.Second,
@@ -723,7 +723,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
period: 2 * time.Second,
steps: []testStep{
@@ -763,7 +763,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
period: 2 * time.Second,
@@ -803,7 +803,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
period: 2 * time.Second,
@@ -841,7 +841,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
period: 2 * time.Second,
@@ -965,7 +965,7 @@ func TestSingleTimer(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -976,7 +976,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
delay: time.Second,
@@ -990,7 +990,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1006,7 +1006,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1022,7 +1022,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
delay: time.Second,
@@ -1040,7 +1040,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
delay: time.Second,
@@ -1058,7 +1058,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset for single tick per advance",
name: "reset-for-single-tick-per-advance",
start: time.Unix(12345, 0),
delay: 3 * time.Second,
steps: []testStep{
@@ -1093,7 +1093,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset for single tick per step",
name: "reset-for-single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -1124,7 +1124,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while active",
name: "reset-while-active",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -1155,7 +1155,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop after fire",
name: "stop-after-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1181,7 +1181,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop before fire",
name: "stop-before-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1207,7 +1207,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop after reset",
name: "stop-after-reset",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1235,7 +1235,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
delay: 2 * time.Second,
steps: []testStep{
@@ -1275,7 +1275,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -1310,7 +1310,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -1344,7 +1344,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
delay: 2 * time.Second,
@@ -1705,7 +1705,7 @@ func TestClockFollowRealTime(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then advance 1s",
name: "increment-ms-then-advance-1s",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1750,7 +1750,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "multiple advances over time",
name: "multiple-advances-over-time",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1795,7 +1795,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "multiple advances at once",
name: "multiple-advances-at-once",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1828,7 +1828,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1861,7 +1861,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "start from current time",
name: "start-from-current-time",
realTimeClockOpts: ClockOpts{
Start: time.Unix(12345, 0),
},
@@ -1966,7 +1966,7 @@ func TestAfterFunc(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1977,7 +1977,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
delay: time.Second,
@@ -1991,7 +1991,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -2007,7 +2007,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -2023,7 +2023,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
delay: time.Second,
@@ -2041,7 +2041,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
delay: time.Second,
@@ -2059,7 +2059,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset for single tick per advance",
name: "reset-for-single-tick-per-advance",
start: time.Unix(12345, 0),
delay: 3 * time.Second,
steps: []testStep{
@@ -2094,7 +2094,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset for single tick per step",
name: "reset-for-single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -2125,7 +2125,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while active",
name: "reset-while-active",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -2156,7 +2156,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop after fire",
name: "stop-after-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2182,7 +2182,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop before fire",
name: "stop-before-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2208,7 +2208,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop after reset",
name: "stop-after-reset",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2236,7 +2236,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
delay: 2 * time.Second,
steps: []testStep{
@@ -2270,7 +2270,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -2303,7 +2303,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -2333,7 +2333,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
delay: 2 * time.Second,