mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Remove hamcrest contains()
This commit is contained in:
parent
a49589c0c7
commit
a5de2c0ce7
@ -3,7 +3,6 @@ use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use flate2::read::GzDecoder;
|
||||
use support::hamcrest::{assert_that, contains};
|
||||
use support::{cross_compile, project, publish};
|
||||
use tar::Archive;
|
||||
|
||||
@ -61,18 +60,9 @@ fn simple_cross_package() {
|
||||
let entry_paths = entries
|
||||
.map(|entry| entry.unwrap().path().unwrap().into_owned())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
assert_that(
|
||||
&entry_paths,
|
||||
contains(vec![PathBuf::from("foo-0.0.0/Cargo.toml")]),
|
||||
);
|
||||
assert_that(
|
||||
&entry_paths,
|
||||
contains(vec![PathBuf::from("foo-0.0.0/Cargo.toml.orig")]),
|
||||
);
|
||||
assert_that(
|
||||
&entry_paths,
|
||||
contains(vec![PathBuf::from("foo-0.0.0/src/main.rs")]),
|
||||
);
|
||||
assert!(entry_paths.contains(&PathBuf::from("foo-0.0.0/Cargo.toml")));
|
||||
assert!(entry_paths.contains(&PathBuf::from("foo-0.0.0/Cargo.toml.orig")));
|
||||
assert!(entry_paths.contains(&PathBuf::from("foo-0.0.0/src/main.rs")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use flate2::read::GzDecoder;
|
||||
use git2;
|
||||
use support::hamcrest::{assert_that, contains, existing_file};
|
||||
use support::hamcrest::{assert_that, existing_file};
|
||||
use support::registry::Package;
|
||||
use support::{basic_manifest, git, is_nightly, path2url, paths, project, registry};
|
||||
use support::{cargo_process, sleep_ms};
|
||||
@ -665,10 +665,7 @@ See [..]
|
||||
let entry_paths = entries
|
||||
.map(|entry| entry.unwrap().path().unwrap().into_owned())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
assert_that(
|
||||
&entry_paths,
|
||||
contains(vec![PathBuf::from("foo-0.0.1/src/foo.rs")]),
|
||||
);
|
||||
assert!(entry_paths.contains(&PathBuf::from("foo-0.0.1/src/foo.rs")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::cmp::PartialEq;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
use support::hamcrest::{assert_that, contains, is_not};
|
||||
|
||||
use cargo::core::dependency::Kind::{self, Development};
|
||||
use cargo::core::resolver::{self, Method};
|
||||
use cargo::core::source::{GitReference, SourceId};
|
||||
@ -215,13 +214,18 @@ fn test_resolving_empty_dependency_list() {
|
||||
assert_eq!(res, names(&["root"]));
|
||||
}
|
||||
|
||||
fn assert_same(a: &[PackageId], b: &[PackageId]) {
|
||||
assert_eq!(a.len(), b.len());
|
||||
for item in a {
|
||||
assert!(b.contains(item));
|
||||
/// Assert `xs` contains `elems`
|
||||
fn assert_contains<A: PartialEq>(xs: &[A], elems: &[A]) {
|
||||
for elem in elems {
|
||||
assert!(xs.contains(elem));
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_same<A: PartialEq>(a: &[A], b: &[A]) {
|
||||
assert_eq!(a.len(), b.len());
|
||||
assert_contains(b, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_resolving_only_package() {
|
||||
let reg = registry(vec![pkg("foo")]);
|
||||
@ -248,7 +252,7 @@ fn test_resolving_transitive_deps() {
|
||||
let reg = registry(vec![pkg!("foo"), pkg!("bar" => ["foo"])]);
|
||||
let res = resolve(&pkg_id("root"), vec![dep("bar")], ®).unwrap();
|
||||
|
||||
assert_that(&res, contains(names(&["root", "foo", "bar"])));
|
||||
assert_contains(&res, &names(&["root", "foo", "bar"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -256,7 +260,7 @@ fn test_resolving_common_transitive_deps() {
|
||||
let reg = registry(vec![pkg!("foo" => ["bar"]), pkg!("bar")]);
|
||||
let res = resolve(&pkg_id("root"), vec![dep("foo"), dep("bar")], ®).unwrap();
|
||||
|
||||
assert_that(&res, contains(names(&["root", "foo", "bar"])));
|
||||
assert_contains(&res, &names(&["root", "foo", "bar"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -300,7 +304,7 @@ fn test_resolving_with_dev_deps() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(&res, contains(names(&["root", "foo", "bar", "baz"])));
|
||||
assert_contains(&res, &names(&["root", "foo", "bar", "baz"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -309,10 +313,7 @@ fn resolving_with_many_versions() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep("foo")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
&res,
|
||||
contains(names(&[("root", "1.0.0"), ("foo", "1.0.2")])),
|
||||
);
|
||||
assert_contains(&res, &names(&[("root", "1.0.0"), ("foo", "1.0.2")]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -321,10 +322,7 @@ fn resolving_with_specific_version() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "=1.0.1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
&res,
|
||||
contains(names(&[("root", "1.0.0"), ("foo", "1.0.1")])),
|
||||
);
|
||||
assert_contains(&res, &names(&[("root", "1.0.0"), ("foo", "1.0.1")]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -343,17 +341,17 @@ fn test_resolving_maximum_version_with_transitive_deps() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
("util", "1.2.2"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
assert_that(&res, is_not(contains(names(&[("util", "1.0.1")]))));
|
||||
assert_that(&res, is_not(contains(names(&[("util", "1.1.1")]))));
|
||||
assert!(!res.contains(&("util", "1.0.1").to_pkgid()));
|
||||
assert!(!res.contains(&("util", "1.1.1").to_pkgid()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -390,17 +388,17 @@ fn test_resolving_minimum_version_with_transitive_deps() {
|
||||
Some(&config),
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
("util", "1.1.1"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
assert_that(&res, is_not(contains(names(&[("util", "1.2.2")]))));
|
||||
assert_that(&res, is_not(contains(names(&[("util", "1.0.0")]))));
|
||||
assert!(!res.contains(&("util", "1.2.2").to_pkgid()));
|
||||
assert!(!res.contains(&("util", "1.0.0").to_pkgid()));
|
||||
}
|
||||
|
||||
// Ensure that the "-Z minimal-versions" CLI option works and the minimal
|
||||
@ -484,13 +482,9 @@ fn resolving_backtrack() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "^1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.1"),
|
||||
("baz", "1.0.0"),
|
||||
])),
|
||||
&names(&[("root", "1.0.0"), ("foo", "1.0.1"), ("baz", "1.0.0")]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -508,13 +502,9 @@ fn resolving_backtrack_features() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "^1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.1"),
|
||||
("bar", "1.0.0"),
|
||||
])),
|
||||
&names(&[("root", "1.0.0"), ("foo", "1.0.1"), ("bar", "1.0.0")]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -534,9 +524,9 @@ fn resolving_allows_multiple_compatible_versions() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep("bar")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("foo", "2.0.0"),
|
||||
@ -547,7 +537,7 @@ fn resolving_allows_multiple_compatible_versions() {
|
||||
("d3", "1.0.0"),
|
||||
("d4", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -567,14 +557,14 @@ fn resolving_with_deep_backtracking() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "2.0.0"),
|
||||
("baz", "1.0.1"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -598,16 +588,16 @@ fn resolving_with_sys_crates() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("d", "1.0.0"),
|
||||
("r", "1.0.0"),
|
||||
("l-sys", "0.9.1"),
|
||||
("l", "0.9.1"),
|
||||
("l", "0.10.0"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -647,14 +637,14 @@ fn resolving_with_constrained_sibling_backtrack_parent() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
("constrained", "1.0.0"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -692,10 +682,7 @@ fn resolving_with_many_equivalent_backtracking() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("level0", "*")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
&res,
|
||||
contains(names(&[("root", "1.0.0"), ("level0", "1.0.0")])),
|
||||
);
|
||||
assert_contains(&res, &names(&[("root", "1.0.0"), ("level0", "1.0.0")]));
|
||||
|
||||
// Make sure we have not special case no candidates.
|
||||
reglist.push(pkg!(("constrained", "1.1.0")));
|
||||
@ -712,13 +699,13 @@ fn resolving_with_many_equivalent_backtracking() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("level0", "1.0.0"),
|
||||
("constrained", "1.1.0"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
|
||||
let reg = registry(reglist.clone());
|
||||
@ -729,13 +716,13 @@ fn resolving_with_many_equivalent_backtracking() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
(format!("level{}", DEPTH).as_str(), "1.0.0"),
|
||||
("constrained", "1.0.0"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
|
||||
let reg = registry(reglist.clone());
|
||||
@ -879,9 +866,9 @@ fn resolving_with_constrained_cousins_backtrack() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[("constrained", "2.0.0"), ("cloaking", "1.0.0")])),
|
||||
&names(&[("constrained", "2.0.0"), ("cloaking", "1.0.0")]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -919,14 +906,14 @@ fn resolving_with_constrained_sibling_backtrack_activation() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("foo", "1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
("constrained", "1.0.60"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -965,14 +952,14 @@ fn resolving_with_constrained_sibling_transitive_dep_effects() {
|
||||
|
||||
let res = resolve(&pkg_id("root"), vec![dep_req("A", "1")], ®).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
&names(&[
|
||||
("A", "1.0.0"),
|
||||
("B", "1.0.0"),
|
||||
("C", "1.0.0"),
|
||||
("D", "1.0.105"),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1014,12 +1001,8 @@ fn hard_equality() {
|
||||
®,
|
||||
).unwrap();
|
||||
|
||||
assert_that(
|
||||
assert_contains(
|
||||
&res,
|
||||
contains(names(&[
|
||||
("root", "1.0.0"),
|
||||
("foo", "1.0.0"),
|
||||
("bar", "1.0.0"),
|
||||
])),
|
||||
&names(&[("root", "1.0.0"), ("foo", "1.0.0"), ("bar", "1.0.0")]),
|
||||
);
|
||||
}
|
||||
|
@ -78,24 +78,3 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains<T>(item: Vec<T>) -> Contains<T> {
|
||||
Contains(item)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Contains<T>(Vec<T>);
|
||||
|
||||
impl<'a, T> Matcher<&'a Vec<T>> for Contains<T>
|
||||
where
|
||||
T: fmt::Debug + PartialEq,
|
||||
{
|
||||
fn matches(&self, actual: &'a Vec<T>) -> Result<(), String> {
|
||||
for item in self.0.iter() {
|
||||
if !actual.contains(item) {
|
||||
return Err(format!("failed to find {:?}", item));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user