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:
committed by
Brad Fitzpatrick
parent
0f02c20c5e
commit
5ef3713c9f
+23
-23
@@ -16,77 +16,77 @@ func TestCompare(t *testing.T) {
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "both empty",
|
||||
name: "both-empty",
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "v1 empty",
|
||||
name: "v1-empty",
|
||||
v2: "1.2.3",
|
||||
want: -1,
|
||||
},
|
||||
{
|
||||
name: "v2 empty",
|
||||
name: "v2-empty",
|
||||
v1: "1.2.3",
|
||||
want: 1,
|
||||
},
|
||||
|
||||
{
|
||||
name: "semver major",
|
||||
name: "semver-major",
|
||||
v1: "2.0.0",
|
||||
v2: "1.9.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver major",
|
||||
name: "semver-major",
|
||||
v1: "2.0.0",
|
||||
v2: "1.9.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver minor",
|
||||
name: "semver-minor",
|
||||
v1: "1.9.0",
|
||||
v2: "1.8.9",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver patch",
|
||||
name: "semver-patch",
|
||||
v1: "1.9.9",
|
||||
v2: "1.9.8",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "semver equal",
|
||||
name: "semver-equal",
|
||||
v1: "1.9.8",
|
||||
v2: "1.9.8",
|
||||
want: 0,
|
||||
},
|
||||
|
||||
{
|
||||
name: "tailscale major",
|
||||
name: "tailscale-major",
|
||||
v1: "1.0-0",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale minor",
|
||||
name: "tailscale-minor",
|
||||
v1: "0.98-0",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale patch",
|
||||
name: "tailscale-patch",
|
||||
v1: "0.97-120",
|
||||
v2: "0.97-105",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "tailscale equal",
|
||||
name: "tailscale-equal",
|
||||
v1: "0.97-105",
|
||||
v2: "0.97-105",
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "tailscale weird extra field",
|
||||
name: "tailscale-weird-extra-field",
|
||||
v1: "0.96.1-0", // more fields == larger
|
||||
v2: "0.96-105",
|
||||
want: 1,
|
||||
@@ -96,7 +96,7 @@ func TestCompare(t *testing.T) {
|
||||
// of strconv.ParseUint with these characters would have lead us to
|
||||
// panic. We're now only looking at ascii numbers, so test these are
|
||||
// compared as text.
|
||||
name: "only ascii numbers",
|
||||
name: "only-ascii-numbers",
|
||||
v1: "۱۱", // 2x EXTENDED ARABIC-INDIC DIGIT ONE
|
||||
v2: "۲", // 1x EXTENDED ARABIC-INDIC DIGIT TWO
|
||||
want: -1,
|
||||
@@ -104,55 +104,55 @@ func TestCompare(t *testing.T) {
|
||||
|
||||
// A few specific OS version tests below.
|
||||
{
|
||||
name: "windows version",
|
||||
name: "windows-version",
|
||||
v1: "10.0.19045.3324",
|
||||
v2: "10.0.18362",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "windows 11 is everything above 10.0.22000",
|
||||
name: "windows-11-above-10_0_22000",
|
||||
v1: "10.0.22631.2262",
|
||||
v2: "10.0.22000",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "android short version",
|
||||
name: "android-short-version",
|
||||
v1: "10",
|
||||
v2: "7",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "android longer version",
|
||||
name: "android-longer-version",
|
||||
v1: "7.1.2",
|
||||
v2: "7",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "iOS version",
|
||||
name: "iOS-version",
|
||||
v1: "15.6.1",
|
||||
v2: "15.6",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Linux short kernel version",
|
||||
name: "linux-short-kernel-version",
|
||||
v1: "4.4.302+",
|
||||
v2: "4.0",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Linux long kernel version",
|
||||
name: "linux-long-kernel-version",
|
||||
v1: "4.14.255-311-248.529.amzn2.x86_64",
|
||||
v2: "4.0",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "FreeBSD version",
|
||||
name: "freebsd-version",
|
||||
v1: "14.0-CURRENT",
|
||||
v2: "14",
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "Synology version",
|
||||
name: "synology-version",
|
||||
v1: "Synology 6.2.4; kernel=3.10.105",
|
||||
v2: "Synology 6",
|
||||
want: 1,
|
||||
|
||||
Reference in New Issue
Block a user