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

--rerun-fails doesn't work when --packages specifies a source file #398

Open
martijnvans opened this issue Apr 10, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@martijnvans
Copy link

The error message is an opaque package command-line-arguments is not in std. Here's a simple repro:

$ cat go.mod
module my_module

go 1.23
$ cat my_test.go
package my

import  "testing"

func TestFail(t *testing.T) {
        t.Fatalf("msg")
}

$ gotestsum --debug --packages=my_module --rerun-fails=2 # works
$ gotestsum --debug --packages=my_test.go --rerun-fails=2 # fails, see below output
exec: [go test -json my_test.go]
go test pid: 2695782
✖  command-line-arguments (15ms)

DONE 1 tests, 1 failure in 0.347s

exec: [go test -json -test.run=^TestFail$ command-line-arguments]
go test pid: 2695942
package command-line-arguments is not in std (/usr/lib/<snip>/command-line-arguments)

=== Failed
=== FAIL: command-line-arguments TestFail (0.00s)
    my_test.go:8: msg

=== Errors
package command-line-arguments is not in std (/usr/lib/<snip>/command-line-arguments)

DONE 2 runs, 1 tests, 1 failure, 1 error in 0.355s
ERROR rerun aborted because previous run had errors

It looks to me like the error comes from

pkg: tc.Package,
, in which the package that a particular failure occurs in gets pulled out of the test JSON, incorrectly in this case.

I'm not sure what the right fix is. Naively, you could just stop setting pkg: tc.Package, and that would fall back to the set of packages set on the command line and would probably fix my issue. However, it might cause issues in cases where you have multiple tests with the same name across the list of packages. You'd end up rerunning all of them instead of just rerunning that test within an individual package. I'll leave it up to you to decide whether that's worth it.

Right now my automation is trying to use --rerun-fails but it can't, not without restructuring to put each source file into its own subdirectory to work around this issue.

@dnephin dnephin added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels May 30, 2024
@dnephin
Copy link
Member

dnephin commented May 30, 2024

Thank you for the bug report! I did not realize that go test also accepted file namess, but I tried it and it does attempt to run them. All the files I have fail because they require symbols from other files in the package, but I can imagine this works in some cases.

I think at the very least gotestsum could notice when the arg is a filename and give a better error, but it may also be possible to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants