Merge fce23513fa
into 0d65753fdb
This commit is contained in:
commit
20c5e33d80
13
src/main.rs
13
src/main.rs
|
@ -124,7 +124,7 @@ fn main() {
|
|||
}
|
||||
|
||||
if matches.subcommand_matches("verify").is_some() {
|
||||
verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
verify(&exercises, 0, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
if matches.subcommand_matches("watch").is_some() {
|
||||
|
@ -210,7 +210,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
|
|||
clear_screen();
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = match verify(exercises.iter(), verbose) {
|
||||
let failed_exercise_hint = match verify(exercises, 0, verbose) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
|
||||
};
|
||||
|
@ -221,11 +221,12 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
|
|||
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
|
||||
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
|
||||
let filepath = b.as_path().canonicalize().unwrap();
|
||||
let pending_exercises = exercises
|
||||
.iter()
|
||||
.skip_while(|e| !filepath.ends_with(&e.path));
|
||||
let skip_n = match exercises.iter().position(|e| filepath.ends_with(&e.path)) {
|
||||
Some(index) => index,
|
||||
None => continue,
|
||||
};
|
||||
clear_screen();
|
||||
match verify(pending_exercises, verbose) {
|
||||
match verify(exercises, skip_n, verbose) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(exercise) => {
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
||||
use console::style;
|
||||
use indicatif::ProgressBar;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
// Verify that the provided container of Exercise objects
|
||||
// can be compiled and run without any failures.
|
||||
|
@ -8,10 +8,17 @@ use indicatif::ProgressBar;
|
|||
// 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>,
|
||||
verbose: bool,
|
||||
exercises: &'a [Exercise],
|
||||
skip_n: usize,
|
||||
verbose: bool
|
||||
) -> Result<(), &'a Exercise> {
|
||||
for exercise in start_at {
|
||||
let bar = ProgressBar::new(exercises.len() as u64);
|
||||
bar.set_style(ProgressStyle::default_bar()
|
||||
.template("Progress: [{bar:60.green/red}] {pos}/{len}")
|
||||
.progress_chars("#>-")
|
||||
);
|
||||
bar.set_position(skip_n as u64);
|
||||
for exercise in exercises.iter().skip(skip_n) {
|
||||
let compile_result = match exercise.mode {
|
||||
Mode::Test => compile_and_test(&exercise, RunMode::Interactive, verbose),
|
||||
Mode::Compile => compile_and_run_interactively(&exercise),
|
||||
|
@ -20,6 +27,7 @@ pub fn verify<'a>(
|
|||
if !compile_result.unwrap_or(false) {
|
||||
return Err(exercise);
|
||||
}
|
||||
bar.inc(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -44,7 +52,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))
|
||||
}
|
||||
|
||||
|
@ -70,8 +77,6 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
|||
}
|
||||
};
|
||||
|
||||
success!("Successfully ran {}!", exercise);
|
||||
|
||||
Ok(prompt_for_completion(&exercise, Some(output.stdout)))
|
||||
}
|
||||
|
||||
|
@ -91,7 +96,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 {
|
||||
|
@ -137,6 +141,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 success_msg = match exercise.mode {
|
||||
Mode::Compile => "The code is compiling!",
|
||||
Mode::Test => "The code is compiling, and the tests pass!",
|
||||
|
|
Loading…
Reference in a new issue