- use trycmd in rustup project
- 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");
}
- test the subcommand's help test
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 = ""
- If I change the first line to
rustup[EXE]-set-auto-self-update
- Run the test with
TRYCMD=overwrite , it will delete the [EXE]
- 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 <auto-self-update-mode>
5 + rustup[EXE] set auto-self-update <auto-self-update-mode>
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 | <auto-self-update-mode> [default: enable] [possible values: enable, disable, check-only]
See: https://github.com/rust-lang/rustup/actions/runs/4150479617/jobs/7180163449
rustup[EXE]-set-auto-self-updateTRYCMD=overwrite, it will delete the[EXE]EXEinto the subcommand help text, then you will get an error:See: https://github.com/rust-lang/rustup/actions/runs/4150479617/jobs/7180163449