From: Alex Crichton Date: Thu, 1 Mar 2018 18:14:17 +0000 (-0800) Subject: Drop outdated hamcrest dependency X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~71^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2a063798eb2a77e374dbe40af25ad25777678f1f;p=cargo.git Drop outdated hamcrest dependency This hasn't been updated in awhile and in general we've been barely using it. This drops the outdated dependency and vendors a small amount of the functionality that it provided. I think eventually we'll want to transition away from this method of assertions but I wanted to get this piece in to avoid too much churn in one commit. --- diff --git a/Cargo.toml b/Cargo.toml index 1b71cc797..e7d52c3e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,6 @@ features = [ [dev-dependencies] bufstream = "0.1" filetime = "0.1" -hamcrest = "=0.1.1" [[bin]] name = "cargo" diff --git a/tests/testsuite/build_lib.rs b/tests/testsuite/build_lib.rs index 90a5a5097..87243d6b3 100644 --- a/tests/testsuite/build_lib.rs +++ b/tests/testsuite/build_lib.rs @@ -1,5 +1,3 @@ -extern crate hamcrest; - use cargotest::support::{basic_bin_manifest, execs, project, Project}; use hamcrest::{assert_that}; diff --git a/tests/testsuite/cargotest/install.rs b/tests/testsuite/cargotest/install.rs index b9905ea24..d9ab27990 100644 --- a/tests/testsuite/cargotest/install.rs +++ b/tests/testsuite/cargotest/install.rs @@ -24,7 +24,7 @@ impl> Matcher

for InstalledExe { } } -impl fmt::Display for InstalledExe { +impl fmt::Debug for InstalledExe { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "installed exe `{}`", self.0) } diff --git a/tests/testsuite/cargotest/support/mod.rs b/tests/testsuite/cargotest/support/mod.rs index 754d3c96f..733d1e66f 100644 --- a/tests/testsuite/cargotest/support/mod.rs +++ b/tests/testsuite/cargotest/support/mod.rs @@ -416,11 +416,10 @@ impl Execs { fn match_status(&self, actual: &Output) -> ham::MatchResult { match self.expect_exit_code { - None => ham::success(), - Some(code) => { - ham::expect( - actual.status.code() == Some(code), - format!("exited with {}\n--- stdout\n{}\n--- stderr\n{}", + None => Ok(()), + Some(code) if actual.status.code() == Some(code) => Ok(()), + Some(_) => { + Err(format!("exited with {}\n--- stdout\n{}\n--- stderr\n{}", actual.status, String::from_utf8_lossy(&actual.stdout), String::from_utf8_lossy(&actual.stderr))) @@ -497,7 +496,7 @@ impl Execs { kind: MatchKind) -> ham::MatchResult { let out = match expected { Some(out) => out, - None => return ham::success(), + None => return Ok(()), }; let actual = match str::from_utf8(actual) { Err(..) => return Err(format!("{} was not utf8 encoded", @@ -514,12 +513,15 @@ impl Execs { let e = out.lines(); let diffs = self.diff_lines(a, e, false); - ham::expect(diffs.is_empty(), - format!("differences:\n\ - {}\n\n\ - other output:\n\ - `{}`", diffs.join("\n"), - String::from_utf8_lossy(extra))) + if diffs.is_empty() { + Ok(()) + } else { + Err(format!("differences:\n\ + {}\n\n\ + other output:\n\ + `{}`", diffs.join("\n"), + String::from_utf8_lossy(extra))) + } } MatchKind::Partial => { let mut a = actual.lines(); @@ -532,12 +534,15 @@ impl Execs { diffs = a; } } - ham::expect(diffs.is_empty(), - format!("expected to find:\n\ - {}\n\n\ - did not find in output:\n\ - {}", out, - actual)) + if diffs.is_empty() { + Ok(()) + } else { + Err(format!("expected to find:\n\ + {}\n\n\ + did not find in output:\n\ + {}", out, + actual)) + } } MatchKind::PartialN(number) => { let mut a = actual.lines(); @@ -552,20 +557,26 @@ impl Execs { a.next() } {} - ham::expect(matches == number, - format!("expected to find {} occurrences:\n\ - {}\n\n\ - did not find in output:\n\ - {}", number, out, - actual)) + if matches == number { + Ok(()) + } else { + Err(format!("expected to find {} occurrences:\n\ + {}\n\n\ + did not find in output:\n\ + {}", number, out, + actual)) + } } MatchKind::NotPresent => { - ham::expect(!actual.contains(out), - format!("expected not to find:\n\ - {}\n\n\ - but found in output:\n\ - {}", out, - actual)) + if !actual.contains(out) { + Ok(()) + } else { + Err(format!("expected not to find:\n\ + {}\n\n\ + but found in output:\n\ + {}", out, + actual)) + } } } } @@ -736,7 +747,7 @@ fn zip_all, I2: Iterator>(a: I1, b: I2) -> ZipAl } } -impl fmt::Display for Execs { +impl fmt::Debug for Execs { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "execs") } diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 864dc2cf7..38b7d214c 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1,10 +1,10 @@ +use cargotest::install::exe; use cargotest::is_nightly; -use cargotest::support::{execs, project}; -use cargotest::support::registry::Package; -use hamcrest::prelude::*; use cargotest::support::paths::CargoPathExt; -use cargotest::install::exe; +use cargotest::support::registry::Package; +use cargotest::support::{execs, project}; use glob::glob; +use hamcrest::{assert_that, existing_file, is_not}; const SIMPLE_MANIFEST: &str = r#" [package] @@ -662,9 +662,8 @@ fn check_artifacts() is_not(existing_file())); assert_that(&p.root().join("target/debug").join(exe("foo")), is_not(existing_file())); - assert_that(glob(&p.root().join("target/debug/t1-*").to_str().unwrap()) - .unwrap().count(), - is(equal_to(0))); + assert_eq!(glob(&p.root().join("target/debug/t1-*").to_str().unwrap()) + .unwrap().count(), 0); p.root().join("target").rm_rf(); assert_that(p.cargo("check").arg("--example").arg("ex1"), @@ -685,7 +684,6 @@ fn check_artifacts() is_not(existing_file())); assert_that(&p.root().join("target/debug").join(exe("foo")), is_not(existing_file())); - assert_that(glob(&p.root().join("target/debug/b1-*").to_str().unwrap()) - .unwrap().count(), - is(equal_to(0))); + assert_eq!(glob(&p.root().join("target/debug/b1-*").to_str().unwrap()) + .unwrap().count(), 0); } diff --git a/tests/testsuite/hamcrest.rs b/tests/testsuite/hamcrest.rs new file mode 100644 index 000000000..414431817 --- /dev/null +++ b/tests/testsuite/hamcrest.rs @@ -0,0 +1,86 @@ +use std::fmt; +use std::marker; +use std::path::Path; + +pub type MatchResult = Result<(), String>; + +pub trait Matcher: fmt::Debug { + fn matches(&self, actual: T) -> Result<(), String>; +} + +pub fn assert_that>(actual: T, matcher: U) { + if let Err(e) = matcher.matches(actual) { + panic!("\nExpected: {:?}\n but: {}", matcher, e) + } +} + +pub fn existing_file() -> ExistingFile { + ExistingFile +} + +#[derive(Debug)] +pub struct ExistingFile; + +impl

Matcher

for ExistingFile where P: AsRef { + fn matches(&self, actual: P) -> Result<(), String> { + if actual.as_ref().is_file() { + Ok(()) + } else { + Err(format!("{} was not a file", actual.as_ref().display())) + } + } +} + +pub fn existing_dir() -> ExistingDir { + ExistingDir +} + +#[derive(Debug)] +pub struct ExistingDir; + +impl

Matcher

for ExistingDir where P: AsRef { + fn matches(&self, actual: P) -> Result<(), String> { + if actual.as_ref().is_dir() { + Ok(()) + } else { + Err(format!("{} was not a dir", actual.as_ref().display())) + } + } +} + +pub fn is_not>(matcher: M) -> IsNot { + IsNot { matcher, _marker: marker::PhantomData } +} + +#[derive(Debug)] +pub struct IsNot { + matcher: M, + _marker: marker::PhantomData, +} + +impl> Matcher for IsNot where T: fmt::Debug { + fn matches(&self, actual: T) -> Result<(), String> { + match self.matcher.matches(actual) { + Ok(_) => Err("matched".to_string()), + Err(_) => Ok(()), + } + } +} + +pub fn contains(item: Vec) -> Contains { + Contains(item) +} + +#[derive(Debug)] +pub struct Contains(Vec); + +impl<'a, T> Matcher<&'a Vec> for Contains where T: fmt::Debug + PartialEq { + fn matches(&self, actual: &'a Vec) -> Result<(), String> { + for item in self.0.iter() { + if !actual.contains(item) { + return Err(format!("failed to find {:?}", item)) + } + } + Ok(()) + } +} diff --git a/tests/testsuite/lib.rs b/tests/testsuite/lib.rs index b804ab0d0..321364b47 100644 --- a/tests/testsuite/lib.rs +++ b/tests/testsuite/lib.rs @@ -4,7 +4,6 @@ extern crate filetime; extern crate flate2; extern crate git2; extern crate glob; -extern crate hamcrest; extern crate hex; extern crate libc; #[macro_use] @@ -20,6 +19,7 @@ extern crate winapi; #[macro_use] mod cargotest; +mod hamcrest; mod alt_registry; mod bad_config; diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index f22e1a3ff..cb30b6abe 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -8,7 +8,7 @@ use cargotest::{cargo_process, process, ChannelChanger}; use cargotest::support::{project, execs, paths, git, path2url, cargo_exe, registry}; use cargotest::support::registry::Package; use flate2::read::GzDecoder; -use hamcrest::{assert_that, existing_file, contains, equal_to}; +use hamcrest::{assert_that, existing_file, contains}; use tar::Archive; #[test] @@ -756,7 +756,7 @@ fn generated_manifest() { entry.read_to_string(&mut contents).unwrap(); // BTreeMap makes the order of dependencies in the generated file deterministic // by sorting alphabetically - assert_that(&contents[..], equal_to( + assert_eq!(&contents[..], &*format!( r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # @@ -795,7 +795,7 @@ registry-index = "{}" [dependencies.ghi] version = "1.0" "#, - registry::alt_registry()))); + registry::alt_registry())); } #[test] @@ -838,7 +838,7 @@ fn ignore_workspace_specifier() { .unwrap(); let mut contents = String::new(); entry.read_to_string(&mut contents).unwrap(); - assert_that(&contents[..], equal_to( + assert_eq!(&contents[..], r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically @@ -855,7 +855,7 @@ r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO name = "bar" version = "0.1.0" authors = [] -"#)); +"#); } #[test] diff --git a/tests/testsuite/rename_deps.rs b/tests/testsuite/rename_deps.rs index cc8a28fa7..92f9b10b2 100644 --- a/tests/testsuite/rename_deps.rs +++ b/tests/testsuite/rename_deps.rs @@ -1,5 +1,3 @@ -extern crate hamcrest; - use cargotest::support::{project, execs}; use cargotest::support::registry::Package; use cargotest::ChannelChanger; diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index c99ff6a5c..e92d72b31 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1,7 +1,7 @@ use cargotest::is_nightly; use cargotest::install::{cargo_home, has_installed_exe}; use cargotest::support::{project, execs}; -use hamcrest::{assert_that, existing_file, not}; +use hamcrest::{assert_that, existing_file, is_not}; #[test] fn build_bin_default_features() { @@ -110,7 +110,7 @@ fn build_bin_multiple_required_features() { assert_that(p.cargo("build"), execs().with_status(0)); - assert_that(&p.bin("foo_1"), not(existing_file())); + assert_that(&p.bin("foo_1"), is_not(existing_file())); assert_that(&p.bin("foo_2"), existing_file()); assert_that(p.cargo("build").arg("--features").arg("c"), @@ -213,7 +213,7 @@ Consider enabling them by passing e.g. `--features=\"b c\"` assert_that(p.cargo("build").arg("--example=foo_2"), execs().with_status(0)); - assert_that(&p.bin("examples/foo_1"), not(existing_file())); + assert_that(&p.bin("examples/foo_1"), is_not(existing_file())); assert_that(&p.bin("examples/foo_2"), existing_file()); assert_that(p.cargo("build").arg("--example=foo_1") @@ -553,7 +553,7 @@ fn install_default_features() { [FINISHED] release [optimized] target(s) in [..] [ERROR] no binaries are available for install using the selected features "))); - assert_that(cargo_home(), not(has_installed_exe("foo"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo"))); assert_that(p.cargo("install").arg("--bin=foo"), execs().with_status(0)); @@ -571,7 +571,7 @@ Caused by: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` "))); - assert_that(cargo_home(), not(has_installed_exe("foo"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo"))); assert_that(p.cargo("install").arg("--example=foo"), execs().with_status(0)); @@ -589,7 +589,7 @@ Caused by: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` "))); - assert_that(cargo_home(), not(has_installed_exe("foo"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo"))); } #[test] @@ -649,7 +649,7 @@ fn install_multiple_required_features() { assert_that(p.cargo("install"), execs().with_status(0)); - assert_that(cargo_home(), not(has_installed_exe("foo_1"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo_1"))); assert_that(cargo_home(), has_installed_exe("foo_2")); assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); @@ -667,8 +667,8 @@ fn install_multiple_required_features() { [FINISHED] release [optimized] target(s) in [..] [ERROR] no binaries are available for install using the selected features ")); - assert_that(cargo_home(), not(has_installed_exe("foo_1"))); - assert_that(cargo_home(), not(has_installed_exe("foo_2"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo_1"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo_2"))); } #[test] @@ -872,7 +872,7 @@ Consider enabling them by passing e.g. `--features=\"bar/a\"` [FINISHED] release [optimized] target(s) in [..] [ERROR] no binaries are available for install using the selected features "))); - assert_that(cargo_home(), not(has_installed_exe("foo"))); + assert_that(cargo_home(), is_not(has_installed_exe("foo"))); assert_that(p.cargo("install").arg("--features").arg("bar/a"), execs().with_status(0)); diff --git a/tests/testsuite/resolve.rs b/tests/testsuite/resolve.rs index 55d683fee..d99cf94f3 100644 --- a/tests/testsuite/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use hamcrest::{assert_that, equal_to, contains, not}; +use hamcrest::{assert_that, contains, is_not}; use cargo::core::source::{SourceId, GitReference}; use cargo::core::dependency::Kind::{self, Development}; @@ -156,23 +156,28 @@ fn test_resolving_empty_dependency_list() { let res = resolve(&pkg_id("root"), Vec::new(), ®istry(vec![])).unwrap(); - assert_that(&res, equal_to(&names(&["root"]))); + 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)); + } } #[test] fn test_resolving_only_package() { let reg = registry(vec![pkg("foo")]); - let res = resolve(&pkg_id("root"), vec![dep("foo")], ®); - - assert_that(&res.unwrap(), contains(names(&["root", "foo"])).exactly()); + let res = resolve(&pkg_id("root"), vec![dep("foo")], ®).unwrap(); + assert_same(&res, &names(&["root", "foo"])); } #[test] fn test_resolving_one_dep() { let reg = registry(vec![pkg("foo"), pkg("bar")]); - let res = resolve(&pkg_id("root"), vec![dep("foo")], ®); - - assert_that(&res.unwrap(), contains(names(&["root", "foo"])).exactly()); + let res = resolve(&pkg_id("root"), vec![dep("foo")], ®).unwrap(); + assert_same(&res, &names(&["root", "foo"])); } #[test] @@ -180,8 +185,7 @@ fn test_resolving_multiple_deps() { let reg = registry(vec![pkg!("foo"), pkg!("bar"), pkg!("baz")]); let res = resolve(&pkg_id("root"), vec![dep("foo"), dep("baz")], ®).unwrap(); - - assert_that(&res, contains(names(&["root", "foo", "baz"])).exactly()); + assert_same(&res, &names(&["root", "foo", "baz"])); } #[test] @@ -210,14 +214,13 @@ fn test_resolving_with_same_name() { let res = resolve(&pkg_id("root"), vec![dep_loc("foo", "http://first.example.com"), dep_loc("bar", "http://second.example.com")], - ®); + ®).unwrap(); let mut names = loc_names(&[("foo", "http://first.example.com"), ("bar", "http://second.example.com")]); names.push(pkg_id("root")); - - assert_that(&res.unwrap(), contains(names).exactly()); + assert_same(&res, &names); } #[test] @@ -280,8 +283,8 @@ fn test_resolving_maximum_version_with_transitive_deps() { ("foo", "1.0.0"), ("bar", "1.0.0"), ("util", "1.2.2")]))); - assert_that(&res, not(contains(names(&[("util", "1.0.1")])))); - assert_that(&res, not(contains(names(&[("util", "1.1.1")])))); + assert_that(&res, is_not(contains(names(&[("util", "1.0.1")])))); + assert_that(&res, is_not(contains(names(&[("util", "1.1.1")])))); } #[test]