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

test: migrate help to snapbox #14060

Merged
merged 7 commits into from
Jun 15, 2024
26 changes: 6 additions & 20 deletions tests/testsuite/help.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Tests for cargo's help output.

#![allow(deprecated)]

use cargo_test_support::registry::Package;
use cargo_test_support::{basic_manifest, cargo_exe, cargo_process, paths, process, project};
use std::fs;
Expand All @@ -16,11 +14,6 @@ fn help() {
cargo_process("help build").run();
cargo_process("build -h").run();
cargo_process("help help").run();
// Ensure that help output goes to stdout, not stderr.
cargo_process("search --help").with_stderr("").run();
cargo_process("search --help")
.with_stdout_contains("[..] --frozen [..]")
.run();
}

#[cargo_test]
Expand All @@ -41,7 +34,7 @@ fn help_external_subcommand() {
.publish();
cargo_process("install cargo-fake-help").run();
cargo_process("help fake-help")
.with_stdout("fancy help output\n")
.with_stdout_data("fancy help output\n")
.run();
}

Expand Down Expand Up @@ -147,7 +140,11 @@ fn help_alias() {
// The `empty-alias` returns an error.
cargo_process("help empty-alias")
.env("PATH", Path::new(""))
.with_stderr_contains("[..]The subcommand 'empty-alias' wasn't recognized[..]")
.with_stderr_data("The subcommand 'empty-alias' wasn't recognized

FIXME: #14076 This assertion isn't working, as this line should have caused a test failure but didn't.
",
)
.run_expect_error();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.with_stderr_data("The subcommand 'empty-alias' wasn't recognized
FIXME: #14076 This assertion isn't working, as this line should have caused a test failure but didn't.
",
)
.run_expect_error();
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no such command: `empty-alias`
Did you mean `empty-alias`?
View all installed commands with `cargo --list`
Find a package to install `empty-alias` with `cargo search cargo-empty-alias`
"#]])
.run();

Something like this should work. See #14076 (comment).

(just realized that the error message regressed…)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind posting another PR fixing #14076 and then update this afterward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just get SNAPSHOTS=overwrite working and pushed 8db30bc.

Would you mind posting another PR fixing #14076 and then update this afterward?

Sure! Will address #14076 first with #14078, and then resolve the conflict here.


// Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage.
Expand All @@ -157,14 +154,3 @@ fn help_alias() {
let out = help_with_stdout_and_path("complex-alias", Path::new(""));
assert_eq!(out, "`complex-alias` is aliased to `build --release`\n");
}

#[cargo_test]
fn alias_z_flag_help() {
for cmd in ["build", "run", "check", "test", "b", "r", "c", "t"] {
cargo_process(&format!("{cmd} -Z help"))
.with_stdout_contains(
" -Z allow-features[..] Allow *only* the listed unstable features",
)
.run();
}
}