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

main: improve test flag handling #3151

Merged
merged 1 commit into from
Jun 29, 2023
Merged

main: improve test flag handling #3151

merged 1 commit into from
Jun 29, 2023

Conversation

jrick
Copy link
Member

@jrick jrick commented Jun 29, 2023

A TestMain func is added to parse the test executable's flags. Before running all tests, any flags that it did not parse (in particular, those following a double hyphen (--) which the flag package will stop parsing after) are retained in the modified os.Args value. This allows the tests that exercise go-flags options to test these options with any user-provided flags prepended.

One such use case for this fix is to change the default appdata directory that tests will use, which allows tests to succeed when the default home directory is read only. For example:

go test . -args -- --appdata=/some/other/appdata

This well cause the go-flags tests to perform their tests with their own options being tested following the appdata change.

Fixes #3150.

A TestMain func is added to parse the test executable's flags.  Before running
all tests, any flags that it did not parse (in particular, those following a
double hyphen (--) which the flag package will stop parsing after) are retained
in the modified os.Args value.  This allows the tests that exercise go-flags
options to test these options with any user-provided flags prepended.

One such use case for this fix is to change the default appdata directory that
tests will use, which allows tests to succeed when the default home directory is
read only.  For example:

go test . -args -- --appdata=/some/other/appdata

This well cause the go-flags tests to perform their tests with their own options
being tested following the appdata change.
@davecgh davecgh merged commit 39e2cc2 into decred:master Jun 29, 2023
@jrick jrick deleted the testflags branch June 29, 2023 01:21
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

Successfully merging this pull request may close these issues.

Unable to override home directory
2 participants