1
1
use crate :: exercise:: { CompiledExercise , Exercise , Mode , State } ;
2
2
use console:: style;
3
- use indicatif:: ProgressBar ;
3
+ use indicatif:: { ProgressBar , ProgressStyle } ;
4
4
use std:: env;
5
5
6
6
// Verify that the provided container of Exercise objects
@@ -9,10 +9,18 @@ use std::env;
9
9
// If the Exercise being verified is a test, the verbose boolean
10
10
// determines whether or not the test harness outputs are displayed.
11
11
pub fn verify < ' a > (
12
- start_at : impl IntoIterator < Item = & ' a Exercise > ,
12
+ exercises : impl IntoIterator < Item = & ' a Exercise > ,
13
+ progress : ( usize , usize ) ,
13
14
verbose : bool ,
14
15
) -> Result < ( ) , & ' a Exercise > {
15
- for exercise in start_at {
16
+ let ( num_done, total) = progress;
17
+ let bar = ProgressBar :: new ( total as u64 ) ;
18
+ bar. set_style ( ProgressStyle :: default_bar ( )
19
+ . template ( "Progress: [{bar:60.green/red}] {pos}/{len}" )
20
+ . progress_chars ( "#>-" )
21
+ ) ;
22
+ bar. set_position ( num_done as u64 ) ;
23
+ for exercise in exercises {
16
24
let compile_result = match exercise. mode {
17
25
Mode :: Test => compile_and_test ( exercise, RunMode :: Interactive , verbose) ,
18
26
Mode :: Compile => compile_and_run_interactively ( exercise) ,
@@ -21,6 +29,7 @@ pub fn verify<'a>(
21
29
if !compile_result. unwrap_or ( false ) {
22
30
return Err ( exercise) ;
23
31
}
32
+ bar. inc ( 1 ) ;
24
33
}
25
34
Ok ( ( ) )
26
35
}
@@ -45,7 +54,6 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
45
54
let _ = compile ( exercise, & progress_bar) ?;
46
55
progress_bar. finish_and_clear ( ) ;
47
56
48
- success ! ( "Successfully compiled {}!" , exercise) ;
49
57
Ok ( prompt_for_completion ( exercise, None ) )
50
58
}
51
59
@@ -71,8 +79,6 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
71
79
}
72
80
} ;
73
81
74
- success ! ( "Successfully ran {}!" , exercise) ;
75
-
76
82
Ok ( prompt_for_completion ( exercise, Some ( output. stdout ) ) )
77
83
}
78
84
@@ -92,7 +98,6 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
92
98
if verbose {
93
99
println ! ( "{}" , output. stdout) ;
94
100
}
95
- success ! ( "Successfully tested {}" , & exercise) ;
96
101
if let RunMode :: Interactive = run_mode {
97
102
Ok ( prompt_for_completion ( exercise, None ) )
98
103
} else {
@@ -138,6 +143,12 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
138
143
State :: Pending ( context) => context,
139
144
} ;
140
145
146
+ match exercise. mode {
147
+ Mode :: Compile => success ! ( "Successfully ran {}!" , exercise) ,
148
+ Mode :: Test => success ! ( "Successfully tested {}!" , exercise) ,
149
+ Mode :: Clippy => success ! ( "Successfully compiled {}!" , exercise) ,
150
+ }
151
+
141
152
let no_emoji = env:: var ( "NO_EMOJI" ) . is_ok ( ) ;
142
153
143
154
let clippy_success_msg = if no_emoji {
0 commit comments