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

Fix "test" subcommand's pass-through arguments #12

Merged
merged 1 commit into from
Apr 14, 2024

Conversation

cpick
Copy link

@cpick cpick commented Apr 13, 2024

The cargo-zigbuild "test" subcommand has an optional, trailing positional TESTNAME argument. This arg sometimes contains a test name filter and sometimes just another flag that should be passed through to the underlying test binary.

For example these work fine (even if args has unexpected contents):

  1. cargo-zigbuild test or cargo-zigbuild test --: test_name: None args: []
  2. cargo-zigbuild test foo or cargo-zigbuild test -- foo: test_name: Some("foo") args: []
  3. cargo-zigbuild test foo bar baz, cargo-zigbuild test -- foo bar baz, or cargo-zigbuild test foo -- bar baz: test_name: Some("foo") args: ["bar", "baz"]

However this does not work (as a result of an unexpected test_name):
4. cargo-zigbuild test -- --nocapture: test_name: Some("--nocapture") args: []

This is becaue cargo-zigbuild test will pass --nocapture through to cargo test without prefixing it with a -- separator (since it mistakenly treats it as a test name filter, not an additional argument).

Likewise the following fails for similar reasons:
5. cargo-zigbuild test -- --nocapture --include-ignored: test_name: Some("--nocapture") args: ["--include-ignored"]

But the following works (since it includes a non-arg test_name):
6. cargo-zigbuild test -- foo --nocapture --include-ignored or cargo-zigbuild test foo -- --nocapture --include-ignored: test_name: Some("foo") args: ["--nocapture", "--include-ignored"]

In all of the above, the cargo "test" subcommand will do the right thing if a -- separator is placed before any test name and/or additional arguments (and also if neither are present). So always pass the separator before either of those.

Fixes: rust-cross/cargo-zigbuild#240

The `cargo-zigbuild` "test" subcommand has an optional, trailing
positional TESTNAME argument. This arg sometimes contains a test name
filter and sometimes just another flag that should be passed through to
the underlying test binary.

For example these work fine (even if `args` has unexpected contents):
1. `cargo-zigbuild test` or `cargo-zigbuild test --`:
   test_name: None args: []
2. `cargo-zigbuild test foo` or `cargo-zigbuild test -- foo`:
   test_name: Some("foo") args: []
3. `cargo-zigbuild test foo bar baz`,
   `cargo-zigbuild test -- foo bar baz`, or
   `cargo-zigbuild test foo -- bar baz`:
   test_name: Some("foo") args: ["bar", "baz"]

However this does not work (as a result of an unexpected `test_name`):
4. `cargo-zigbuild test -- --nocapture`:
   test_name: Some("--nocapture") args: []

This is becaue `cargo-zigbuild test` will pass `--nocapture` through to
`cargo test` without prefixing it with a `--` separator (since it
mistakenly treats it as a test name filter, not an additional argument).

Likewise the following fails for similar reasons:
5. `cargo-zigbuild test -- --nocapture --include-ignored`:
   test_name: Some("--nocapture") args: ["--include-ignored"]

But the following works (since it includes a non-arg test_name):
6. `cargo-zigbuild test -- foo --nocapture --include-ignored` or
   `cargo-zigbuild test foo -- --nocapture --include-ignored`:
   test_name: Some("foo") args: ["--nocapture", "--include-ignored"]

In all of the above, the `cargo` "test" subcommand will do the right
thing if a `--` separator is placed before any test name and/or
additional arguments (and also if neither are present). So always pass
the separator before either of those.

Fixes: rust-cross/cargo-zigbuild#240
@messense messense merged commit 6fbe884 into messense:main Apr 14, 2024
10 checks passed
@cpick cpick deleted the fix-arg-separator branch April 14, 2024 14:43
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.

cargo-zigbuild test doesn't pass arguments through properly
2 participants