@@ -2,10 +2,18 @@ use crate::exercise::{CompiledExercise, Exercise, Mode, State};
22use console:: style;
33use indicatif:: ProgressBar ;
44
5- pub fn verify < ' a > ( start_at : impl IntoIterator < Item = & ' a Exercise > ) -> Result < ( ) , & ' a Exercise > {
5+ // Verify that the provided container of Exercise objects
6+ // can be compiled and run without any failures.
7+ // Any such failures will be reported to the end user.
8+ // If the Exercise being verified is a test, the verbose boolean
9+ // determines whether or not the test harness outputs are displayed.
10+ pub fn verify < ' a > (
11+ start_at : impl IntoIterator < Item = & ' a Exercise > ,
12+ verbose : bool
13+ ) -> Result < ( ) , & ' a Exercise > {
614 for exercise in start_at {
715 let compile_result = match exercise. mode {
8- Mode :: Test => compile_and_test ( & exercise, RunMode :: Interactive ) ,
16+ Mode :: Test => compile_and_test ( & exercise, RunMode :: Interactive , verbose ) ,
917 Mode :: Compile => compile_and_run_interactively ( & exercise) ,
1018 Mode :: Clippy => compile_only ( & exercise) ,
1119 } ;
@@ -21,11 +29,13 @@ enum RunMode {
2129 NonInteractive ,
2230}
2331
24- pub fn test ( exercise : & Exercise ) -> Result < ( ) , ( ) > {
25- compile_and_test ( exercise, RunMode :: NonInteractive ) ?;
32+ // Compile and run the resulting test harness of the given Exercise
33+ pub fn test ( exercise : & Exercise , verbose : bool ) -> Result < ( ) , ( ) > {
34+ compile_and_test ( exercise, RunMode :: NonInteractive , verbose) ?;
2635 Ok ( ( ) )
2736}
2837
38+ // Invoke the rust compiler without running the resulting binary
2939fn compile_only ( exercise : & Exercise ) -> Result < bool , ( ) > {
3040 let progress_bar = ProgressBar :: new_spinner ( ) ;
3141 progress_bar. set_message ( format ! ( "Compiling {}..." , exercise) . as_str ( ) ) ;
@@ -38,6 +48,7 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
3848 Ok ( prompt_for_completion ( & exercise, None ) )
3949}
4050
51+ // Compile the given Exercise and run the resulting binary in an interactive mode
4152fn compile_and_run_interactively ( exercise : & Exercise ) -> Result < bool , ( ) > {
4253 let progress_bar = ProgressBar :: new_spinner ( ) ;
4354 progress_bar. set_message ( format ! ( "Compiling {}..." , exercise) . as_str ( ) ) ;
@@ -63,7 +74,11 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
6374 Ok ( prompt_for_completion ( & exercise, Some ( output. stdout ) ) )
6475}
6576
66- fn compile_and_test ( exercise : & Exercise , run_mode : RunMode ) -> Result < bool , ( ) > {
77+ // Compile the given Exercise as a test harness and display
78+ // the output if verbose is set to true
79+ fn compile_and_test (
80+ exercise : & Exercise , run_mode : RunMode , verbose : bool
81+ ) -> Result < bool , ( ) > {
6782 let progress_bar = ProgressBar :: new_spinner ( ) ;
6883 progress_bar. set_message ( format ! ( "Testing {}..." , exercise) . as_str ( ) ) ;
6984 progress_bar. enable_steady_tick ( 100 ) ;
@@ -73,7 +88,10 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()>
7388 progress_bar. finish_and_clear ( ) ;
7489
7590 match result {
76- Ok ( _) => {
91+ Ok ( output) => {
92+ if verbose {
93+ println ! ( "{}" , output. stdout) ;
94+ }
7795 success ! ( "Successfully tested {}" , & exercise) ;
7896 if let RunMode :: Interactive = run_mode {
7997 Ok ( prompt_for_completion ( & exercise, None ) )
@@ -92,6 +110,8 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()>
92110 }
93111}
94112
113+ // Compile the given Exercise and return an object with information
114+ // about the state of the compilation
95115fn compile < ' a , ' b > (
96116 exercise : & ' a Exercise ,
97117 progress_bar : & ' b ProgressBar ,
0 commit comments