Skip to content

Commit

Permalink
Replace quickcheck with proptest.
Browse files Browse the repository at this point in the history
Yay, dogfooding shiny new features. The code's a lot smaller too, though
the commit diff isn't entirely fair since this also kills the workaround
for output capturing from when one had to run things on different
threads to catch panics.

This is also substantially faster. I'm not sure why, since it's running
far more tests and `Strategy` by all means should have far more overhead
than `Arbitrary`.
  • Loading branch information
AltSysrq committed Aug 15, 2017
1 parent d6bc773 commit 1993081
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 460 deletions.
122 changes: 33 additions & 89 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lazy_static = "0.2.2"
libc = "0.2.20"
notify = "4.0.0"
num_cpus = "1.2.1"
quick-error = "1.1.0"
quick-error = "1.2.0"
rand = "0.3.15"
regex = "0.2.1"
rpassword = { version = "0.3.1", optional = true }
Expand All @@ -41,9 +41,9 @@ default-features = false
features = []

[dev-dependencies]
quickcheck = "0.4.1"
tempdir = "0.3.5"
os_pipe = "0.4.1"
proptest = "0.2.0"

[features]

Expand Down
50 changes: 6 additions & 44 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,51 +79,14 @@ pub trait Logger {

#[cfg(test)]
mod println_logger {
use std::io::{Result,Write};
use std::sync::{Arc, Mutex};

use super::*;

/// Trivial implementation of `Logger` which simply dumps everything (in
/// debug format) to the given writer.
pub struct PrintlnLogger<W>(Arc<Mutex<W>>);

impl<W> PrintlnLogger<W> {
pub fn new(w: W) -> Self {
PrintlnLogger(Arc::new(Mutex::new(w)))
}
}

impl<W> Clone for PrintlnLogger<W> {
fn clone(&self) -> Self {
PrintlnLogger(self.0.clone())
}
}

/// Writer which logs to the same "stdout" `print!` does, since for some
/// reason that's not accessible via any sane mechanism.
///
/// Panics if a buffer written is not valid UTF-8.
pub struct PrintWriter;
impl Write for PrintWriter {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
use std::str;
print!("{}", str::from_utf8(buf).unwrap());
Ok(buf.len())
}

fn flush(&mut self) -> Result<()> {
Ok(())
}
}

impl PrintlnLogger<PrintWriter> {
pub fn stdout() -> Self {
PrintlnLogger::new(PrintWriter)
}
}
/// debug format) to stdout.
#[derive(Clone, Copy, Debug)]
pub struct PrintlnLogger;

impl<W : Write> Logger for PrintlnLogger<W> {
impl Logger for PrintlnLogger {
fn log(&self, level: LogLevel, what: &Log) {
let level_str = match level {
FATAL => "FATAL",
Expand All @@ -133,11 +96,10 @@ mod println_logger {
INFO => " INFO",
_ => "?????",
};
writeln!(self.0.lock().unwrap(), "[{}] {:?}",
level_str, what).unwrap();
println!("[{}] {:?}", level_str, what);
}
}
}

#[cfg(test)]
pub use self::println_logger::{PrintlnLogger,PrintWriter};
pub use self::println_logger::PrintlnLogger;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ extern crate toml;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate quick_error;

#[cfg(test)] extern crate quickcheck;
#[cfg(test)] extern crate os_pipe;
#[cfg(test)] extern crate tempdir;
#[cfg(test)] #[macro_use] extern crate proptest;

mod defs;
mod errors;
Expand Down
Loading

0 comments on commit 1993081

Please sign in to comment.