Skip to content

Commit

Permalink
Refactore test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Dec 15, 2019
1 parent f9d077c commit d5b3929
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ pub enum CommandResult {
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::init;

use env_logger;
use spectral::{AssertionFailure, Spec};
use spectral::prelude::*;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

#[test]
fn execution_ok() {
init();
Expand All @@ -163,7 +160,7 @@ mod tests {
fn execution_failed() {
init();

let command = Command::new("uname", r#"/usr/bin/false"#, 1);
let command = Command::new("false", r#"/usr/bin/false"#, 1);

let res = command.exec();

Expand All @@ -174,7 +171,7 @@ mod tests {
fn execution_timeout() {
init();

let command = Command::new("uname", r#"/bin/sleep 5"#, 1);
let command = Command::new("sleep", r#"/bin/sleep 5"#, 1);

let res = command.exec();

Expand All @@ -185,7 +182,7 @@ mod tests {
fn execution_error() {
init();

let command = Command::new("uname", r#"/no_such_command"#, 1);
let command = Command::new("no_such_command", r#"/no_such_command"#, 1);

let res = command.exec();

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
/// External CLI commands used to collect USE report information.
pub mod command;

/// Test helper
#[cfg(test)]
pub(crate) mod tests;
4 changes: 4 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Initialize environment for tests, e.g. Logging.
pub(crate) fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}

0 comments on commit d5b3929

Please sign in to comment.