mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 05:39:19 +00:00
fix(verify): print feedback on verify pass for tests
This commit is contained in:
parent
c923e7af73
commit
a6ffd5c84f
@ -15,14 +15,15 @@ pub fn verify<'a>(
|
|||||||
) -> Result<(), &'a Exercise> {
|
) -> Result<(), &'a Exercise> {
|
||||||
let (num_done, total) = progress;
|
let (num_done, total) = progress;
|
||||||
let bar = ProgressBar::new(total as u64);
|
let bar = ProgressBar::new(total as u64);
|
||||||
bar.set_style(ProgressStyle::default_bar()
|
bar.set_style(
|
||||||
.template("Progress: [{bar:60.green/red}] {pos}/{len}")
|
ProgressStyle::default_bar()
|
||||||
.progress_chars("#>-")
|
.template("Progress: [{bar:60.green/red}] {pos}/{len}")
|
||||||
|
.progress_chars("#>-"),
|
||||||
);
|
);
|
||||||
bar.set_position(num_done as u64);
|
bar.set_position(num_done as u64);
|
||||||
for exercise in exercises {
|
for exercise in exercises {
|
||||||
let compile_result = match exercise.mode {
|
let compile_result = match exercise.mode {
|
||||||
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose),
|
Mode::Test => compile_and_test(exercise, verbose),
|
||||||
Mode::Compile => compile_and_run_interactively(exercise),
|
Mode::Compile => compile_and_run_interactively(exercise),
|
||||||
Mode::Clippy => compile_only(exercise),
|
Mode::Clippy => compile_only(exercise),
|
||||||
};
|
};
|
||||||
@ -34,14 +35,9 @@ pub fn verify<'a>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RunMode {
|
|
||||||
Interactive,
|
|
||||||
NonInteractive,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile and run the resulting test harness of the given Exercise
|
// Compile and run the resulting test harness of the given Exercise
|
||||||
pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
||||||
compile_and_test(exercise, RunMode::NonInteractive, verbose)?;
|
compile_and_test(exercise, verbose)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +80,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
|
|||||||
|
|
||||||
// Compile the given Exercise as a test harness and display
|
// Compile the given Exercise as a test harness and display
|
||||||
// the output if verbose is set to true
|
// the output if verbose is set to true
|
||||||
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Result<bool, ()> {
|
fn compile_and_test(exercise: &Exercise, verbose: bool) -> Result<bool, ()> {
|
||||||
let progress_bar = ProgressBar::new_spinner();
|
let progress_bar = ProgressBar::new_spinner();
|
||||||
progress_bar.set_message(format!("Testing {}...", exercise));
|
progress_bar.set_message(format!("Testing {}...", exercise));
|
||||||
progress_bar.enable_steady_tick(100);
|
progress_bar.enable_steady_tick(100);
|
||||||
@ -98,11 +94,7 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
|
|||||||
if verbose {
|
if verbose {
|
||||||
println!("{}", output.stdout);
|
println!("{}", output.stdout);
|
||||||
}
|
}
|
||||||
if let RunMode::Interactive = run_mode {
|
Ok(prompt_for_completion(exercise, None))
|
||||||
Ok(prompt_for_completion(exercise, None))
|
|
||||||
} else {
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(output) => {
|
Err(output) => {
|
||||||
warn!(
|
warn!(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user