mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Don't export lines_match.
Use better high-level interfaces to achieve the same thing.
This commit is contained in:
parent
b9f15ab1f0
commit
b73e3d4fa5
@ -165,7 +165,7 @@ pub fn match_exact(
|
||||
"{} did not match:\n\
|
||||
{}\n\n\
|
||||
other output:\n\
|
||||
`{}`",
|
||||
{}\n",
|
||||
description,
|
||||
diffs.join("\n"),
|
||||
other_output,
|
||||
@ -173,6 +173,14 @@ pub fn match_exact(
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience wrapper around [`match_exact`] which will panic on error.
|
||||
#[track_caller]
|
||||
pub fn assert_match_exact(expected: &str, actual: &str) {
|
||||
if let Err(e) = match_exact(expected, actual, "", "", None) {
|
||||
crate::panic_error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks that the given string contains the given lines, ignoring the order
|
||||
/// of the lines.
|
||||
///
|
||||
@ -487,17 +495,7 @@ fn zip_all<T, I1: Iterator<Item = T>, I2: Iterator<Item = T>>(a: I1, b: I2) -> Z
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares a line with an expected pattern.
|
||||
/// - Use `[..]` as a wildcard to match 0 or more characters on the same line
|
||||
/// (similar to `.*` in a regex). It is non-greedy.
|
||||
/// - Use `[EXE]` to optionally add `.exe` on Windows (empty string on other
|
||||
/// platforms).
|
||||
/// - There is a wide range of macros (such as `[COMPILING]` or `[WARNING]`)
|
||||
/// to match cargo's "status" output and allows you to ignore the alignment.
|
||||
/// See `substitute_macros` for a complete list of macros.
|
||||
/// - `[ROOT]` the path to the test directory's root
|
||||
/// - `[CWD]` is the working directory of the process that was run.
|
||||
pub fn lines_match(expected: &str, mut actual: &str) -> bool {
|
||||
fn lines_match(expected: &str, mut actual: &str) -> bool {
|
||||
for (i, part) in expected.split("[..]").enumerate() {
|
||||
match actual.find(part) {
|
||||
Some(j) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::compare::{find_json_mismatch, lines_match};
|
||||
use crate::compare::{assert_match_exact, find_json_mismatch};
|
||||
use crate::registry::{self, alt_api_path};
|
||||
use flate2::read::GzDecoder;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -151,16 +151,7 @@ pub fn validate_crate_contents(
|
||||
let actual_contents = files
|
||||
.get(&full_e_name)
|
||||
.unwrap_or_else(|| panic!("file `{}` missing in archive", e_file_name));
|
||||
if !lines_match(e_file_contents, actual_contents) {
|
||||
panic!(
|
||||
"Crate contents mismatch for {:?}:\n\
|
||||
--- expected\n\
|
||||
{}\n\
|
||||
--- actual \n\
|
||||
{}\n",
|
||||
e_file_name, e_file_contents, actual_contents
|
||||
);
|
||||
}
|
||||
assert_match_exact(e_file_contents, actual_contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Tests for build.rs scripts.
|
||||
|
||||
use cargo_test_support::compare::lines_match;
|
||||
use cargo_test_support::compare::assert_match_exact;
|
||||
use cargo_test_support::paths::CargoPathExt;
|
||||
use cargo_test_support::registry::Package;
|
||||
use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project};
|
||||
@ -3038,25 +3038,9 @@ fn generate_good_d_files() {
|
||||
|
||||
println!("*.d file content*: {}", &dot_d);
|
||||
|
||||
#[cfg(windows)]
|
||||
assert!(
|
||||
lines_match(
|
||||
"[..]\\target\\debug\\meow.exe: [..]\\awoo\\barkbarkbark [..]\\awoo\\build.rs[..]",
|
||||
&dot_d
|
||||
) || lines_match(
|
||||
"[..]\\target\\debug\\meow.exe: [..]\\awoo\\build.rs [..]\\awoo\\barkbarkbark[..]",
|
||||
&dot_d
|
||||
)
|
||||
);
|
||||
#[cfg(not(windows))]
|
||||
assert!(
|
||||
lines_match(
|
||||
"[..]/target/debug/meow: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..]",
|
||||
&dot_d
|
||||
) || lines_match(
|
||||
"[..]/target/debug/meow: [..]/awoo/build.rs [..]/awoo/barkbarkbark[..]",
|
||||
&dot_d
|
||||
)
|
||||
assert_match_exact(
|
||||
"[..]/target/debug/meow[EXE]: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..]",
|
||||
&dot_d,
|
||||
);
|
||||
|
||||
// paths relative to dependency roots should not be allowed
|
||||
@ -3077,25 +3061,9 @@ fn generate_good_d_files() {
|
||||
|
||||
println!("*.d file content with dep-info-basedir*: {}", &dot_d);
|
||||
|
||||
#[cfg(windows)]
|
||||
assert!(
|
||||
lines_match(
|
||||
"target\\debug\\meow.exe: [..]awoo\\barkbarkbark [..]awoo\\build.rs[..]",
|
||||
&dot_d
|
||||
) || lines_match(
|
||||
"target\\debug\\meow.exe: [..]awoo\\build.rs [..]awoo\\barkbarkbark[..]",
|
||||
&dot_d
|
||||
)
|
||||
);
|
||||
#[cfg(not(windows))]
|
||||
assert!(
|
||||
lines_match(
|
||||
"target/debug/meow: [..]awoo/barkbarkbark [..]awoo/build.rs[..]",
|
||||
&dot_d
|
||||
) || lines_match(
|
||||
"target/debug/meow: [..]awoo/build.rs [..]awoo/barkbarkbark[..]",
|
||||
&dot_d
|
||||
)
|
||||
assert_match_exact(
|
||||
"target/debug/meow[EXE]: awoo/barkbarkbark awoo/build.rs[..]",
|
||||
&dot_d,
|
||||
);
|
||||
|
||||
// paths relative to dependency roots should not be allowed
|
||||
|
@ -1151,7 +1151,8 @@ fn publish_no_implicit() {
|
||||
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
||||
&[(
|
||||
"Cargo.toml",
|
||||
r#"[..]
|
||||
&format!(
|
||||
r#"{}
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
@ -1169,6 +1170,8 @@ optional = true
|
||||
[features]
|
||||
feat = ["opt-dep1"]
|
||||
"#,
|
||||
cargo::core::package::MANIFEST_PREAMBLE
|
||||
),
|
||||
)],
|
||||
);
|
||||
}
|
||||
@ -1255,7 +1258,8 @@ fn publish() {
|
||||
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
||||
&[(
|
||||
"Cargo.toml",
|
||||
r#"[..]
|
||||
&format!(
|
||||
r#"{}
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
@ -1271,6 +1275,8 @@ feat1 = []
|
||||
feat2 = ["dep:bar"]
|
||||
feat3 = ["feat2"]
|
||||
"#,
|
||||
cargo::core::package::MANIFEST_PREAMBLE
|
||||
),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Tests for supporting older versions of the Cargo.lock file format.
|
||||
|
||||
use cargo_test_support::compare::lines_match;
|
||||
use cargo_test_support::compare::assert_match_exact;
|
||||
use cargo_test_support::git;
|
||||
use cargo_test_support::registry::Package;
|
||||
use cargo_test_support::{basic_lib_manifest, basic_manifest, project};
|
||||
@ -13,15 +13,6 @@ fn oldest_lockfile_still_works() {
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_lockfiles_eq(expected: &str, actual: &str) {
|
||||
for (l, r) in expected.lines().zip(actual.lines()) {
|
||||
assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r);
|
||||
}
|
||||
|
||||
assert_eq!(expected.lines().count(), actual.lines().count());
|
||||
}
|
||||
|
||||
fn oldest_lockfile_still_works_with_command(cargo_command: &str) {
|
||||
Package::new("bar", "0.1.0").publish();
|
||||
|
||||
@ -77,7 +68,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
p.cargo(cargo_command).run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(expected_lockfile, &lock);
|
||||
assert_match_exact(expected_lockfile, &lock);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -123,7 +114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
p.cargo("build --locked").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(&old_lockfile, &lock);
|
||||
assert_match_exact(&old_lockfile, &lock);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -170,7 +161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
p.cargo("build").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(
|
||||
assert_match_exact(
|
||||
r#"# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
@ -428,7 +419,7 @@ dependencies = [
|
||||
\"bar\",
|
||||
]
|
||||
";
|
||||
assert_lockfiles_eq(expected, &actual);
|
||||
assert_match_exact(expected, &actual);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -472,7 +463,7 @@ dependencies = [
|
||||
p.cargo("build").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(
|
||||
assert_match_exact(
|
||||
r#"# [..]
|
||||
# [..]
|
||||
version = 3
|
||||
@ -569,7 +560,7 @@ dependencies = [
|
||||
p.cargo("fetch").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(&lockfile, &lock);
|
||||
assert_match_exact(&lockfile, &lock);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -640,7 +631,7 @@ dependencies = [
|
||||
p.cargo("fetch").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(&lockfile, &lock);
|
||||
assert_match_exact(&lockfile, &lock);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -696,7 +687,7 @@ dependencies = [
|
||||
p.cargo("fetch").run();
|
||||
|
||||
let lock = p.read_lockfile();
|
||||
assert_lockfiles_eq(&lockfile, &lock);
|
||||
assert_match_exact(&lockfile, &lock);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
@ -1213,22 +1213,41 @@ fn publish_git_with_version() {
|
||||
(
|
||||
"Cargo.toml",
|
||||
// Check that only `version` is included in Cargo.toml.
|
||||
"[..]\n\
|
||||
[dependencies.dep1]\n\
|
||||
version = \"1.0\"\n\
|
||||
",
|
||||
&format!(
|
||||
"{}\n\
|
||||
[package]\n\
|
||||
edition = \"2018\"\n\
|
||||
name = \"foo\"\n\
|
||||
version = \"0.1.0\"\n\
|
||||
authors = []\n\
|
||||
description = \"foo\"\n\
|
||||
license = \"MIT\"\n\
|
||||
[dependencies.dep1]\n\
|
||||
version = \"1.0\"\n\
|
||||
",
|
||||
cargo::core::package::MANIFEST_PREAMBLE
|
||||
),
|
||||
),
|
||||
(
|
||||
"Cargo.lock",
|
||||
// The important check here is that it is 1.0.1 in the registry.
|
||||
"[..]\n\
|
||||
"# This file is automatically @generated by Cargo.\n\
|
||||
# It is not intended for manual editing.\n\
|
||||
version = 3\n\
|
||||
\n\
|
||||
[[package]]\n\
|
||||
name = \"dep1\"\n\
|
||||
version = \"1.0.1\"\n\
|
||||
source = \"registry+https://github.com/rust-lang/crates.io-index\"\n\
|
||||
checksum = \"[..]\"\n\
|
||||
\n\
|
||||
[[package]]\n\
|
||||
name = \"foo\"\n\
|
||||
version = \"0.1.0\"\n\
|
||||
dependencies = [\n\
|
||||
\x20\"dep1\",\n\
|
||||
]\n\
|
||||
[..]",
|
||||
",
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -1297,7 +1316,8 @@ fn publish_dev_dep_no_version() {
|
||||
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
||||
&[(
|
||||
"Cargo.toml",
|
||||
r#"[..]
|
||||
&format!(
|
||||
r#"{}
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
@ -1310,6 +1330,8 @@ repository = "foo"
|
||||
|
||||
[dev-dependencies]
|
||||
"#,
|
||||
cargo::core::package::MANIFEST_PREAMBLE
|
||||
),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
@ -702,7 +702,8 @@ fn publish() {
|
||||
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
|
||||
&[(
|
||||
"Cargo.toml",
|
||||
r#"[..]
|
||||
&format!(
|
||||
r#"{}
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
@ -717,6 +718,8 @@ optional = true
|
||||
feat1 = []
|
||||
feat2 = ["bar?/feat"]
|
||||
"#,
|
||||
cargo::core::package::MANIFEST_PREAMBLE
|
||||
),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user