summaryrefslogtreecommitdiff
path: root/src/run.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-04 21:06:11 +0200
committermo8it <mo8it@proton.me>2024-04-04 21:06:11 +0200
commit34375b2ebfbdb0b6504a56c82635c8c9d3d6ce59 (patch)
treecad0bc7aa09a386adcd2e3521960eba632e4b75a /src/run.rs
parent9ea744a7104f441ef505db0a96e852f93d8c0bf4 (diff)
Clean up as a preparation for the TUI
Diffstat (limited to 'src/run.rs')
-rw-r--r--src/run.rs38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/run.rs b/src/run.rs
index 3f93f14..0a09ecc 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,39 +1,27 @@
-use anyhow::{bail, Result};
+use anyhow::Result;
use std::io::{stdout, Write};
-use std::time::Duration;
-use crate::exercise::{Exercise, Mode};
-use crate::verify::test;
-use indicatif::ProgressBar;
+use crate::exercise::Exercise;
// Invoke the rust compiler on the path of the given exercise,
// and run the ensuing binary.
// The verbose argument helps determine whether or not to show
// the output from the test harnesses (if the mode of the exercise is test)
-pub fn run(exercise: &Exercise, verbose: bool) -> Result<()> {
- match exercise.mode {
- Mode::Test => test(exercise, verbose),
- Mode::Compile | Mode::Clippy => compile_and_run(exercise),
- }
-}
-
-// Compile and run an exercise.
-// This is strictly for non-test binaries, so output is displayed
-fn compile_and_run(exercise: &Exercise) -> Result<()> {
- let progress_bar = ProgressBar::new_spinner();
- progress_bar.set_message(format!("Running {exercise}..."));
- progress_bar.enable_steady_tick(Duration::from_millis(100));
-
+pub fn run(exercise: &Exercise) -> Result<()> {
let output = exercise.run()?;
- progress_bar.finish_and_clear();
- stdout().write_all(&output.stdout)?;
- if !output.status.success() {
- stdout().write_all(&output.stderr)?;
+ {
+ let mut stdout = stdout().lock();
+ stdout.write_all(&output.stdout)?;
+ stdout.write_all(&output.stderr)?;
+ stdout.flush()?;
+ }
+
+ if output.status.success() {
+ success!("Successfully ran {}", exercise);
+ } else {
warn!("Ran {} with errors", exercise);
- bail!("TODO");
}
- success!("Successfully ran {}", exercise);
Ok(())
}