Skip to content

Commit 844457c

Browse files
committed
Auto merge of #14577 - epage:tests-basic, r=weihanglo
test: Migrate remaining with_stdout/with_stderr calls ### What does this PR try to resolve? This is part of #14039 and is another step towards us not needing our own redaction logic. Along the way, I switched us to using `expect` to make it easier to tell when `allow(deprecated)` should be removed. ### How should we test and review this PR? ### Additional information
2 parents 5e44da4 + 7ab9320 commit 844457c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+159
-172
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cargo-credential-macos-keychain = { version = "0.4.7", path = "credential/cargo-
3131
cargo-credential-wincred = { version = "0.4.7", path = "credential/cargo-credential-wincred" }
3232
cargo-platform = { path = "crates/cargo-platform", version = "0.1.5" }
3333
cargo-test-macro = { version = "0.3.0", path = "crates/cargo-test-macro" }
34-
cargo-test-support = { version = "0.4.0", path = "crates/cargo-test-support" }
34+
cargo-test-support = { version = "0.5.0", path = "crates/cargo-test-support" }
3535
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
3636
cargo-util-schemas = { version = "0.6.0", path = "crates/cargo-util-schemas" }
3737
cargo_metadata = "0.18.1"

crates/cargo-test-support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-test-support"
3-
version = "0.4.1"
3+
version = "0.5.0"
44
edition.workspace = true
55
rust-version = "1.81" # MSRV:1
66
license.workspace = true

crates/cargo-test-support/src/compare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! # Deprecated comparisons
44
//!
55
//! Cargo's tests are in transition from internal-only pattern and normalization routines used in
6-
//! asserts like [`crate::Execs::with_stdout`] to [`assert_e2e`] and [`assert_ui`].
6+
//! asserts like [`crate::Execs::with_stdout_contains`] to [`assert_e2e`] and [`assert_ui`].
77
//!
88
//! ## Patterns
99
//!
@@ -208,7 +208,7 @@ fn add_regex_redactions(subs: &mut snapbox::Redactions) {
208208
.unwrap();
209209
subs.insert(
210210
"[FILE_NUM]",
211-
regex!(r"\[(REMOVED|SUMMARY)\] (?<redacted>[0-9]+) files"),
211+
regex!(r"\[(REMOVED|SUMMARY)\] (?<redacted>[1-9][0-9]*) files"),
212212
)
213213
.unwrap();
214214
subs.insert(

crates/cargo-test-support/src/lib.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,10 @@ impl Project {
472472
/// # Example:
473473
///
474474
/// ```no_run
475+
/// # use cargo_test_support::str;
475476
/// # let p = cargo_test_support::project().build();
476477
/// p.process(&p.bin("foo"))
477-
/// .with_stdout("bar\n")
478+
/// .with_stdout_data(str!["bar\n"])
478479
/// .run();
479480
/// ```
480481
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs {
@@ -644,9 +645,7 @@ struct RawOutput {
644645
pub struct Execs {
645646
ran: bool,
646647
process_builder: Option<ProcessBuilder>,
647-
expect_stdout: Option<String>,
648648
expect_stdin: Option<String>,
649-
expect_stderr: Option<String>,
650649
expect_exit_code: Option<i32>,
651650
expect_stdout_data: Option<snapbox::Data>,
652651
expect_stderr_data: Option<snapbox::Data>,
@@ -673,22 +672,6 @@ impl Execs {
673672

674673
/// # Configure assertions
675674
impl Execs {
676-
/// Verifies that stdout is equal to the given lines.
677-
/// See [`compare`] for supported patterns.
678-
#[deprecated(note = "replaced with `Execs::with_stdout_data(expected)`")]
679-
pub fn with_stdout<S: ToString>(&mut self, expected: S) -> &mut Self {
680-
self.expect_stdout = Some(expected.to_string());
681-
self
682-
}
683-
684-
/// Verifies that stderr is equal to the given lines.
685-
/// See [`compare`] for supported patterns.
686-
#[deprecated(note = "replaced with `Execs::with_stderr_data(expected)`")]
687-
pub fn with_stderr<S: ToString>(&mut self, expected: S) -> &mut Self {
688-
self.expect_stderr = Some(expected.to_string());
689-
self
690-
}
691-
692675
/// Verifies that stdout is equal to the given lines.
693676
///
694677
/// See [`compare::assert_e2e`] for assertion details.
@@ -1058,9 +1041,7 @@ impl Execs {
10581041
#[track_caller]
10591042
fn verify_checks_output(&self, stdout: &[u8], stderr: &[u8]) {
10601043
if self.expect_exit_code.unwrap_or(0) != 0
1061-
&& self.expect_stdout.is_none()
10621044
&& self.expect_stdin.is_none()
1063-
&& self.expect_stderr.is_none()
10641045
&& self.expect_stdout_data.is_none()
10651046
&& self.expect_stderr_data.is_none()
10661047
&& self.expect_stdout_contains.is_empty()
@@ -1154,12 +1135,6 @@ impl Execs {
11541135
),
11551136
}
11561137

1157-
if let Some(expect_stdout) = &self.expect_stdout {
1158-
compare::match_exact(expect_stdout, stdout, "stdout", stderr, cwd)?;
1159-
}
1160-
if let Some(expect_stderr) = &self.expect_stderr {
1161-
compare::match_exact(expect_stderr, stderr, "stderr", stdout, cwd)?;
1162-
}
11631138
if let Some(expect_stdout_data) = &self.expect_stdout_data {
11641139
if let Err(err) = self.assert.try_eq(
11651140
Some(&"stdout"),
@@ -1227,8 +1202,6 @@ pub fn execs() -> Execs {
12271202
Execs {
12281203
ran: false,
12291204
process_builder: None,
1230-
expect_stdout: None,
1231-
expect_stderr: None,
12321205
expect_stdin: None,
12331206
expect_exit_code: Some(0),
12341207
expect_stdout_data: None,

crates/cargo-test-support/src/registry.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! ```no_run
66
//! use cargo_test_support::registry::Package;
77
//! use cargo_test_support::project;
8+
//! use cargo_test_support::str;
89
//!
910
//! // Publish package "a" depending on "b".
1011
//! Package::new("a", "1.0.0")
@@ -38,7 +39,7 @@
3839
//! "#)
3940
//! .build();
4041
//!
41-
//! p.cargo("run").with_stdout("24").run();
42+
//! p.cargo("run").with_stdout_data(str!["24"]).run();
4243
//! ```
4344
4445
use crate::git::repo;

tests/testsuite/artifact_dep.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ fn build_script_with_bin_artifact_and_lib_false() {
687687
)
688688
.build();
689689

690-
#[allow(deprecated)]
690+
#[expect(deprecated)]
691691
p.cargo("build -Z bindeps")
692692
.masquerade_as_nightly_cargo(&["bindeps"])
693693
.with_status(101)
@@ -731,7 +731,7 @@ fn lib_with_bin_artifact_and_lib_false() {
731731
)
732732
.build();
733733

734-
#[allow(deprecated)]
734+
#[expect(deprecated)]
735735
p.cargo("build -Z bindeps")
736736
.masquerade_as_nightly_cargo(&["bindeps"])
737737
.with_status(101)
@@ -1117,7 +1117,7 @@ fn build_script_deps_adopt_specified_target_unconditionally() {
11171117
.file("bar/src/lib.rs", "pub fn doit() {}")
11181118
.build();
11191119

1120-
#[allow(deprecated)]
1120+
#[expect(deprecated)]
11211121
p.cargo("check -v -Z bindeps")
11221122
.masquerade_as_nightly_cargo(&["bindeps"])
11231123
.with_stderr_does_not_contain(format!(
@@ -1237,7 +1237,7 @@ fn non_build_script_deps_adopt_specified_target_unconditionally() {
12371237
.file("bar/src/lib.rs", "pub fn doit() {}")
12381238
.build();
12391239

1240-
#[allow(deprecated)]
1240+
#[expect(deprecated)]
12411241
p.cargo("check -v -Z bindeps")
12421242
.masquerade_as_nightly_cargo(&["bindeps"])
12431243
.with_stderr_contains(format!(
@@ -1385,7 +1385,7 @@ fn build_script_deps_adopts_target_platform_if_target_equals_target() {
13851385
.build();
13861386

13871387
let alternate_target = cross_compile::alternate();
1388-
#[allow(deprecated)]
1388+
#[expect(deprecated)]
13891389
p.cargo("check -v -Z bindeps --target")
13901390
.arg(alternate_target)
13911391
.masquerade_as_nightly_cargo(&["bindeps"])

tests/testsuite/build.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn cargo_compile_incremental() {
132132
.run();
133133
}
134134

135-
#[allow(deprecated)]
135+
#[expect(deprecated)]
136136
#[cargo_test]
137137
fn incremental_profile() {
138138
let p = project()
@@ -176,7 +176,7 @@ fn incremental_profile() {
176176
.run();
177177
}
178178

179-
#[allow(deprecated)]
179+
#[expect(deprecated)]
180180
#[cargo_test]
181181
fn incremental_config() {
182182
let p = project()
@@ -1524,7 +1524,6 @@ fn ignores_carriage_return_in_lockfile() {
15241524
p.cargo("build").run();
15251525
}
15261526

1527-
#[allow(deprecated)]
15281527
#[cargo_test]
15291528
fn cargo_default_env_metadata_env_var() {
15301529
// Ensure that path dep + dylib + env_var get metadata
@@ -4124,7 +4123,7 @@ fn panic_abort_compiles_with_panic_abort() {
41244123
.run();
41254124
}
41264125

4127-
#[allow(deprecated)]
4126+
#[expect(deprecated)]
41284127
#[cargo_test]
41294128
fn compiler_json_error_format() {
41304129
let p = project()
@@ -4314,7 +4313,7 @@ fn wrong_message_format_option() {
43144313
.run();
43154314
}
43164315

4317-
#[allow(deprecated)]
4316+
#[expect(deprecated)]
43184317
#[cargo_test]
43194318
fn message_format_json_forward_stderr() {
43204319
let p = project()
@@ -5177,7 +5176,7 @@ WRAPPER CALLED: rustc --crate-name foo [..]
51775176
.run();
51785177
}
51795178

5180-
#[allow(deprecated)]
5179+
#[expect(deprecated)]
51815180
#[cargo_test]
51825181
fn rustc_wrapper_queries() {
51835182
// Check that the invocations querying rustc for information are done with the wrapper.
@@ -5917,7 +5916,7 @@ fn build_filter_infer_profile() {
59175916
.run();
59185917
}
59195918

5920-
#[allow(deprecated)]
5919+
#[expect(deprecated)]
59215920
#[cargo_test]
59225921
fn targets_selected_default() {
59235922
let p = project().file("src/main.rs", "fn main() {}").build();
@@ -6871,7 +6870,7 @@ Caused by:
68716870
.run();
68726871
}
68736872

6874-
#[allow(deprecated)]
6873+
#[expect(deprecated)]
68756874
#[cargo_test]
68766875
fn build_script_o0_default() {
68776876
let p = project()
@@ -6884,7 +6883,7 @@ fn build_script_o0_default() {
68846883
.run();
68856884
}
68866885

6887-
#[allow(deprecated)]
6886+
#[expect(deprecated)]
68886887
#[cargo_test]
68896888
fn build_script_o0_default_even_with_release() {
68906889
let p = project()

tests/testsuite/build_script.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3779,7 +3779,7 @@ fn custom_target_dir() {
37793779
p.cargo("build -v").run();
37803780
}
37813781

3782-
#[allow(deprecated)]
3782+
#[expect(deprecated)]
37833783
#[cargo_test]
37843784
fn panic_abort_with_build_scripts() {
37853785
let p = project()

tests/testsuite/build_script_extra_link_arg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ the future. For more information, see <https://github.com/rust-lang/cargo/issues
233233
.run();
234234
}
235235

236-
#[allow(deprecated)]
236+
#[expect(deprecated)]
237237
#[cargo_test]
238238
fn link_arg_transitive_not_allowed() {
239239
// Verify that transitive dependencies don't pass link args.

tests/testsuite/cache_messages.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ WRAPPER CALLED: rustc [..]
527527
.run();
528528
}
529529

530-
#[allow(deprecated)]
530+
#[expect(deprecated)]
531531
#[cargo_test]
532532
fn wacky_hashless_fingerprint() {
533533
// On Windows, executables don't have hashes. This checks for a bad

tests/testsuite/cargo_command.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn list_command_looks_at_path_case_mismatch() {
137137
);
138138
}
139139

140-
#[allow(deprecated)]
140+
#[expect(deprecated)]
141141
#[cargo_test]
142142
fn list_command_handles_known_external_commands() {
143143
let p = project()
@@ -358,7 +358,6 @@ fn override_cargo_home() {
358358
assert!(paths::root().join("foo2/.git").is_dir());
359359
}
360360

361-
#[allow(deprecated)]
362361
#[cargo_test]
363362
fn cargo_subcommand_env() {
364363
let src = format!(
@@ -390,7 +389,7 @@ fn cargo_subcommand_env() {
390389

391390
cargo_process("envtest")
392391
.env("PATH", &path)
393-
.with_stdout(cargo.to_str().unwrap())
392+
.with_stdout_data(format!("{}\n", cargo.to_str().unwrap()).raw())
394393
.run();
395394

396395
// Check that subcommands inherit an overridden $CARGO
@@ -403,7 +402,7 @@ fn cargo_subcommand_env() {
403402
cargo_process("envtest")
404403
.env("PATH", &path)
405404
.env(cargo::CARGO_ENV, &envtest_bin)
406-
.with_stdout(envtest_bin)
405+
.with_stdout_data(format!("{}\n", envtest_bin).raw().raw())
407406
.run();
408407
}
409408

tests/testsuite/check.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn check_all() {
406406
.run();
407407
}
408408

409-
#[allow(deprecated)]
409+
#[expect(deprecated)]
410410
#[cargo_test]
411411
fn check_all_exclude() {
412412
let p = project()
@@ -433,7 +433,7 @@ fn check_all_exclude() {
433433
.run();
434434
}
435435

436-
#[allow(deprecated)]
436+
#[expect(deprecated)]
437437
#[cargo_test]
438438
fn check_all_exclude_glob() {
439439
let p = project()
@@ -491,7 +491,7 @@ fn check_virtual_all_implied() {
491491
.run();
492492
}
493493

494-
#[allow(deprecated)]
494+
#[expect(deprecated)]
495495
#[cargo_test]
496496
fn check_virtual_manifest_one_project() {
497497
let p = project()
@@ -518,7 +518,7 @@ fn check_virtual_manifest_one_project() {
518518
.run();
519519
}
520520

521-
#[allow(deprecated)]
521+
#[expect(deprecated)]
522522
#[cargo_test]
523523
fn check_virtual_manifest_glob() {
524524
let p = project()
@@ -559,7 +559,7 @@ fn exclude_warns_on_non_existing_package() {
559559
.run();
560560
}
561561

562-
#[allow(deprecated)]
562+
#[expect(deprecated)]
563563
#[cargo_test]
564564
fn targets_selected_default() {
565565
let foo = project()
@@ -633,7 +633,7 @@ error[E0425]: cannot find value `badtext` in this scope
633633
.run();
634634
}
635635

636-
#[allow(deprecated)]
636+
#[expect(deprecated)]
637637
// Verify what is checked with various command-line filters.
638638
#[cargo_test]
639639
fn check_filters() {
@@ -1000,7 +1000,7 @@ WRAPPER CALLED: rustc --crate-name foo [..]
10001000
.run();
10011001
}
10021002

1003-
#[allow(deprecated)]
1003+
#[expect(deprecated)]
10041004
#[cargo_test]
10051005
fn rustc_workspace_wrapper_respects_primary_units() {
10061006
let p = project()
@@ -1024,7 +1024,7 @@ fn rustc_workspace_wrapper_respects_primary_units() {
10241024
.run();
10251025
}
10261026

1027-
#[allow(deprecated)]
1027+
#[expect(deprecated)]
10281028
#[cargo_test]
10291029
fn rustc_workspace_wrapper_excludes_published_deps() {
10301030
let p = project()

0 commit comments

Comments
 (0)