Skip to content

Commit

Permalink
Auto merge of #13879 - weihanglo:test, r=Muscraft
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 7, 2024
2 parents 451d384 + 88ac4aa commit c77e4ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 64 deletions.
60 changes: 14 additions & 46 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests specific to artifact dependencies, designated using
//! the new `dep = { artifact = "bin", … }` syntax in manifests.
use cargo_test_support::compare::match_exact;
use cargo_test_support::compare;
use cargo_test_support::registry::{Package, RegistryBuilder};
use cargo_test_support::{
basic_bin_manifest, basic_manifest, cross_compile, project, publish, registry, rustc_host,
Expand Down Expand Up @@ -593,35 +593,27 @@ fn build_script_with_bin_artifacts() {
.run();

let build_script_output = build_script_output_string(&p, "foo");
let msg = "we need the binary directory for this artifact along with all binary paths";
// we need the binary directory for this artifact along with all binary paths
if cfg!(target_env = "msvc") {
match_exact(
compare::assert_match_exact(
"[..]/artifact/bar-[..]/bin/baz.exe\n\
[..]/artifact/bar-[..]/staticlib/bar-[..].lib\n\
[..]/artifact/bar-[..]/cdylib/bar.dll\n\
[..]/artifact/bar-[..]/bin\n\
[..]/artifact/bar-[..]/bin/bar.exe\n\
[..]/artifact/bar-[..]/bin/bar.exe",
&build_script_output,
msg,
"",
None,
)
.unwrap();
} else {
match_exact(
compare::assert_match_exact(
"[..]/artifact/bar-[..]/bin/baz-[..]\n\
[..]/artifact/bar-[..]/staticlib/libbar-[..].a\n\
[..]/artifact/bar-[..]/cdylib/[..]bar.[..]\n\
[..]/artifact/bar-[..]/bin\n\
[..]/artifact/bar-[..]/bin/bar-[..]\n\
[..]/artifact/bar-[..]/bin/bar-[..]",
&build_script_output,
msg,
"",
None,
)
.unwrap();
}

assert!(
Expand Down Expand Up @@ -783,31 +775,22 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {
.run();

let build_script_output = build_script_output_string(&p, "foo");
let msg = "we need the binary directory for this artifact and the binary itself";

// we need the binary directory for this artifact and the binary itself
if cfg!(target_env = "msvc") {
cargo_test_support::compare::match_exact(
compare::assert_match_exact(
&format!(
"[..]/artifact/bar-baz-[..]/bin\n\
[..]/artifact/bar-baz-[..]/bin/baz_suffix{}",
std::env::consts::EXE_SUFFIX,
),
&build_script_output,
msg,
"",
None,
)
.unwrap();
);
} else {
cargo_test_support::compare::match_exact(
compare::assert_match_exact(
"[..]/artifact/bar-baz-[..]/bin\n\
[..]/artifact/bar-baz-[..]/bin/baz_suffix-[..]",
&build_script_output,
msg,
"",
None,
)
.unwrap();
);
}

assert!(
Expand Down Expand Up @@ -1757,14 +1740,7 @@ fn allow_dep_renames_with_multiple_versions() {
.with_stderr_contains("[COMPILING] foo [..]")
.run();
let build_script_output = build_script_output_string(&p, "foo");
match_exact(
"0.5.0\n1.0.0",
&build_script_output,
"build script output",
"",
None,
)
.unwrap();
compare::assert_match_exact("0.5.0\n1.0.0", &build_script_output);
}

#[cargo_test]
Expand Down Expand Up @@ -3240,26 +3216,18 @@ fn build_only_specified_artifact_library() {
.cargo("build -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.run();
match_exact(
compare::assert_match_exact(
"cdylib present: true\nstaticlib present: false",
&build_script_output_string(&cdylib, "foo"),
"build script output",
"",
None,
)
.unwrap();
);

let staticlib = create_project("staticlib");
staticlib
.cargo("build -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.run();
match_exact(
compare::assert_match_exact(
"cdylib present: false\nstaticlib present: true",
&build_script_output_string(&staticlib, "foo"),
"build script output",
"",
None,
)
.unwrap();
);
}
23 changes: 8 additions & 15 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cargo::util::context::{
};
use cargo::CargoResult;
use cargo_test_support::compare;
use cargo_test_support::{panic_error, paths, project, symlink_supported, t};
use cargo_test_support::{paths, project, symlink_supported, t};
use cargo_util_schemas::manifest::TomlTrimPaths;
use cargo_util_schemas::manifest::TomlTrimPathsValue;
use cargo_util_schemas::manifest::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
Expand Down Expand Up @@ -222,14 +222,7 @@ pub fn assert_error<E: Borrow<anyhow::Error>>(error: E, msgs: &str) {
})
.collect::<Vec<_>>()
.join("\n\n");
assert_match(msgs, &causes);
}

#[track_caller]
pub fn assert_match(expected: &str, actual: &str) {
if let Err(e) = compare::match_exact(expected, actual, "output", "", None) {
panic_error("", e);
}
compare::assert_match_exact(msgs, &causes);
}

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

#[cargo_test]
Expand All @@ -323,7 +316,7 @@ f1 = 1

// It should NOT have warned for the symlink.
let output = read_output(gctx);
assert_match("", &output);
compare::assert_match_exact("", &output);
}

#[cargo_test]
Expand All @@ -349,7 +342,7 @@ f1 = 1

// It should NOT have warned for the symlink.
let output = read_output(gctx);
assert_match("", &output);
compare::assert_match_exact("", &output);
}

#[cargo_test]
Expand All @@ -375,7 +368,7 @@ f1 = 1

// It should NOT have warned for this situation.
let output = read_output(gctx);
assert_match("", &output);
compare::assert_match_exact("", &output);
}

#[cargo_test]
Expand Down Expand Up @@ -405,7 +398,7 @@ f1 = 2
let expected = "\
[WARNING] both `[..]/.cargo/config` and `[..]/.cargo/config.toml` exist. Using `[..]/.cargo/config`
";
assert_match(expected, &output);
compare::assert_match_exact(expected, &output);
}

#[cargo_test]
Expand Down Expand Up @@ -439,7 +432,7 @@ unused = 456
let expected = "\
warning: unused config key `S.unused` in `[..]/.cargo/config.toml`
";
assert_match(expected, &output);
compare::assert_match_exact(expected, &output);
}

#[cargo_test]
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/config_cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Tests for the --config CLI option.
use super::config::{
assert_error, assert_match, read_output, write_config_at, write_config_toml,
GlobalContextBuilder,
assert_error, read_output, write_config_at, write_config_toml, GlobalContextBuilder,
};
use cargo::util::context::Definition;
use cargo_test_support::compare;
use cargo_test_support::paths;
use std::{collections::HashMap, fs};

Expand Down Expand Up @@ -344,7 +344,7 @@ fn unused_key() {
let expected = "\
warning: unused config key `build.unused` in `--config cli option`
";
assert_match(expected, &output);
compare::assert_match_exact(expected, &output);
}

#[cargo_test]
Expand Down

0 comments on commit c77e4ea

Please sign in to comment.