2024-04-04 23:44:43 +01:00
|
|
|
use anyhow::{bail, Result};
|
2024-03-31 19:08:23 +01:00
|
|
|
use std::io::{stdout, Write};
|
2022-08-17 15:31:53 +01:00
|
|
|
|
2024-04-04 20:06:11 +01:00
|
|
|
use crate::exercise::Exercise;
|
2019-01-09 19:33:43 +00:00
|
|
|
|
2020-06-04 15:31:17 +01:00
|
|
|
// 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)
|
2024-04-04 20:06:11 +01:00
|
|
|
pub fn run(exercise: &Exercise) -> Result<()> {
|
2024-03-31 15:55:33 +01:00
|
|
|
let output = exercise.run()?;
|
2019-03-06 20:47:00 +00:00
|
|
|
|
2024-04-04 20:06:11 +01:00
|
|
|
{
|
|
|
|
let mut stdout = stdout().lock();
|
|
|
|
stdout.write_all(&output.stdout)?;
|
|
|
|
stdout.write_all(&output.stderr)?;
|
|
|
|
stdout.flush()?;
|
|
|
|
}
|
|
|
|
|
2024-04-04 23:44:43 +01:00
|
|
|
if !output.status.success() {
|
|
|
|
bail!("Ran {exercise} with errors");
|
2019-01-09 19:33:43 +00:00
|
|
|
}
|
2024-03-31 15:55:33 +01:00
|
|
|
|
2024-04-04 23:49:22 +01:00
|
|
|
// TODO: Color
|
|
|
|
println!("Successfully ran {exercise}");
|
2024-04-04 23:44:43 +01:00
|
|
|
|
2024-03-31 15:55:33 +01:00
|
|
|
Ok(())
|
2019-01-09 19:33:43 +00:00
|
|
|
}
|