Skip to content

Commit d363109

Browse files
committed
Auto merge of #5103 - alexcrichton:no-hamcrest, r=matklad
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.
2 parents f55b326 + 2a06379 commit d363109

17 files changed

+199
-170
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ features = [
8080

8181
[dev-dependencies]
8282
bufstream = "0.1"
83-
cargotest = { path = "tests/testsuite/cargotest", version = "0.1" }
8483
filetime = "0.1"
85-
hamcrest = "=0.1.1"
8684

8785
[[bin]]
8886
name = "cargo"

tests/testsuite/build_lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
extern crate cargotest;
2-
extern crate hamcrest;
3-
41
use cargotest::support::{basic_bin_manifest, execs, project, Project};
52
use hamcrest::{assert_that};
63

tests/testsuite/cargotest/Cargo.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/testsuite/cargotest/install.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::fmt;
22
use std::path::{PathBuf, Path};
33

44
use hamcrest::{Matcher, MatchResult, existing_file};
5-
use support::paths;
5+
6+
use cargotest::support::paths;
67

78
pub use self::InstalledExe as has_installed_exe;
89

@@ -23,7 +24,7 @@ impl<P: AsRef<Path>> Matcher<P> for InstalledExe {
2324
}
2425
}
2526

26-
impl fmt::Display for InstalledExe {
27+
impl fmt::Debug for InstalledExe {
2728
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2829
write!(f, "installed exe `{}`", self.0)
2930
}

tests/testsuite/cargotest/lib.rs renamed to tests/testsuite/cargotest/mod.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
#![deny(warnings)]
2-
3-
extern crate cargo;
4-
extern crate filetime;
5-
extern crate flate2;
6-
extern crate git2;
7-
extern crate hamcrest;
8-
extern crate hex;
9-
#[macro_use]
10-
extern crate serde_json;
11-
extern crate tar;
12-
extern crate url;
13-
141
use std::ffi::OsStr;
152
use std::time::Duration;
163

174
use cargo::util::Rustc;
5+
use cargo;
186
use std::path::PathBuf;
197

8+
#[macro_use]
209
pub mod support;
10+
2111
pub mod install;
2212

2313
thread_local!(pub static RUSTC: Rustc = Rustc::new(PathBuf::from("rustc"), None).unwrap());
@@ -95,5 +85,5 @@ pub fn cargo_process() -> cargo::util::ProcessBuilder {
9585
}
9686

9787
pub fn sleep_ms(ms: u64) {
98-
std::thread::sleep(Duration::from_millis(ms));
88+
::std::thread::sleep(Duration::from_millis(ms));
9989
}

tests/testsuite/cargotest/support/cross_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::process::Command;
33
use std::sync::{Once, ONCE_INIT};
44
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
55

6-
use support::{project, main_file, basic_bin_manifest};
6+
use cargotest::support::{project, main_file, basic_bin_manifest};
77

88
pub fn disabled() -> bool {
99
// First, disable if ./configure requested so

tests/testsuite/cargotest/support/git.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::fs::{self, File};
22
use std::io::prelude::*;
33
use std::path::{Path, PathBuf};
44

5-
use url::Url;
5+
use cargo::util::ProcessError;
66
use git2;
7+
use url::Url;
78

8-
use cargo::util::ProcessError;
9-
use support::{ProjectBuilder, Project, project, path2url};
9+
use cargotest::support::{ProjectBuilder, Project, project, path2url};
1010

1111
#[must_use]
1212
pub struct RepoBuilder {

tests/testsuite/cargotest/support/mod.rs

Lines changed: 44 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ use hamcrest as ham;
1515
use cargo::util::ProcessBuilder;
1616
use cargo::util::{ProcessError};
1717

18-
use support::paths::CargoPathExt;
18+
use cargotest::support::paths::CargoPathExt;
1919

20-
#[macro_export]
2120
macro_rules! t {
2221
($e:expr) => (match $e {
2322
Ok(e) => e,
@@ -110,10 +109,6 @@ impl ProjectBuilder {
110109
self.root.root()
111110
}
112111

113-
pub fn build_dir(&self) -> PathBuf {
114-
self.root.build_dir()
115-
}
116-
117112
pub fn target_debug_dir(&self) -> PathBuf {
118113
self.root.target_debug_dir()
119114
}
@@ -218,7 +213,7 @@ impl Project {
218213
}
219214

220215
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> ProcessBuilder {
221-
let mut p = ::process(program);
216+
let mut p = ::cargotest::process(program);
222217
p.cwd(self.root());
223218
return p
224219
}
@@ -406,11 +401,6 @@ impl Execs {
406401
self
407402
}
408403

409-
pub fn with_neither_contains<S: ToString>(mut self, expected: S) -> Execs {
410-
self.expect_neither_contains.push(expected.to_string());
411-
self
412-
}
413-
414404
pub fn with_json(mut self, expected: &str) -> Execs {
415405
self.expect_json = Some(expected.split("\n\n").map(|obj| {
416406
obj.parse().unwrap()
@@ -426,11 +416,10 @@ impl Execs {
426416

427417
fn match_status(&self, actual: &Output) -> ham::MatchResult {
428418
match self.expect_exit_code {
429-
None => ham::success(),
430-
Some(code) => {
431-
ham::expect(
432-
actual.status.code() == Some(code),
433-
format!("exited with {}\n--- stdout\n{}\n--- stderr\n{}",
419+
None => Ok(()),
420+
Some(code) if actual.status.code() == Some(code) => Ok(()),
421+
Some(_) => {
422+
Err(format!("exited with {}\n--- stdout\n{}\n--- stderr\n{}",
434423
actual.status,
435424
String::from_utf8_lossy(&actual.stdout),
436425
String::from_utf8_lossy(&actual.stderr)))
@@ -507,7 +496,7 @@ impl Execs {
507496
kind: MatchKind) -> ham::MatchResult {
508497
let out = match expected {
509498
Some(out) => out,
510-
None => return ham::success(),
499+
None => return Ok(()),
511500
};
512501
let actual = match str::from_utf8(actual) {
513502
Err(..) => return Err(format!("{} was not utf8 encoded",
@@ -524,12 +513,15 @@ impl Execs {
524513
let e = out.lines();
525514

526515
let diffs = self.diff_lines(a, e, false);
527-
ham::expect(diffs.is_empty(),
528-
format!("differences:\n\
529-
{}\n\n\
530-
other output:\n\
531-
`{}`", diffs.join("\n"),
532-
String::from_utf8_lossy(extra)))
516+
if diffs.is_empty() {
517+
Ok(())
518+
} else {
519+
Err(format!("differences:\n\
520+
{}\n\n\
521+
other output:\n\
522+
`{}`", diffs.join("\n"),
523+
String::from_utf8_lossy(extra)))
524+
}
533525
}
534526
MatchKind::Partial => {
535527
let mut a = actual.lines();
@@ -542,12 +534,15 @@ impl Execs {
542534
diffs = a;
543535
}
544536
}
545-
ham::expect(diffs.is_empty(),
546-
format!("expected to find:\n\
547-
{}\n\n\
548-
did not find in output:\n\
549-
{}", out,
550-
actual))
537+
if diffs.is_empty() {
538+
Ok(())
539+
} else {
540+
Err(format!("expected to find:\n\
541+
{}\n\n\
542+
did not find in output:\n\
543+
{}", out,
544+
actual))
545+
}
551546
}
552547
MatchKind::PartialN(number) => {
553548
let mut a = actual.lines();
@@ -562,20 +557,26 @@ impl Execs {
562557
a.next()
563558
} {}
564559

565-
ham::expect(matches == number,
566-
format!("expected to find {} occurrences:\n\
567-
{}\n\n\
568-
did not find in output:\n\
569-
{}", number, out,
570-
actual))
560+
if matches == number {
561+
Ok(())
562+
} else {
563+
Err(format!("expected to find {} occurrences:\n\
564+
{}\n\n\
565+
did not find in output:\n\
566+
{}", number, out,
567+
actual))
568+
}
571569
}
572570
MatchKind::NotPresent => {
573-
ham::expect(!actual.contains(out),
574-
format!("expected not to find:\n\
575-
{}\n\n\
576-
but found in output:\n\
577-
{}", out,
578-
actual))
571+
if !actual.contains(out) {
572+
Ok(())
573+
} else {
574+
Err(format!("expected not to find:\n\
575+
{}\n\n\
576+
but found in output:\n\
577+
{}", out,
578+
actual))
579+
}
579580
}
580581
}
581582
}
@@ -746,7 +747,7 @@ fn zip_all<T, I1: Iterator<Item=T>, I2: Iterator<Item=T>>(a: I1, b: I2) -> ZipAl
746747
}
747748
}
748749

749-
impl fmt::Display for Execs {
750+
impl fmt::Debug for Execs {
750751
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
751752
write!(f, "execs")
752753
}
@@ -803,31 +804,6 @@ pub fn execs() -> Execs {
803804
}
804805
}
805806

806-
#[derive(Clone)]
807-
pub struct ShellWrites {
808-
expected: String
809-
}
810-
811-
impl fmt::Display for ShellWrites {
812-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
813-
write!(f, "`{}` written to the shell", self.expected)
814-
}
815-
}
816-
817-
impl<'a> ham::Matcher<&'a [u8]> for ShellWrites {
818-
fn matches(&self, actual: &[u8])
819-
-> ham::MatchResult
820-
{
821-
let actual = String::from_utf8_lossy(actual);
822-
let actual = actual.to_string();
823-
ham::expect(actual == self.expected, actual)
824-
}
825-
}
826-
827-
pub fn shell_writes<T: fmt::Display>(string: T) -> ShellWrites {
828-
ShellWrites { expected: string.to_string() }
829-
}
830-
831807
pub trait Tap {
832808
fn tap<F: FnOnce(&mut Self)>(self, callback: F) -> Self;
833809
}

tests/testsuite/cargotest/support/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::path::PathBuf;
22
use std::io::prelude::*;
33
use std::fs::{self, File};
44

5-
use support::paths;
6-
use support::git::{repo, Repository};
5+
use cargotest::support::paths;
6+
use cargotest::support::git::{repo, Repository};
77

88
use url::Url;
99

tests/testsuite/cargotest/support/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use std::fs::{self, File};
33
use std::io::prelude::*;
44
use std::path::{PathBuf, Path};
55

6+
use cargo::util::Sha256;
67
use flate2::Compression;
78
use flate2::write::GzEncoder;
89
use git2;
910
use hex;
1011
use tar::{Builder, Header};
1112
use url::Url;
1213

13-
use support::paths;
14-
use support::git::repo;
15-
use cargo::util::Sha256;
14+
use cargotest::support::paths;
15+
use cargotest::support::git::repo;
1616

1717
pub fn registry_path() -> PathBuf { paths::root().join("registry") }
1818
pub fn registry() -> Url { Url::from_file_path(&*registry_path()).ok().unwrap() }

tests/testsuite/check.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use cargotest::install::exe;
12
use cargotest::is_nightly;
2-
use cargotest::support::{execs, project};
3-
use cargotest::support::registry::Package;
4-
use hamcrest::prelude::*;
53
use cargotest::support::paths::CargoPathExt;
6-
use cargotest::install::exe;
4+
use cargotest::support::registry::Package;
5+
use cargotest::support::{execs, project};
76
use glob::glob;
7+
use hamcrest::{assert_that, existing_file, is_not};
88

99
const SIMPLE_MANIFEST: &str = r#"
1010
[package]
@@ -662,9 +662,8 @@ fn check_artifacts()
662662
is_not(existing_file()));
663663
assert_that(&p.root().join("target/debug").join(exe("foo")),
664664
is_not(existing_file()));
665-
assert_that(glob(&p.root().join("target/debug/t1-*").to_str().unwrap())
666-
.unwrap().count(),
667-
is(equal_to(0)));
665+
assert_eq!(glob(&p.root().join("target/debug/t1-*").to_str().unwrap())
666+
.unwrap().count(), 0);
668667

669668
p.root().join("target").rm_rf();
670669
assert_that(p.cargo("check").arg("--example").arg("ex1"),
@@ -685,7 +684,6 @@ fn check_artifacts()
685684
is_not(existing_file()));
686685
assert_that(&p.root().join("target/debug").join(exe("foo")),
687686
is_not(existing_file()));
688-
assert_that(glob(&p.root().join("target/debug/b1-*").to_str().unwrap())
689-
.unwrap().count(),
690-
is(equal_to(0)));
687+
assert_eq!(glob(&p.root().join("target/debug/b1-*").to_str().unwrap())
688+
.unwrap().count(), 0);
691689
}

0 commit comments

Comments
 (0)