diff options
| author | Abdou Seck <djily02016@gmail.com> | 2020-06-04 10:31:17 -0400 |
|---|---|---|
| committer | Abdou Seck <djily02016@gmail.com> | 2020-06-04 11:18:26 -0400 |
| commit | 8ad5f9bf531a4848b1104b7b389a20171624c82f (patch) | |
| tree | 331c5d3725140b07d836ed8be6df30c8ddfd63fb /src/verify.rs | |
| parent | 02a2fe48714a4546b28d38fb611e6bfce9f43cf6 (diff) | |
feat: Add a --nocapture option to display test harnesses' outputs
This new feature can be accessed by invoking rustlings with --nocapture.
Both unit and integration tests added.
closes #262
BREAKING CHANGES:
The following function take a new boolean argument:
* `run`
* `verify`
* `test`
* `compile_and_test`
Diffstat (limited to 'src/verify.rs')
| -rw-r--r-- | src/verify.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/verify.rs b/src/verify.rs index 6e0e45e..fac0491 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -2,10 +2,18 @@ use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; use indicatif::ProgressBar; -pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<(), &'a Exercise> { +// Verify that the provided container of Exercise objects +// can be compiled and run without any failures. +// Any such failures will be reported to the end user. +// If the Exercise being verified is a test, the verbose boolean +// determines whether or not the test harness outputs are displayed. +pub fn verify<'a>( + start_at: impl IntoIterator<Item = &'a Exercise>, + verbose: bool +) -> Result<(), &'a Exercise> { for exercise in start_at { let compile_result = match exercise.mode { - Mode::Test => compile_and_test(&exercise, RunMode::Interactive), + Mode::Test => compile_and_test(&exercise, RunMode::Interactive, verbose), Mode::Compile => compile_and_run_interactively(&exercise), Mode::Clippy => compile_only(&exercise), }; @@ -21,11 +29,13 @@ enum RunMode { NonInteractive, } -pub fn test(exercise: &Exercise) -> Result<(), ()> { - compile_and_test(exercise, RunMode::NonInteractive)?; +// Compile and run the resulting test harness of the given Exercise +pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> { + compile_and_test(exercise, RunMode::NonInteractive, verbose)?; Ok(()) } +// Invoke the rust compiler without running the resulting binary fn compile_only(exercise: &Exercise) -> Result<bool, ()> { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); @@ -38,6 +48,7 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> { Ok(prompt_for_completion(&exercise, None)) } +// Compile the given Exercise and run the resulting binary in an interactive mode fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); @@ -63,7 +74,11 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> { Ok(prompt_for_completion(&exercise, Some(output.stdout))) } -fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()> { +// Compile the given Exercise as a test harness and display +// the output if verbose is set to true +fn compile_and_test( + exercise: &Exercise, run_mode: RunMode, verbose: bool +) -> Result<bool, ()> { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Testing {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); @@ -73,7 +88,10 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()> progress_bar.finish_and_clear(); match result { - Ok(_) => { + Ok(output) => { + if verbose { + println!("{}", output.stdout); + } success!("Successfully tested {}", &exercise); if let RunMode::Interactive = run_mode { Ok(prompt_for_completion(&exercise, None)) @@ -92,6 +110,8 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()> } } +// Compile the given Exercise and return an object with information +// about the state of the compilation fn compile<'a, 'b>( exercise: &'a Exercise, progress_bar: &'b ProgressBar, |
