1
1
use crate :: exercise:: { CompiledExercise , Exercise , Mode , State } ;
2
2
use console:: style;
3
3
use indicatif:: { ProgressBar , ProgressStyle } ;
4
- use std:: env;
4
+ use std:: { env, time :: Duration } ;
5
5
6
6
// Verify that the provided container of Exercise objects
7
7
// can be compiled and run without any failures.
@@ -17,9 +17,11 @@ pub fn verify<'a>(
17
17
let ( num_done, total) = progress;
18
18
let bar = ProgressBar :: new ( total as u64 ) ;
19
19
let mut percentage = num_done as f32 / total as f32 * 100.0 ;
20
- bar. set_style ( ProgressStyle :: default_bar ( )
21
- . template ( "Progress: [{bar:60.green/red}] {pos}/{len} {msg}" )
22
- . progress_chars ( "#>-" )
20
+ bar. set_style (
21
+ ProgressStyle :: default_bar ( )
22
+ . template ( "Progress: [{bar:60.green/red}] {pos}/{len} {msg}" )
23
+ . expect ( "Progressbar template should be valid!" )
24
+ . progress_chars ( "#>-" ) ,
23
25
) ;
24
26
bar. set_position ( num_done as u64 ) ;
25
27
bar. set_message ( format ! ( "({:.1} %)" , percentage) ) ;
@@ -55,7 +57,7 @@ pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
55
57
fn compile_only ( exercise : & Exercise , success_hints : bool ) -> Result < bool , ( ) > {
56
58
let progress_bar = ProgressBar :: new_spinner ( ) ;
57
59
progress_bar. set_message ( format ! ( "Compiling {exercise}..." ) ) ;
58
- progress_bar. enable_steady_tick ( 100 ) ;
60
+ progress_bar. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
59
61
60
62
let _ = compile ( exercise, & progress_bar) ?;
61
63
progress_bar. finish_and_clear ( ) ;
@@ -67,7 +69,7 @@ fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
67
69
fn compile_and_run_interactively ( exercise : & Exercise , success_hints : bool ) -> Result < bool , ( ) > {
68
70
let progress_bar = ProgressBar :: new_spinner ( ) ;
69
71
progress_bar. set_message ( format ! ( "Compiling {exercise}..." ) ) ;
70
- progress_bar. enable_steady_tick ( 100 ) ;
72
+ progress_bar. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
71
73
72
74
let compilation = compile ( exercise, & progress_bar) ?;
73
75
@@ -85,15 +87,24 @@ fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Re
85
87
}
86
88
} ;
87
89
88
- Ok ( prompt_for_completion ( exercise, Some ( output. stdout ) , success_hints) )
90
+ Ok ( prompt_for_completion (
91
+ exercise,
92
+ Some ( output. stdout ) ,
93
+ success_hints,
94
+ ) )
89
95
}
90
96
91
97
// Compile the given Exercise as a test harness and display
92
98
// the output if verbose is set to true
93
- fn compile_and_test ( exercise : & Exercise , run_mode : RunMode , verbose : bool , success_hints : bool ) -> Result < bool , ( ) > {
99
+ fn compile_and_test (
100
+ exercise : & Exercise ,
101
+ run_mode : RunMode ,
102
+ verbose : bool ,
103
+ success_hints : bool ,
104
+ ) -> Result < bool , ( ) > {
94
105
let progress_bar = ProgressBar :: new_spinner ( ) ;
95
106
progress_bar. set_message ( format ! ( "Testing {exercise}..." ) ) ;
96
- progress_bar. enable_steady_tick ( 100 ) ;
107
+ progress_bar. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
97
108
98
109
let compilation = compile ( exercise, & progress_bar) ?;
99
110
let result = compilation. run ( ) ;
@@ -143,7 +154,11 @@ fn compile<'a, 'b>(
143
154
}
144
155
}
145
156
146
- fn prompt_for_completion ( exercise : & Exercise , prompt_output : Option < String > , success_hints : bool ) -> bool {
157
+ fn prompt_for_completion (
158
+ exercise : & Exercise ,
159
+ prompt_output : Option < String > ,
160
+ success_hints : bool ,
161
+ ) -> bool {
147
162
let context = match exercise. state ( ) {
148
163
State :: Done => return true ,
149
164
State :: Pending ( context) => context,
0 commit comments