|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
|
|
|
|
use console::style;
|
|
|
|
|
use indicatif::ProgressBar;
|
|
|
|
|
use indicatif::{ProgressBar, ProgressStyle};
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
|
|
// Verify that the provided container of Exercise objects
|
|
|
|
@ -9,10 +9,18 @@ use std::env;
|
|
|
|
|
// If the Exercise being verified is a test, the verbose boolean
|
|
|
|
|
// determines whether or not the test harness outputs are displayed.
|
|
|
|
|
pub fn verify<'a>(
|
|
|
|
|
start_at: impl IntoIterator<Item = &'a Exercise>,
|
|
|
|
|
exercises: impl IntoIterator<Item = &'a Exercise>,
|
|
|
|
|
progress: (usize, usize),
|
|
|
|
|
verbose: bool,
|
|
|
|
|
) -> Result<(), &'a Exercise> {
|
|
|
|
|
for exercise in start_at {
|
|
|
|
|
let (num_done, total) = progress;
|
|
|
|
|
let bar = ProgressBar::new(total as u64);
|
|
|
|
|
bar.set_style(ProgressStyle::default_bar()
|
|
|
|
|
.template("Progress: [{bar:60.green/red}] {pos}/{len}")
|
|
|
|
|
.progress_chars("#>-")
|
|
|
|
|
);
|
|
|
|
|
bar.set_position(num_done as u64);
|
|
|
|
|
for exercise in exercises {
|
|
|
|
|
let compile_result = match exercise.mode {
|
|
|
|
|
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose),
|
|
|
|
|
Mode::Compile => compile_and_run_interactively(exercise),
|
|
|
|
@ -21,6 +29,7 @@ pub fn verify<'a>(
|
|
|
|
|
if !compile_result.unwrap_or(false) {
|
|
|
|
|
return Err(exercise);
|
|
|
|
|
}
|
|
|
|
|
bar.inc(1);
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
@ -45,7 +54,6 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
|
|
|
|
|
let _ = compile(exercise, &progress_bar)?;
|
|
|
|
|
progress_bar.finish_and_clear();
|
|
|
|
|
|
|
|
|
|
success!("Successfully compiled {}!", exercise);
|
|
|
|
|
Ok(prompt_for_completion(exercise, None))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -71,8 +79,6 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
success!("Successfully ran {}!", exercise);
|
|
|
|
|
|
|
|
|
|
Ok(prompt_for_completion(exercise, Some(output.stdout)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -92,7 +98,6 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
|
|
|
|
|
if verbose {
|
|
|
|
|
println!("{}", output.stdout);
|
|
|
|
|
}
|
|
|
|
|
success!("Successfully tested {}", &exercise);
|
|
|
|
|
if let RunMode::Interactive = run_mode {
|
|
|
|
|
Ok(prompt_for_completion(exercise, None))
|
|
|
|
|
} else {
|
|
|
|
@ -138,6 +143,12 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
|
|
|
|
|
State::Pending(context) => context,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match exercise.mode {
|
|
|
|
|
Mode::Compile => success!("Successfully ran {}!", exercise),
|
|
|
|
|
Mode::Test => success!("Successfully tested {}!", exercise),
|
|
|
|
|
Mode::Clippy => success!("Successfully compiled {}!", exercise),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let no_emoji = env::var("NO_EMOJI").is_ok();
|
|
|
|
|
|
|
|
|
|
let clippy_success_msg = if no_emoji {
|
|
|
|
|