assert-rs / snapbox

Snapshot testing for a herd of CLI tests
docs.rs/trycmd
Apache License 2.0
138 stars 18 forks source link

Can not ust [EXE] in subcommand #197

Closed Rustin170506 closed 1 year ago

Rustin170506 commented 1 year ago
  1. use trycmd in rustup project
  2. create a test
    
    use rustup::utils::utils;

[test]

fn ui_tests() { let t = trycmd::TestCases::new(); let rustup_init = trycmd::cargo::cargo_bin("rustup-init"); let rustup = trycmd::cargo::cargo_bin("rustup"); t.register_bin("rustup-init", &rustup_init); // Copy rustup-init to rustup so that the tests can run it. utils::copy_file(&rustup_init, &rustup).unwrap(); t.register_bin("rustup", &rustup); t.case("tests/cli-ui/*.toml"); }

3. test the subcommand's help test
```toml
bin.name = "rustup"
args = ["set","auto-self-update","--help"]
stdout = """
rustup-set-auto-self-update
The rustup auto self update mode

USAGE:
    rustup[EXE] set auto-self-update <auto-self-update-mode>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <auto-self-update-mode>     [default: enable]  [possible values: enable, disable, check-only]
"""
stderr = ""
  1. If I change the first line to rustup[EXE]-set-auto-self-update
  2. Run the test with TRYCMD=overwrite, it will delete the [EXE]
  3. If I don't put the EXE into the subcommand help text, then you will get an error:

Testing tests\cli-ui\rustup_set_cmd_auto-self-update_cmd_help_flag_stdout.toml ... failed Exit: success

---- expected: stdout ++++ actual: stdout 1 - rustup-set-auto-self-update 1 + rustup[EXE]-set-auto-self-update 2 2 | The rustup auto self update mode 3 3 | 4 4 | USAGE: 5 - rustup set auto-self-update 5 + rustup[EXE] set auto-self-update 6 6 | 7 7 | FLAGS: 8 8 | -h, --help Prints help information 9 9 | -V, --version Prints version information 10 10 | 11 11 | ARGS: 12 12 | [default: enable] [possible values: enable, disable, check-only]



See: https://github.com/rust-lang/rustup/actions/runs/4150479617/jobs/7180163449
Rustin170506 commented 1 year ago

Now, I just use ... as a workaround.

Rustin170506 commented 1 year ago

I see, this seems a bug of clap. https://github.com/clap-rs/clap/pull/3693

epage commented 1 year ago

Want to take on updating from clap 2 to clap 4?