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
@@ -13,12 +13,12 @@ func TestEscape(t *testing.T) {
|
||||
name, input, want string
|
||||
}{
|
||||
{
|
||||
name: "no illegal chars",
|
||||
name: "no-illegal-chars",
|
||||
input: "/home/user",
|
||||
want: "/home/user",
|
||||
},
|
||||
{
|
||||
name: "empty string",
|
||||
name: "empty-string",
|
||||
input: "",
|
||||
want: "\"\"",
|
||||
},
|
||||
@@ -38,12 +38,12 @@ func TestEscape(t *testing.T) {
|
||||
want: "\"\n\"",
|
||||
},
|
||||
{
|
||||
name: "double quote",
|
||||
name: "double-quote",
|
||||
input: "\"",
|
||||
want: "\"\\\"\"",
|
||||
},
|
||||
{
|
||||
name: "single quote",
|
||||
name: "single-quote",
|
||||
input: "'",
|
||||
want: "\"'\"",
|
||||
},
|
||||
@@ -53,12 +53,12 @@ func TestEscape(t *testing.T) {
|
||||
want: "\"\\\\\"",
|
||||
},
|
||||
{
|
||||
name: "greater than",
|
||||
name: "greater-than",
|
||||
input: ">",
|
||||
want: "\">\"",
|
||||
},
|
||||
{
|
||||
name: "less than",
|
||||
name: "less-than",
|
||||
input: "<",
|
||||
want: "\"<\"",
|
||||
},
|
||||
@@ -93,7 +93,7 @@ func TestEscape(t *testing.T) {
|
||||
want: "\"*\"",
|
||||
},
|
||||
{
|
||||
name: "question mark",
|
||||
name: "question-mark",
|
||||
input: "?",
|
||||
want: "\"?\"",
|
||||
},
|
||||
@@ -103,12 +103,12 @@ func TestEscape(t *testing.T) {
|
||||
want: "\"#\"",
|
||||
},
|
||||
{
|
||||
name: "open paren",
|
||||
name: "open-paren",
|
||||
input: "(",
|
||||
want: "\"(\"",
|
||||
},
|
||||
{
|
||||
name: "close paren",
|
||||
name: "close-paren",
|
||||
input: ")",
|
||||
want: "\")\"",
|
||||
},
|
||||
@@ -118,17 +118,17 @@ func TestEscape(t *testing.T) {
|
||||
want: "\"\\`\"",
|
||||
},
|
||||
{
|
||||
name: "char without escape",
|
||||
name: "char-without-escape",
|
||||
input: "/home/user\t",
|
||||
want: "\"/home/user\t\"",
|
||||
},
|
||||
{
|
||||
name: "char with escape",
|
||||
name: "char-with-escape",
|
||||
input: "/home/user\\",
|
||||
want: "\"/home/user\\\\\"",
|
||||
},
|
||||
{
|
||||
name: "all illegal chars",
|
||||
name: "all-illegal-chars",
|
||||
input: "/home/user" + needsEscape,
|
||||
want: "\"/home/user \t\n\\\"'\\\\><~|&;\\$*?#()\\`\"",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user