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

cargo insta test error: unexpected argument '--color' found #473

Closed
NoodleSamaChan opened this issue Apr 3, 2024 · 3 comments · Fixed by #491
Closed

cargo insta test error: unexpected argument '--color' found #473

NoodleSamaChan opened this issue Apr 3, 2024 · 3 comments · Fixed by #491
Labels
bug Something isn't working

Comments

@NoodleSamaChan
Copy link

NoodleSamaChan commented Apr 3, 2024

What happened?

Whenever I try to run my insta tests, I receive an error message stating

error: unexpected argument '--color' found

Usage: integration_test-c206b9c74ed18dac [OPTIONS]

Caused by:
  process didn't exit successfully: `/Users/pong/target/debug/deps/integration_test-c206b9c74ed18dac --color=auto` (exit status: 2)
note: test exited abnormally; to see the full output pass --nocapture to the harness.

I am really unsure about this error message since I didn't include any argument, especially not anything such as --color.

Would you know if there's any fixes for such a problem?

If needed, please find here the link to the code which carries the bug: https://github.com/NoodleSamaChan/pong/tree/58287b1f64ffb6b7e0b184ce959bf998c3874f51

Please note that if I run cargo test and then cargo insta review, I am able to generate the snapshot.

Reproduction steps

  1. run 'cargo insta test'

Insta Version

1.38.0

rustc Version

1.77.0

No response

What did you expect?

I was expecting the tests to run and the snapshots to be generated and ready for review

@NoodleSamaChan NoodleSamaChan added the bug Something isn't working label Apr 3, 2024
@max-sixty
Copy link
Collaborator

It seems that parsing the cli args here is the cause.

On the one hand, it's probably not test best-practice to parse the CLI args in unit tests. On the other, insta shouldn't be interfering with that. And it's a very unfriendly error message.

This stems from a very old issue in cargo: rust-lang/cargo#1983.

In the meantime, a few options:

  • We could avoid passing anything if auto would be passed, reducing the number of cases where this breaks. But some combinations will still break. Would be really confusing if it works locally and then breaks in CI.
  • We could revert Pass --color=... to libtest #375 and always lose colors; e.g. in CI. (I guess cargo test never shows colors in CI?)
  • Accept the bug until upstream issues are resolved
  • I'm not sure there's anything better? I don't think it's possible to somehow detect that the CLI args are getting parsed. We could try and parse errors, check whether this error is raised, and offer a better error message. Seems finicky though.

@NoodleSamaChan
Copy link
Author

Thanks very much for the very prompt feedback, it's honestly really helpful ! I tried running everything once again while removing the CLI and it works perfectly now. : )

I apologise for my mistake, my problem is solved! Would you still like me to keep the issue open if you'd like to have a go at fixing it further on your side since you mentioned insta shouldn't be interfering with it anyway?

Cheers

@max-sixty
Copy link
Collaborator

Thanks @NoodleSamaChan !

Would you still like me to keep the issue open if you'd like to have a go at fixing it further on your side since you mentioned insta shouldn't be interfering with it anyway?

I defer to @mitsuhiko !

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

Successfully merging a pull request may close this issue.

2 participants