summaryrefslogtreecommitdiffstats
path: root/CLI
diff options
context:
space:
mode:
authora14m <[email protected]>2021-04-09 16:42:38 +0200
committera14m <[email protected]>2021-04-09 16:42:38 +0200
commit7ecf487bc932c8e4e73166b501e66e4b6ff7821a (patch)
treefefe13961d83d0c6bf258c96053bce6e302b67a6 /CLI
parentc9e64f9583b2d1fa4cd887ec4878b5414b2db37f (diff)
Refactor testing of app to be safer (by mocking terminal_size)
Diffstat (limited to 'CLI')
-rw-r--r--CLI/rust/src/game_of_life.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/CLI/rust/src/game_of_life.rs b/CLI/rust/src/game_of_life.rs
index affe003..1f8a2a9 100644
--- a/CLI/rust/src/game_of_life.rs
+++ b/CLI/rust/src/game_of_life.rs
@@ -86,6 +86,7 @@ pub(crate) fn app() -> App<'static> {
mod app {
use super::*;
use mocktopus::mocking::*;
+ use terminal_size::{Height, Width};
#[test]
fn no_options() {
@@ -119,33 +120,29 @@ mod app {
#[test]
fn valid_width() {
+ opts::terminal_size_wrapper.mock_safe(|| MockResult::Return((Width(42), Height(42))));
let matches = app().get_matches_from(vec!["", "--width=13"]);
- validators::is_fitting_term_width.mock_safe(|_| MockResult::Return(Ok(())));
- validators::is_fitting_term_height.mock_safe(|_| MockResult::Return(Ok(())));
assert_eq!(matches.value_of("width"), Some("13"));
}
#[test]
fn valid_height() {
+ opts::terminal_size_wrapper.mock_safe(|| MockResult::Return((Width(42), Height(42))));
let matches = app().get_matches_from(vec!["", "--height=13"]);
- validators::is_fitting_term_width.mock_safe(|_| MockResult::Return(Ok(())));
- validators::is_fitting_term_height.mock_safe(|_| MockResult::Return(Ok(())));
assert_eq!(matches.value_of("height"), Some("13"));
}
#[test]
fn invalid_width() {
+ opts::terminal_size_wrapper.mock_safe(|| MockResult::Return((Width(42), Height(42))));
let matches = app().try_get_matches_from(vec!["", "--width=1337"]);
- validators::is_fitting_term_width.mock_safe(|_| MockResult::Return(Err(String::from("Invalid"))));
- validators::is_fitting_term_height.mock_safe(|_| MockResult::Return(Ok(())));
assert!(matches.is_err());
}
#[test]
fn invalid_height() {
+ opts::terminal_size_wrapper.mock_safe(|| MockResult::Return((Width(42), Height(42))));
let matches = app().try_get_matches_from(vec!["", "--height=1337"]);
- validators::is_fitting_term_width.mock_safe(|_| MockResult::Return(Ok(())));
- validators::is_fitting_term_height.mock_safe(|_| MockResult::Return(Err(String::from("Invalid"))));
assert!(matches.is_err());
}