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

test-explorer: test binary complains flags not defined #263

Closed
xhd2015 opened this issue Sep 20, 2024 · 1 comment
Closed

test-explorer: test binary complains flags not defined #263

xhd2015 opened this issue Sep 20, 2024 · 1 comment

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Sep 20, 2024

The following test:

package args

func TestArgs(t *testing.T){
    t.Logf("args: %v", os.Args)
}

When run with:

go test -v ./ -args a b c

Will print a list of test flags like -test.v, along with a b c.

However, when run with

go test -v ./ -args -a b c

The program complains about flag a provided but not defined

@xhd2015
Copy link
Owner Author

xhd2015 commented Sep 20, 2024

The reason is that, when go emits test binary, the binary itself will invoke flag.Parse(), which then will try to parse all flags on the command line, even when the program itself will parse these flags correctly.

To suppress this behavior, we just need to add a -- after -args, which will then prevent flag.Parse() from consuming the reminder args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant