From 37e96a6ac958d3856377c75b22cbad54ac98e1d6 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Tue, 2 Apr 2019 12:39:33 -0400 Subject: [PATCH 01/10] introduce `Expect` type used by test helpers to describe expected result --- tests/files.rs | 8 +++--- tests/path.rs | 10 +++---- tests/run.rs | 72 +++++++++++++++++++++++++------------------------- tests/stdio.rs | 45 +++++++++++++------------------ tests/utils.rs | 62 ++++++++++++++++++++++++++++++++++++------- 5 files changed, 116 insertions(+), 81 deletions(-) diff --git a/tests/files.rs b/tests/files.rs index cfc1956..00b708e 100644 --- a/tests/files.rs +++ b/tests/files.rs @@ -9,7 +9,7 @@ mod utils; use scriptkeeper::R; -use utils::test_run; +use utils::{test_run, Expect}; #[test] fn allows_to_mock_files_existence() -> R<()> { @@ -27,7 +27,7 @@ fn allows_to_mock_files_existence() -> R<()> { | mockedFiles: | - /foo ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -48,7 +48,7 @@ fn allows_to_mock_directory_existence() -> R<()> { | mockedFiles: | - /foo/ ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -66,7 +66,7 @@ fn does_not_mock_existence_of_unspecified_files() -> R<()> { |tests: | - steps: [] ", - Ok(()), + Expect::ok(), )?; Ok(()) } diff --git a/tests/path.rs b/tests/path.rs index 9ab193a..7b2340a 100644 --- a/tests/path.rs +++ b/tests/path.rs @@ -9,7 +9,7 @@ mod utils; use scriptkeeper::R; use test_utils::trim_margin; -use utils::test_run; +use utils::{test_run, Expect}; #[test] fn looks_up_step_executable_in_path() -> R<()> { @@ -22,7 +22,7 @@ fn looks_up_step_executable_in_path() -> R<()> { |steps: | - cp ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -40,7 +40,7 @@ fn looks_up_unmocked_command_executable_in_path() -> R<()> { |unmockedCommands: | - ls ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -56,7 +56,7 @@ fn shortens_received_executable_to_file_name_when_reporting_step_error() -> R<() |steps: | - cp ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp @@ -78,7 +78,7 @@ fn runs_step_executable_that_is_not_in_path() -> R<()> { |steps: | - /not/in/path ", - Ok(()), + Expect::ok(), )?; Ok(()) } diff --git a/tests/run.rs b/tests/run.rs index b97dc0c..f7bd4c0 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -14,7 +14,7 @@ use std::env; use std::fs; use std::path::PathBuf; use test_utils::{assert_error, trim_margin, TempFile}; -use utils::{prepare_script, test_run, test_run_with_tempfile}; +use utils::{prepare_script, test_run, test_run_with_tempfile, Expect}; #[test] fn simple() -> R<()> { @@ -27,7 +27,7 @@ fn simple() -> R<()> { |steps: | - cp ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -99,7 +99,7 @@ fn can_specify_interpreter() -> R<()> { | - "true" |interpreter: /usr/bin/ruby "#, - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -116,7 +116,7 @@ fn allows_to_match_command_with_regex() -> R<()> { | - steps: | - regex: cp \d "#, - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -182,7 +182,7 @@ fn multiple() -> R<()> { | - cp | - ls ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -198,7 +198,7 @@ fn failing() -> R<()> { |steps: | - cp ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp @@ -222,7 +222,7 @@ fn failing_later() -> R<()> { | - ls | - cp ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp @@ -368,7 +368,7 @@ mod arguments { |steps: | - cp foo ", - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -384,7 +384,7 @@ mod arguments { |steps: | - cp foo ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp foo @@ -406,7 +406,7 @@ mod arguments { |steps: | - cp "foo bar" "#, - Ok(()), + Expect::ok(), )?; Ok(()) } @@ -422,7 +422,7 @@ mod arguments { |steps: | - cp "foo bar" "#, - Err(&trim_margin( + Expect::err(&trim_margin( r#" |error: | expected: cp "foo bar" @@ -447,7 +447,7 @@ fn reports_the_first_error() -> R<()> { | - cp first | - cp second ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp first @@ -473,7 +473,7 @@ mod mismatch_in_number_of_commands { | - ls | - cp ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: cp @@ -496,7 +496,7 @@ mod mismatch_in_number_of_commands { |steps: | - ls ", - Err(&trim_margin( + Expect::err(&trim_margin( " |error: | expected: