1
- use crate :: exercise:: { ContextLine , Exercise , Mode , State } ;
1
+ use crate :: exercise:: { Exercise , Mode , State } ;
2
2
use console:: { style, Emoji } ;
3
3
use indicatif:: ProgressBar ;
4
4
5
5
pub fn verify < ' a > ( start_at : impl IntoIterator < Item = & ' a Exercise > ) -> Result < ( ) , ( ) > {
6
6
for exercise in start_at {
7
7
let is_done = match exercise. mode {
8
- Mode :: Test => test ( & exercise) ?,
8
+ Mode :: Test => compile_and_test_interactively ( & exercise) ?,
9
9
Mode :: Compile => compile_only ( & exercise) ?,
10
10
} ;
11
11
if !is_done {
@@ -15,6 +15,11 @@ pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<()
15
15
Ok ( ( ) )
16
16
}
17
17
18
+ pub fn test ( exercise : & Exercise ) -> Result < ( ) , ( ) > {
19
+ compile_and_test ( exercise, true ) ?;
20
+ Ok ( ( ) )
21
+ }
22
+
18
23
fn compile_only ( exercise : & Exercise ) -> Result < bool , ( ) > {
19
24
let progress_bar = ProgressBar :: new_spinner ( ) ;
20
25
progress_bar. set_message ( format ! ( "Compiling {}..." , exercise) . as_str ( ) ) ;
@@ -25,12 +30,7 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
25
30
let formatstr = format ! ( "{} Successfully compiled {}!" , Emoji ( "✅" , "✓" ) , exercise) ;
26
31
println ! ( "{}" , style( formatstr) . green( ) ) ;
27
32
exercise. clean ( ) ;
28
- if let State :: Pending ( context) = exercise. state ( ) {
29
- print_everything_looks_good ( exercise. mode , context) ;
30
- Ok ( false )
31
- } else {
32
- Ok ( true )
33
- }
33
+ Ok ( prompt_for_completion ( & exercise) )
34
34
} else {
35
35
let formatstr = format ! (
36
36
"{} Compilation of {} failed! Compiler error message:\n " ,
@@ -44,7 +44,11 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
44
44
}
45
45
}
46
46
47
- pub fn test ( exercise : & Exercise ) -> Result < bool , ( ) > {
47
+ fn compile_and_test_interactively ( exercise : & Exercise ) -> Result < bool , ( ) > {
48
+ compile_and_test ( exercise, false )
49
+ }
50
+
51
+ fn compile_and_test ( exercise : & Exercise , skip_prompt : bool ) -> Result < bool , ( ) > {
48
52
let progress_bar = ProgressBar :: new_spinner ( ) ;
49
53
progress_bar. set_message ( format ! ( "Testing {}..." , exercise) . as_str ( ) ) ;
50
54
progress_bar. enable_steady_tick ( 100 ) ;
@@ -60,12 +64,7 @@ pub fn test(exercise: &Exercise) -> Result<bool, ()> {
60
64
let formatstr = format ! ( "{} Successfully tested {}!" , Emoji ( "✅" , "✓" ) , exercise) ;
61
65
println ! ( "{}" , style( formatstr) . green( ) ) ;
62
66
exercise. clean ( ) ;
63
- if let State :: Pending ( context) = exercise. state ( ) {
64
- print_everything_looks_good ( exercise. mode , context) ;
65
- Ok ( false )
66
- } else {
67
- Ok ( true )
68
- }
67
+ Ok ( skip_prompt || prompt_for_completion ( exercise) )
69
68
} else {
70
69
let formatstr = format ! (
71
70
"{} Testing of {} failed! Please try again. Here's the output:" ,
@@ -91,8 +90,13 @@ pub fn test(exercise: &Exercise) -> Result<bool, ()> {
91
90
}
92
91
}
93
92
94
- fn print_everything_looks_good ( mode : Mode , context : Vec < ContextLine > ) {
95
- let success_msg = match mode {
93
+ fn prompt_for_completion ( exercise : & Exercise ) -> bool {
94
+ let context = match exercise. state ( ) {
95
+ State :: Done => return true ,
96
+ State :: Pending ( context) => context,
97
+ } ;
98
+
99
+ let success_msg = match exercise. mode {
96
100
Mode :: Compile => "The code is compiling!" ,
97
101
Mode :: Test => "The code is compiling, and the tests pass!" ,
98
102
} ;
@@ -120,4 +124,6 @@ fn print_everything_looks_good(mode: Mode, context: Vec<ContextLine>) {
120
124
formatted_line
121
125
) ;
122
126
}
127
+
128
+ false
123
129
}
0 commit comments