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
24 changes: 16 additions & 8 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 @@ -17,9 +15,15 @@ fn help() {
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_stderr_data("").run();
cargo_process("search --help")
.with_stdout_contains("[..] --frozen [..]")
.with_stdout_data(
Copy link
Member

Choose a reason for hiding this comment

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

You could use str![] and regenerate snapshots by running this command SNAPSHOTS=overwrite cargo t --test testsuite help::

Suggested change
.with_stdout_data(
.with_stdout_data(str![])

This comment was marked as outdated.

This comment was marked as outdated.

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably delete this test because we have help UI tests for every command, like

https://github.com/rust-lang/cargo/blob/master/tests/testsuite/cargo_search/help/mod.rs

Copy link
Contributor Author

@choznerol choznerol Jun 15, 2024

Choose a reason for hiding this comment

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

Thanks. Removed the search --help cases in eef057e.

P.s. I left L11-16 untouched, as the exact command are slightly different from the existing UI tests.

"\
...
[..] --frozen [..]
...
",
)
.run();
}

Expand All @@ -41,7 +45,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 +151,7 @@ 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 [..]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we drop the [..]s? We are trying to move away from them where it makes sense because they get in the way of snapshot updating

Copy link
Contributor Author

@choznerol choznerol Jun 15, 2024

Choose a reason for hiding this comment

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

Removed in e5e9f2f, but in fact there is another issue #14076 with this test case. I mentioned that as well in the same commit.

Fixed in 8db30bc

.run_expect_error();

// Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage.
Expand All @@ -162,8 +166,12 @@ fn help_alias() {
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",
.with_stdout_data(
"\
...
-Z allow-features[..] Allow *only* the listed unstable features
...
",
)
.run();
Copy link
Contributor

Choose a reason for hiding this comment

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

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. Removed in 3fd3879.

}
Expand Down
Loading