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

Package defines -update flag even if golden package is unused #270

Closed
tadeokondrak opened this issue Jul 13, 2023 · 4 comments · Fixed by #271
Closed

Package defines -update flag even if golden package is unused #270

tadeokondrak opened this issue Jul 13, 2023 · 4 comments · Fixed by #271
Labels

Comments

@tadeokondrak
Copy link

We use gotest.tools/v3/assert right now and I'm happy with it.

I'd like to use github.com/hexops/autogold to automatically update tests with inline values, but if I try to use it and gotest.tools/v3/assert in the same package, initialization panics with flag redefined: update and tests don't run.

I'd understand that the problem might be impossible to fix if I were using both gotest.tools/v3/golden and autogold, but it feels like it should be possible to use gotest.tools/v3/assert and autogold together.

Would you be interested in a PR to fix this? Maybe the internal packages can be rearranged to only define the flag when golden is used.

@dnephin dnephin added the bug label Jul 14, 2023
@dnephin
Copy link
Member

dnephin commented Jul 14, 2023

Thank you for the bug report! I have been wondering if this flag would conflict at some point.

The reasons it's imported from /v3/assert is because assert.Equal has autogold style behaviour for string values. As long as the expected variable is named expected or expected<Something> that value can be updated with -update.

I imagine you might be using autogold for non-string values as well though.

I've got an idea for how to fix this using https://pkg.go.dev/flag#Lookup. Let me open a PR to see how it works.

@dnephin
Copy link
Member

dnephin commented Jul 14, 2023

I've opened #271. I tried it out , and it works as long as gotest.tools/v3 is imported after autogold. If autogold implements the same logic, then the import order won't matter.

Let me know if this works for you.

@tadeokondrak
Copy link
Author

Great, thanks! I'll take a look at getting autogold to do the same thing.

@tadeokondrak
Copy link
Author

With both packages patched everything works great. In my case autogold is imported second so #271 isn't actually being used yet, but it's good not to rely on import order.

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

Successfully merging a pull request may close this issue.

2 participants