Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go, testing: consider shrinking set of characters allowed/passed through in subtest names #73116

Open
dmitshur opened this issue Apr 1, 2025 · 1 comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Apr 1, 2025

This issue is meant to capture a small finding from #73086, and it's related to the cluster of proposals like #67562 (and its earlier version #45549), #27896, possibly more like #44970, #20209, #20210, #20115, and so on. Also #60977. It's not a proposal in its current form as that needs a more holistic analysis.

Right now there are some characters permitted to be used in subtest names that might cause problems for other systems that need to process go test -json output, including the Unicode replacement character U+FFFD:

package main

import (
	"strconv"
	"testing"
)

func Test(t *testing.T) {
	const r = '\uFFFD' // https://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character
	t.Run(string(r), func(t *testing.T) {
		t.Logf("Hello, %U.", r)
		if strconv.IsPrint(r) {
			t.Logf("%q is a printable rune.", r)
		}
	})

	// Output:
	// === RUN   Test
	// === RUN   Test/�
	//     prog_test.go:11: Hello, U+FFFD.
	//     prog_test.go:13: '�' is a printable rune.
	// --- PASS: Test (0.00s)
	//     --- PASS: Test/� (0.00s)
	// PASS
}

(playground link: https://go.dev/play/p/unQcgsua0J3)

Also potentially worth considering are subtest names that use different Unicode normalization, which the current basic rewriting of equal subtest names doesn't catch: https://go.dev/play/p/xut7W4Cp4p_g.

Said programs can (and do) deal with this by escaping on their end, but this issue is to investigate whether a future version of the go command can do better, perhaps by disallowing or rewriting subtest names.

Note that a subtest name is often used in combination with other parts needed to uniquely identify a test, which have corresponding existing constraints:

CC @matloob, @samthanawalla.

@dmitshur dmitshur added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 1, 2025
@dmitshur dmitshur added this to the Backlog milestone Apr 1, 2025
@patrickmeiring
Copy link

A further point: go subtest names are separated by forward slashes in go test output ('/'), but these separators cannot be reliably identified by downstream systems as the subtest names passed t.Run(...) are allowed to contain a slash (and these slashes are not escaped or encoded). This makes it error prone for tools to interpret the hierarchy of subtest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants