@@ -12,6 +12,7 @@ pub fn verify<'a>(
12
12
exercises : impl IntoIterator < Item = & ' a Exercise > ,
13
13
progress : ( usize , usize ) ,
14
14
verbose : bool ,
15
+ success_hints : bool ,
15
16
) -> Result < ( ) , & ' a Exercise > {
16
17
let ( num_done, total) = progress;
17
18
let bar = ProgressBar :: new ( total as u64 ) ;
@@ -25,9 +26,9 @@ pub fn verify<'a>(
25
26
26
27
for exercise in exercises {
27
28
let compile_result = match exercise. mode {
28
- Mode :: Test => compile_and_test ( exercise, RunMode :: Interactive , verbose) ,
29
- Mode :: Compile => compile_and_run_interactively ( exercise) ,
30
- Mode :: Clippy => compile_only ( exercise) ,
29
+ Mode :: Test => compile_and_test ( exercise, RunMode :: Interactive , verbose, success_hints ) ,
30
+ Mode :: Compile => compile_and_run_interactively ( exercise, success_hints ) ,
31
+ Mode :: Clippy => compile_only ( exercise, success_hints ) ,
31
32
} ;
32
33
if !compile_result. unwrap_or ( false ) {
33
34
return Err ( exercise) ;
@@ -46,24 +47,24 @@ enum RunMode {
46
47
47
48
// Compile and run the resulting test harness of the given Exercise
48
49
pub fn test ( exercise : & Exercise , verbose : bool ) -> Result < ( ) , ( ) > {
49
- compile_and_test ( exercise, RunMode :: NonInteractive , verbose) ?;
50
+ compile_and_test ( exercise, RunMode :: NonInteractive , verbose, false ) ?;
50
51
Ok ( ( ) )
51
52
}
52
53
53
54
// Invoke the rust compiler without running the resulting binary
54
- fn compile_only ( exercise : & Exercise ) -> Result < bool , ( ) > {
55
+ fn compile_only ( exercise : & Exercise , success_hints : bool ) -> Result < bool , ( ) > {
55
56
let progress_bar = ProgressBar :: new_spinner ( ) ;
56
57
progress_bar. set_message ( format ! ( "Compiling {exercise}..." ) ) ;
57
58
progress_bar. enable_steady_tick ( 100 ) ;
58
59
59
60
let _ = compile ( exercise, & progress_bar) ?;
60
61
progress_bar. finish_and_clear ( ) ;
61
62
62
- Ok ( prompt_for_completion ( exercise, None ) )
63
+ Ok ( prompt_for_completion ( exercise, None , success_hints ) )
63
64
}
64
65
65
66
// Compile the given Exercise and run the resulting binary in an interactive mode
66
- fn compile_and_run_interactively ( exercise : & Exercise ) -> Result < bool , ( ) > {
67
+ fn compile_and_run_interactively ( exercise : & Exercise , success_hints : bool ) -> Result < bool , ( ) > {
67
68
let progress_bar = ProgressBar :: new_spinner ( ) ;
68
69
progress_bar. set_message ( format ! ( "Compiling {exercise}..." ) ) ;
69
70
progress_bar. enable_steady_tick ( 100 ) ;
@@ -84,12 +85,12 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
84
85
}
85
86
} ;
86
87
87
- Ok ( prompt_for_completion ( exercise, Some ( output. stdout ) ) )
88
+ Ok ( prompt_for_completion ( exercise, Some ( output. stdout ) , success_hints ) )
88
89
}
89
90
90
91
// Compile the given Exercise as a test harness and display
91
92
// the output if verbose is set to true
92
- fn compile_and_test ( exercise : & Exercise , run_mode : RunMode , verbose : bool ) -> Result < bool , ( ) > {
93
+ fn compile_and_test ( exercise : & Exercise , run_mode : RunMode , verbose : bool , success_hints : bool ) -> Result < bool , ( ) > {
93
94
let progress_bar = ProgressBar :: new_spinner ( ) ;
94
95
progress_bar. set_message ( format ! ( "Testing {exercise}..." ) ) ;
95
96
progress_bar. enable_steady_tick ( 100 ) ;
@@ -104,7 +105,7 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
104
105
println ! ( "{}" , output. stdout) ;
105
106
}
106
107
if let RunMode :: Interactive = run_mode {
107
- Ok ( prompt_for_completion ( exercise, None ) )
108
+ Ok ( prompt_for_completion ( exercise, None , success_hints ) )
108
109
} else {
109
110
Ok ( true )
110
111
}
@@ -142,12 +143,11 @@ fn compile<'a, 'b>(
142
143
}
143
144
}
144
145
145
- fn prompt_for_completion ( exercise : & Exercise , prompt_output : Option < String > ) -> bool {
146
+ fn prompt_for_completion ( exercise : & Exercise , prompt_output : Option < String > , success_hints : bool ) -> bool {
146
147
let context = match exercise. state ( ) {
147
148
State :: Done => return true ,
148
149
State :: Pending ( context) => context,
149
150
} ;
150
-
151
151
match exercise. mode {
152
152
Mode :: Compile => success ! ( "Successfully ran {}!" , exercise) ,
153
153
Mode :: Test => success ! ( "Successfully tested {}!" , exercise) ,
@@ -167,7 +167,6 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
167
167
Mode :: Test => "The code is compiling, and the tests pass!" ,
168
168
Mode :: Clippy => clippy_success_msg,
169
169
} ;
170
-
171
170
println ! ( ) ;
172
171
if no_emoji {
173
172
println ! ( "~*~ {success_msg} ~*~" )
@@ -183,6 +182,13 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
183
182
println ! ( "{}" , separator( ) ) ;
184
183
println ! ( ) ;
185
184
}
185
+ if success_hints {
186
+ println ! ( "Hints:" ) ;
187
+ println ! ( "{}" , separator( ) ) ;
188
+ println ! ( "{}" , exercise. hint) ;
189
+ println ! ( "{}" , separator( ) ) ;
190
+ println ! ( ) ;
191
+ }
186
192
187
193
println ! ( "You can keep working on this exercise," ) ;
188
194
println ! (
0 commit comments