Skip to content

Commit

Permalink
Various small changes to cargo_test and friends.
Browse files Browse the repository at this point in the history
- Reworked CargoTestError to contain Vec<ProcessError>
- Remove #[allow(trivial_casts)]
- Coding style fixes
  • Loading branch information
nicokoch committed Sep 12, 2015
1 parent cef86c1 commit 4a30bcd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ pub fn run_tests(manifest_path: &Path,

// If we have an error and want to fail fast, return
if errors.len() > 0 && !options.no_fail_fast {
return Ok(Some(CargoTestError::from(&errors[..])))
return Ok(Some(CargoTestError::new(errors)))
}

// If a specific test was requested or we're not running any tests at all,
// don't run any doc tests.
if let ops::CompileFilter::Only { .. } = options.compile_opts.filter {
match errors.len() {
0 => return Ok(None),
_ => return Ok(Some(CargoTestError::from(&errors[..])))
_ => return Ok(Some(CargoTestError::new(errors)))
}
}

errors.extend(try!(run_doc_tests(options, test_args, &compilation)));
if errors.len() == 0 {
Ok(None)
} else {
Ok(Some(CargoTestError::from(&errors[..])))
Ok(Some(CargoTestError::new(errors)))
}
}

Expand All @@ -56,7 +56,7 @@ pub fn run_benches(manifest_path: &Path,
let errors = try!(run_unit_tests(options, &args, &compilation));
match errors.len() {
0 => Ok(None),
_ => Ok(Some(CargoTestError::from(&errors[..]))),
_ => Ok(Some(CargoTestError::new(errors))),
}
}

Expand Down
37 changes: 19 additions & 18 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl<'a, T, F> ChainError<T> for F where F: FnOnce() -> CargoResult<T> {
}

impl<T, E: CargoError + 'static> ChainError<T> for Result<T, E> {
#[allow(trivial_casts)]
fn chain_error<E2: 'static, C>(self, callback: C) -> CargoResult<T>
where E2: CargoError, C: FnOnce() -> E2 {
self.map_err(move |err| {
Expand Down Expand Up @@ -114,7 +113,6 @@ pub struct ProcessError {

impl Error for ProcessError {
fn description(&self) -> &str { &self.desc }
#[allow(trivial_casts)]
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|s| s as &Error)
}
Expand All @@ -138,7 +136,24 @@ impl fmt::Debug for ProcessError {
pub struct CargoTestError {
pub desc: String,
pub exit: Option<ExitStatus>,
cause: Option<io::Error>,
pub causes: Vec<ProcessError>,
}

impl CargoTestError {
#[allow(deprecated)] // connect => join in 1.3
pub fn new(errors: Vec<ProcessError>) -> Self {
if errors.len() == 0 {
panic!("Cannot create CargoTestError from empty Vec")
}
let desc = errors.iter().map(|error| error.desc.clone())
.collect::<Vec<String>>()
.connect("\n");
CargoTestError {
desc: desc,
exit: errors[0].exit,
causes: errors,
}
}
}

impl fmt::Display for CargoTestError {
Expand All @@ -155,22 +170,8 @@ impl fmt::Debug for CargoTestError {

impl Error for CargoTestError {
fn description(&self) -> &str { &self.desc }
#[allow(trivial_casts)]
fn cause(&self) -> Option<&Error> {
self.cause.as_ref().map(|s| s as &Error)
}
}

#[allow(deprecated)] // connect => join in 1.3
impl<'a> From<&'a [ProcessError]> for CargoTestError {
fn from(errors: &[ProcessError]) -> Self {
if errors.len() == 0 { panic!("Cannot create CargoTestError from empty Vec") }
let desc = errors.iter().map(|error| error.desc.clone()).collect::<Vec<String>>().connect("\n");
CargoTestError {
desc: desc,
exit: errors[0].exit,
cause: None,
}
self.causes.get(0).map(|s| s as &Error)
}
}

Expand Down

0 comments on commit 4a30bcd

Please sign in to comment.