Skip to content

Commit c77e4ea

Browse files
committed
Auto merge of #13879 - weihanglo:test, r=Muscraft
test: clean up unnecessary uses of `match_exact` It was found during the review of <#13842 (comment)> We should be happy using `assert_match_exact` directly. The extra arguments to `match_exact` are not necessary for those test cases.
2 parents 451d384 + 88ac4aa commit c77e4ea

File tree

3 files changed

+25
-64
lines changed

3 files changed

+25
-64
lines changed

tests/testsuite/artifact_dep.rs

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests specific to artifact dependencies, designated using
22
//! the new `dep = { artifact = "bin", … }` syntax in manifests.
33
4-
use cargo_test_support::compare::match_exact;
4+
use cargo_test_support::compare;
55
use cargo_test_support::registry::{Package, RegistryBuilder};
66
use cargo_test_support::{
77
basic_bin_manifest, basic_manifest, cross_compile, project, publish, registry, rustc_host,
@@ -593,35 +593,27 @@ fn build_script_with_bin_artifacts() {
593593
.run();
594594

595595
let build_script_output = build_script_output_string(&p, "foo");
596-
let msg = "we need the binary directory for this artifact along with all binary paths";
596+
// we need the binary directory for this artifact along with all binary paths
597597
if cfg!(target_env = "msvc") {
598-
match_exact(
598+
compare::assert_match_exact(
599599
"[..]/artifact/bar-[..]/bin/baz.exe\n\
600600
[..]/artifact/bar-[..]/staticlib/bar-[..].lib\n\
601601
[..]/artifact/bar-[..]/cdylib/bar.dll\n\
602602
[..]/artifact/bar-[..]/bin\n\
603603
[..]/artifact/bar-[..]/bin/bar.exe\n\
604604
[..]/artifact/bar-[..]/bin/bar.exe",
605605
&build_script_output,
606-
msg,
607-
"",
608-
None,
609606
)
610-
.unwrap();
611607
} else {
612-
match_exact(
608+
compare::assert_match_exact(
613609
"[..]/artifact/bar-[..]/bin/baz-[..]\n\
614610
[..]/artifact/bar-[..]/staticlib/libbar-[..].a\n\
615611
[..]/artifact/bar-[..]/cdylib/[..]bar.[..]\n\
616612
[..]/artifact/bar-[..]/bin\n\
617613
[..]/artifact/bar-[..]/bin/bar-[..]\n\
618614
[..]/artifact/bar-[..]/bin/bar-[..]",
619615
&build_script_output,
620-
msg,
621-
"",
622-
None,
623616
)
624-
.unwrap();
625617
}
626618

627619
assert!(
@@ -783,31 +775,22 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {
783775
.run();
784776

785777
let build_script_output = build_script_output_string(&p, "foo");
786-
let msg = "we need the binary directory for this artifact and the binary itself";
787-
778+
// we need the binary directory for this artifact and the binary itself
788779
if cfg!(target_env = "msvc") {
789-
cargo_test_support::compare::match_exact(
780+
compare::assert_match_exact(
790781
&format!(
791782
"[..]/artifact/bar-baz-[..]/bin\n\
792783
[..]/artifact/bar-baz-[..]/bin/baz_suffix{}",
793784
std::env::consts::EXE_SUFFIX,
794785
),
795786
&build_script_output,
796-
msg,
797-
"",
798-
None,
799-
)
800-
.unwrap();
787+
);
801788
} else {
802-
cargo_test_support::compare::match_exact(
789+
compare::assert_match_exact(
803790
"[..]/artifact/bar-baz-[..]/bin\n\
804791
[..]/artifact/bar-baz-[..]/bin/baz_suffix-[..]",
805792
&build_script_output,
806-
msg,
807-
"",
808-
None,
809-
)
810-
.unwrap();
793+
);
811794
}
812795

813796
assert!(
@@ -1757,14 +1740,7 @@ fn allow_dep_renames_with_multiple_versions() {
17571740
.with_stderr_contains("[COMPILING] foo [..]")
17581741
.run();
17591742
let build_script_output = build_script_output_string(&p, "foo");
1760-
match_exact(
1761-
"0.5.0\n1.0.0",
1762-
&build_script_output,
1763-
"build script output",
1764-
"",
1765-
None,
1766-
)
1767-
.unwrap();
1743+
compare::assert_match_exact("0.5.0\n1.0.0", &build_script_output);
17681744
}
17691745

17701746
#[cargo_test]
@@ -3240,26 +3216,18 @@ fn build_only_specified_artifact_library() {
32403216
.cargo("build -Z bindeps")
32413217
.masquerade_as_nightly_cargo(&["bindeps"])
32423218
.run();
3243-
match_exact(
3219+
compare::assert_match_exact(
32443220
"cdylib present: true\nstaticlib present: false",
32453221
&build_script_output_string(&cdylib, "foo"),
3246-
"build script output",
3247-
"",
3248-
None,
3249-
)
3250-
.unwrap();
3222+
);
32513223

32523224
let staticlib = create_project("staticlib");
32533225
staticlib
32543226
.cargo("build -Z bindeps")
32553227
.masquerade_as_nightly_cargo(&["bindeps"])
32563228
.run();
3257-
match_exact(
3229+
compare::assert_match_exact(
32583230
"cdylib present: false\nstaticlib present: true",
32593231
&build_script_output_string(&staticlib, "foo"),
3260-
"build script output",
3261-
"",
3262-
None,
3263-
)
3264-
.unwrap();
3232+
);
32653233
}

tests/testsuite/config.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cargo::util::context::{
66
};
77
use cargo::CargoResult;
88
use cargo_test_support::compare;
9-
use cargo_test_support::{panic_error, paths, project, symlink_supported, t};
9+
use cargo_test_support::{paths, project, symlink_supported, t};
1010
use cargo_util_schemas::manifest::TomlTrimPaths;
1111
use cargo_util_schemas::manifest::TomlTrimPathsValue;
1212
use cargo_util_schemas::manifest::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
@@ -222,14 +222,7 @@ pub fn assert_error<E: Borrow<anyhow::Error>>(error: E, msgs: &str) {
222222
})
223223
.collect::<Vec<_>>()
224224
.join("\n\n");
225-
assert_match(msgs, &causes);
226-
}
227-
228-
#[track_caller]
229-
pub fn assert_match(expected: &str, actual: &str) {
230-
if let Err(e) = compare::match_exact(expected, actual, "output", "", None) {
231-
panic_error("", e);
232-
}
225+
compare::assert_match_exact(msgs, &causes);
233226
}
234227

235228
#[cargo_test]
@@ -297,7 +290,7 @@ f1 = 1
297290
let expected = "\
298291
[WARNING] `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
299292
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`";
300-
assert_match(expected, &output);
293+
compare::assert_match_exact(expected, &output);
301294
}
302295

303296
#[cargo_test]
@@ -323,7 +316,7 @@ f1 = 1
323316

324317
// It should NOT have warned for the symlink.
325318
let output = read_output(gctx);
326-
assert_match("", &output);
319+
compare::assert_match_exact("", &output);
327320
}
328321

329322
#[cargo_test]
@@ -349,7 +342,7 @@ f1 = 1
349342

350343
// It should NOT have warned for the symlink.
351344
let output = read_output(gctx);
352-
assert_match("", &output);
345+
compare::assert_match_exact("", &output);
353346
}
354347

355348
#[cargo_test]
@@ -375,7 +368,7 @@ f1 = 1
375368

376369
// It should NOT have warned for this situation.
377370
let output = read_output(gctx);
378-
assert_match("", &output);
371+
compare::assert_match_exact("", &output);
379372
}
380373

381374
#[cargo_test]
@@ -405,7 +398,7 @@ f1 = 2
405398
let expected = "\
406399
[WARNING] both `[..]/.cargo/config` and `[..]/.cargo/config.toml` exist. Using `[..]/.cargo/config`
407400
";
408-
assert_match(expected, &output);
401+
compare::assert_match_exact(expected, &output);
409402
}
410403

411404
#[cargo_test]
@@ -439,7 +432,7 @@ unused = 456
439432
let expected = "\
440433
warning: unused config key `S.unused` in `[..]/.cargo/config.toml`
441434
";
442-
assert_match(expected, &output);
435+
compare::assert_match_exact(expected, &output);
443436
}
444437

445438
#[cargo_test]

tests/testsuite/config_cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Tests for the --config CLI option.
22
33
use super::config::{
4-
assert_error, assert_match, read_output, write_config_at, write_config_toml,
5-
GlobalContextBuilder,
4+
assert_error, read_output, write_config_at, write_config_toml, GlobalContextBuilder,
65
};
76
use cargo::util::context::Definition;
7+
use cargo_test_support::compare;
88
use cargo_test_support::paths;
99
use std::{collections::HashMap, fs};
1010

@@ -344,7 +344,7 @@ fn unused_key() {
344344
let expected = "\
345345
warning: unused config key `build.unused` in `--config cli option`
346346
";
347-
assert_match(expected, &output);
347+
compare::assert_match_exact(expected, &output);
348348
}
349349

350350
#[cargo_test]

0 commit comments

Comments
 (0)