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
proposal: cmd/go: add -testlabel to print a label on the test package names #60128
Comments
Change https://go.dev/cl/494498 mentions this issue: |
As far as I am aware, the only use-case we have for this at the moment is in |
One advantage of doing it in cmd/go is that it can easily transform the text format as well. See, for example, CL 494407. Before this change, dist test prints inscrutable blocks like:
With this change, it prints:
These package names are also dist's internal test names now, so if you want to reproduce, you can do, e.g., dist test -run (This doesn't do much for your argument that dist may be the only user of this.) |
A possible alternative proposal for As a possible line directive: //go:testvariant <variant name> <alternative build or test settings for the test> Or registered at runtime: package p_test
import "testing"
func init() {
testing.RegisterTestAlternative("<variant name>", [...])
}
func TestA(t *testing .T) { [...] } Such that by default If something like that were available, the special case registration done in Of course this -label (or -testlabel as written in proposal title) flag for Perhaps some large Go projects that currently have a Makefile with multiple targets of differing |
For the proposed flag and behavior, this seems very reasonable and cleaner than dist doing the JSON event post-processing itself, at the cost of one additional fairly unobtrusive flag added to It might help to initially constrain the permitted characters (and possibly max length) in the label value. It'll be easy to expand the allowed set if allowing more characters turns out to be worthwhile, not so easy to take it back otherwise. |
@aclements, I think that for the inscrutable Maybe something more like:
|
@bcmills, that's pretty reasonable for the text output. We still need some way to distinguish the test variants in the JSON output, preferably in a way that existing CI systems can immediately take advantage of. Were you thinking we'd still do the pkg:variant renaming in the JSON output, but just show the command for the text output? (If we have the logic to print the command, maybe we also inject some Action:"output" record to the JSON with the command...) For some context, originally I'd proposed test label support in cmd/go to @rsc as a dist-specific back door, largely because we control both cmd/dist and cmd/go and it's much less annoying to implement this in cmd/go and also much easier to test. |
I hadn't really though that far into it, but that sounds like a pretty reasonable approach to me. 😅 |
Retracted for now; we'll do what we need in cmd/dist and get some experience. |
For reference, CL 494958 does what we need in dist using a stdout filter. |
This proposal has been declined as retracted. |
When running go test with various different settings, it can be useful to distinguish those results from others in the test output. I propose we add a new
go test
flag-label=arg
that will add:arg
to the printed package names in test results, soThis label would also be included in the Package field in go test -json output. This is particularly useful when running a test in different modes in a larger wrapper - it avoids the need to post-process the JSON output to adjust the names to keep different modes separated.
A different option would be to indicate the label some other way, such as an extra JSON field, but currently tooling that understands test2json separates different tests running in parallel by the Package field. If we break that invariant we'd probably want to introduce an ID field that would hold a random identifier chosen for each test2json invocation, to allow disentangling merged streams of JSON output. Given the choice, I think I'd rather just use the :arg syntax in the Package.
/cc @aclements @bcmills
The text was updated successfully, but these errors were encountered: