Skip to content

update dependencies, drop time dependency, fix compiler and clippy warnings #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "rspec"
description = "Write Rspec-like tests with stable rust"
version = "1.0.0"
edition = "2015"

readme = "README.md"
repository = "https://github.com/rust-rspec/rspec"
Expand All @@ -23,17 +24,11 @@ categories = [
"development-tools::testing"
]


[build-dependencies.clippy]
optional = true
version = "0.0.153"

[dependencies]
colored = "2.0"
derive-new = "0.5"
derive_builder = "0.9"
derive-new = "0.6"
derive_builder = "0.20"
rayon = "1.5"
time = "0.2"

[dependencies.expectest]
optional = true
Expand Down
3 changes: 2 additions & 1 deletion src/block/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use header::{ContextHeader, ContextLabel, ExampleHeader, ExampleLabel};
use report::ExampleResult;

/// Test contexts are a convenient tool for adding structure and code sharing to a test suite.
#[allow(clippy::type_complexity)]
pub struct Context<T> {
pub(crate) header: Option<ContextHeader>,
pub(crate) blocks: Vec<Block<T>>,
Expand Down Expand Up @@ -285,7 +286,7 @@ where
use std::panic::{catch_unwind, AssertUnwindSafe};

let example = Example::new(header, move |environment| {
let result = catch_unwind(AssertUnwindSafe(|| body(&environment).into()));
let result = catch_unwind(AssertUnwindSafe(|| body(environment).into()));
match result {
Ok(result) => result,
Err(error) => {
Expand Down
12 changes: 4 additions & 8 deletions src/block/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ mod tests {
let suite = suite("name", (), |_| {});
assert_eq!(suite.header.label, SuiteLabel::Suite);
assert_eq!(suite.header.name, "name");
assert_eq!(suite.environment, ());
assert_eq!(suite.is_empty(), true);
assert!(suite.is_empty());
assert_eq!(suite.num_examples(), 0);
}

Expand All @@ -134,8 +133,7 @@ mod tests {
let describe = describe("name", (), |_| {});
assert_eq!(describe.header.label, SuiteLabel::Describe);
assert_eq!(describe.header.name, "name");
assert_eq!(describe.environment, ());
assert_eq!(describe.is_empty(), true);
assert!(describe.is_empty());
assert_eq!(describe.num_examples(), 0);
}

Expand All @@ -144,8 +142,7 @@ mod tests {
let given = given("name", (), |_| {});
assert_eq!(given.header.label, SuiteLabel::Given);
assert_eq!(given.header.name, "name");
assert_eq!(given.environment, ());
assert_eq!(given.is_empty(), true);
assert!(given.is_empty());
assert_eq!(given.num_examples(), 0);
}

Expand All @@ -156,8 +153,7 @@ mod tests {
});
assert_eq!(suite.header.label, SuiteLabel::Suite);
assert_eq!(suite.header.name, "suite");
assert_eq!(suite.environment, ());
assert_eq!(suite.is_empty(), false);
assert!(!suite.is_empty());
assert_eq!(suite.num_examples(), 0);
}
}
6 changes: 4 additions & 2 deletions src/header/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ mod tests {
fn label_fmt() {
fn subject(label: ContextLabel) -> String {
format!("{}", label)
};
}

assert_eq!(subject(ContextLabel::Context), "Context".to_owned());
assert_eq!(subject(ContextLabel::Specify), "Specify".to_owned());
assert_eq!(subject(ContextLabel::When), "When".to_owned());
Expand All @@ -49,7 +50,8 @@ mod tests {
fn header_fmt() {
fn subject(label: ContextLabel) -> String {
format!("{}", ContextHeader::new(label, "Test"))
};
}

assert_eq!(
subject(ContextLabel::Context),
"Context \"Test\"".to_owned()
Expand Down
6 changes: 4 additions & 2 deletions src/header/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ mod tests {
fn label_fmt() {
fn subject(label: ExampleLabel) -> String {
format!("{}", label)
};
}

assert_eq!(subject(ExampleLabel::Example), "Example".to_owned());
assert_eq!(subject(ExampleLabel::It), "It".to_owned());
assert_eq!(subject(ExampleLabel::Then), "Then".to_owned());
Expand All @@ -57,7 +58,8 @@ mod tests {
fn header_fmt() {
fn subject(label: ExampleLabel) -> String {
format!("{}", ExampleHeader::new(label, "Test"))
};
}

assert_eq!(
subject(ExampleLabel::Example),
"Example \"Test\"".to_owned()
Expand Down
6 changes: 4 additions & 2 deletions src/header/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ mod tests {
fn label_fmt() {
fn subject(label: SuiteLabel) -> String {
format!("{}", label)
};
}

assert_eq!(subject(SuiteLabel::Suite), "Suite".to_owned());
assert_eq!(subject(SuiteLabel::Describe), "Describe".to_owned());
assert_eq!(subject(SuiteLabel::Given), "Given".to_owned());
Expand All @@ -49,7 +50,8 @@ mod tests {
fn header_fmt() {
fn subject(label: SuiteLabel) -> String {
format!("{}", SuiteHeader::new(label, "Test"))
};
}

assert_eq!(subject(SuiteLabel::Suite), "Suite \"Test\"".to_owned());
assert_eq!(
subject(SuiteLabel::Describe),
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![doc(html_root_url = "https://mackwic.github.io/rspec")]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![allow(dead_code)]

#[macro_use]
Expand All @@ -13,7 +11,6 @@ extern crate colored;
#[cfg(feature = "expectest_compat")]
extern crate expectest;
extern crate rayon;
extern crate time;

pub mod block;
pub mod header;
Expand Down Expand Up @@ -64,8 +61,8 @@ where
#[cfg(test)]
mod tests {

pub use super::*;
pub use block::*;
//pub use super::*;
//pub use block::*;

// Test list:
// x check that tests can call `assert_eq!`
Expand Down
4 changes: 2 additions & 2 deletions src/logger/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;
use std::ops::DerefMut;
use std::sync::Mutex;

use time::Duration;
use std::time::Duration;

use colored::*;

Expand Down Expand Up @@ -162,7 +162,7 @@ impl<T: io::Write> SerialLogger<T> {
let minute = 60 * second;
let hour = 60 * minute;

let remainder = duration.whole_milliseconds();
let remainder = duration.subsec_millis();

let hours = remainder / hour;
let remainder = remainder % hour;
Expand Down
3 changes: 2 additions & 1 deletion src/report/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use report::{BlockReport, Report};
use time::Duration;

/// `ContextReport` holds the results of a context's test execution.
#[derive(PartialEq, Eq, Clone, Debug, new)]
Expand Down
3 changes: 1 addition & 2 deletions src/report/example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::convert::From;

use time::Duration;
use std::time::Duration;

use report::Report;

Expand Down
2 changes: 1 addition & 1 deletion src/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod context;
mod example;
mod suite;

pub use time::Duration;
use std::time::Duration;

pub use report::context::*;
pub use report::example::*;
Expand Down
2 changes: 1 addition & 1 deletion src/report/suite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use time::Duration;
use std::time::Duration;

use header::SuiteHeader;
use report::{ContextReport, Report};
Expand Down
16 changes: 8 additions & 8 deletions src/runner/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ mod tests {
#[test]
fn default_with_builder() {
let config = ConfigurationBuilder::default().build().unwrap();
assert_eq!(config.parallel, true);
assert_eq!(config.exit_on_failure, true);
assert!(config.parallel);
assert!(config.exit_on_failure);
}

#[test]
Expand All @@ -43,21 +43,21 @@ mod tests {
#[test]
fn builder() {
let config = ConfigurationBuilder::default().build().unwrap();
assert_eq!(config.parallel, true);
assert_eq!(config.exit_on_failure, true);
assert!(config.parallel);
assert!(config.exit_on_failure);

let config = ConfigurationBuilder::default()
.parallel(false)
.build()
.unwrap();
assert_eq!(config.parallel, false);
assert_eq!(config.exit_on_failure, true);
assert!(!config.parallel);
assert!(config.exit_on_failure);

let config = ConfigurationBuilder::default()
.exit_on_failure(false)
.build()
.unwrap();
assert_eq!(config.parallel, true);
assert_eq!(config.exit_on_failure, false);
assert!(config.parallel);
assert!(!config.exit_on_failure);
}
}
29 changes: 14 additions & 15 deletions src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use std::panic;
#[cfg(not(test))]
use std::process;
use std::sync::{Arc, Mutex};

use time::Instant;
use std::time::Instant;

use rayon::prelude::*;

Expand Down Expand Up @@ -228,7 +227,7 @@ where

fn visit(&self, context: &Context<T>, environment: &mut Self::Environment) -> Self::Output {
if let Some(ref header) = context.header {
self.broadcast(|handler| handler.enter_context(self, &header));
self.broadcast(|handler| handler.enter_context(self, header));
}
let start_time = Instant::now();
let reports: Vec<_> = self.wrap_all(context, environment, |environment| {
Expand All @@ -242,7 +241,7 @@ where
let elapsed_time = end_time - start_time;
let report = ContextReport::new(reports, elapsed_time);
if let Some(ref header) = context.header {
self.broadcast(|handler| handler.exit_context(self, &header, &report));
self.broadcast(|handler| handler.exit_context(self, header, &report));
}
report
}
Expand Down Expand Up @@ -300,7 +299,7 @@ mod tests {
// act
runner.broadcast(|_| has_been_called.store(true, Ordering::SeqCst));
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand Down Expand Up @@ -347,7 +346,7 @@ mod tests {
runner.broadcast(|observer| observer.enter_suite(&runner, &expected.clone()));
// assert
let lock = spy1.events.lock().expect("no dangling threads");
let res = (*lock).get(0).expect("to have been called once");
let res = (*lock).first().expect("to have been called once");
assert_eq!(&("enter_suite", expected), res);
}
}
Expand Down Expand Up @@ -376,7 +375,7 @@ mod tests {
has_been_called.store(true, Ordering::SeqCst)
});
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand All @@ -390,7 +389,7 @@ mod tests {
context.before_each(move |_| closure_bool_handler.store(true, Ordering::SeqCst));
runner.wrap_each(&context, &mut (), |_| ());
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand All @@ -404,7 +403,7 @@ mod tests {
context.after_each(move |_| closure_bool_handler.store(true, Ordering::SeqCst));
runner.wrap_each(&context, &mut (), |_| ());
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand Down Expand Up @@ -510,7 +509,7 @@ mod tests {
has_been_called.store(true, Ordering::SeqCst)
});
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand All @@ -524,7 +523,7 @@ mod tests {
context.before_all(move |_| closure_bool_handler.store(true, Ordering::SeqCst));
runner.wrap_all(&context, &mut (), |_| ());
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand All @@ -538,7 +537,7 @@ mod tests {
context.after_all(move |_| closure_bool_handler.store(true, Ordering::SeqCst));
runner.wrap_all(&context, &mut (), |_| ());
// assert
assert_eq!(true, has_been_called.load(Ordering::SeqCst));
assert!(has_been_called.load(Ordering::SeqCst));
}

#[test]
Expand Down Expand Up @@ -688,8 +687,8 @@ mod tests {
// act
runner.visit(&example, &mut ());
// assert
assert_eq!(true, spy.enter_example.load(Ordering::SeqCst));
assert_eq!(true, spy.exit_example.load(Ordering::SeqCst))
assert!(spy.enter_example.load(Ordering::SeqCst));
assert!(spy.exit_example.load(Ordering::SeqCst))
}

#[test]
Expand All @@ -704,7 +703,7 @@ mod tests {
});
runner.visit(&example, &mut environment);
// assert
assert_eq!(true, environment.load(Ordering::SeqCst));
assert!(environment.load(Ordering::SeqCst));
}
}

Expand Down