Skip to content

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

@dmitshur

Description

@dmitshur

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions