@@ -2,10 +2,18 @@ use crate::exercise::{CompiledExercise, Exercise, Mode, State};
2
2
use console:: style;
3
3
use indicatif:: ProgressBar ;
4
4
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 > {
6
14
for exercise in start_at {
7
15
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 ) ,
9
17
Mode :: Compile => compile_and_run_interactively ( & exercise) ,
10
18
Mode :: Clippy => compile_only ( & exercise) ,
11
19
} ;
@@ -21,11 +29,13 @@ enum RunMode {
21
29
NonInteractive ,
22
30
}
23
31
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) ?;
26
35
Ok ( ( ) )
27
36
}
28
37
38
+ // Invoke the rust compiler without running the resulting binary
29
39
fn compile_only ( exercise : & Exercise ) -> Result < bool , ( ) > {
30
40
let progress_bar = ProgressBar :: new_spinner ( ) ;
31
41
progress_bar. set_message ( format ! ( "Compiling {}..." , exercise) . as_str ( ) ) ;
@@ -38,6 +48,7 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
38
48
Ok ( prompt_for_completion ( & exercise, None ) )
39
49
}
40
50
51
+ // Compile the given Exercise and run the resulting binary in an interactive mode
41
52
fn compile_and_run_interactively ( exercise : & Exercise ) -> Result < bool , ( ) > {
42
53
let progress_bar = ProgressBar :: new_spinner ( ) ;
43
54
progress_bar. set_message ( format ! ( "Compiling {}..." , exercise) . as_str ( ) ) ;
@@ -63,7 +74,11 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
63
74
Ok ( prompt_for_completion ( & exercise, Some ( output. stdout ) ) )
64
75
}
65
76
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 , ( ) > {
67
82
let progress_bar = ProgressBar :: new_spinner ( ) ;
68
83
progress_bar. set_message ( format ! ( "Testing {}..." , exercise) . as_str ( ) ) ;
69
84
progress_bar. enable_steady_tick ( 100 ) ;
@@ -73,7 +88,10 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()>
73
88
progress_bar. finish_and_clear ( ) ;
74
89
75
90
match result {
76
- Ok ( _) => {
91
+ Ok ( output) => {
92
+ if verbose {
93
+ println ! ( "{}" , output. stdout) ;
94
+ }
77
95
success ! ( "Successfully tested {}" , & exercise) ;
78
96
if let RunMode :: Interactive = run_mode {
79
97
Ok ( prompt_for_completion ( & exercise, None ) )
@@ -92,6 +110,8 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode) -> Result<bool, ()>
92
110
}
93
111
}
94
112
113
+ // Compile the given Exercise and return an object with information
114
+ // about the state of the compilation
95
115
fn compile < ' a , ' b > (
96
116
exercise : & ' a Exercise ,
97
117
progress_bar : & ' b ProgressBar ,
0 commit comments