forked from shramee/starklings-cairo1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.rs
executable file
·79 lines (69 loc) · 2.39 KB
/
run.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use std::process::Command;
use crate::exercise::{Exercise, Mode};
use indicatif::ProgressBar;
// 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) -> Result<(), ()> {
match exercise.mode {
Mode::Compile => run_cairo(exercise)?,
Mode::Test => test_cairo(exercise)?,
}
Ok(())
}
// Resets the exercise by stashing the changes.
pub fn reset(exercise: &Exercise) -> Result<(), ()> {
let command = Command::new("git")
.args(["stash", "--"])
.arg(&exercise.path)
.spawn();
match command {
Ok(_) => Ok(()),
Err(_) => Err(()),
}
}
// Invoke the rust compiler on the path of the given exercise
// and run the ensuing binary.
// This is strictly for non-test binaries, so output is displayed
fn run_cairo(exercise: &Exercise) -> Result<(), ()> {
let progress_bar = ProgressBar::new_spinner();
progress_bar.set_message(format!("Running {exercise}..."));
progress_bar.enable_steady_tick(100);
let output = exercise.run_cairo();
if let Some(error) = output.as_ref().err(){
progress_bar.finish_and_clear();
println!("Err");
println!("{}", error.to_string());
println!("Normal");
println!("{}", error.to_string());
Err(())
} else {
let message = output.unwrap();
println!("{}", message);
success!("Successfully ran {}", exercise);
Ok(())
}
}
// Invoke the rust compiler on the path of the given exercise
// and run the ensuing binary.
// This is strictly for non-test binaries, so output is displayed
fn test_cairo(exercise: &Exercise) -> Result<(), ()> {
let progress_bar = ProgressBar::new_spinner();
progress_bar.set_message(format!("Running {exercise}..."));
progress_bar.enable_steady_tick(100);
let output = exercise.test_cairo();
if let Some(error) = output.as_ref().err(){
progress_bar.finish_and_clear();
println!("Err");
println!("{}", error.to_string());
println!("Normal");
println!("{}", error.to_string());
Err(())
} else {
let message = output.unwrap();
println!("{}", message);
success!("Successfully ran {}", exercise);
Ok(())
}
}