add the whole curriculum
This commit is contained in:
parent
f7846af7ac
commit
18a1447a65
88
src/main.rs
88
src/main.rs
|
@ -7,6 +7,7 @@ use clap::{App, SubCommand};
|
||||||
use indicatif::{ProgressBar};
|
use indicatif::{ProgressBar};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use std::fs::remove_file;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = App::new("r2")
|
let matches = App::new("r2")
|
||||||
|
@ -17,15 +18,64 @@ fn main() {
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if let Some(_) = matches.subcommand_matches("verify") {
|
if let Some(_) = matches.subcommand_matches("verify") {
|
||||||
execute("exercises/ex1.rs");
|
compile_only("exercises/ex1.rs");
|
||||||
execute("exercises/ex2.rs");
|
compile_only("exercises/ex2.rs");
|
||||||
execute("exercises/ex3.rs");
|
compile_only("exercises/ex3.rs");
|
||||||
execute("exercises/ex4.rs");
|
compile_only("exercises/ex4.rs");
|
||||||
execute("exercises/ex5.rs");
|
compile_only("exercises/ex5.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/variables/variables1.rs");
|
||||||
|
compile_only("exercises/variables/variables2.rs");
|
||||||
|
compile_only("exercises/variables/variables3.rs");
|
||||||
|
compile_only("exercises/variables/variables4.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/functions/functions1.rs");
|
||||||
|
compile_only("exercises/functions/functions2.rs");
|
||||||
|
compile_only("exercises/functions/functions3.rs");
|
||||||
|
compile_only("exercises/functions/functions4.rs");
|
||||||
|
compile_only("exercises/functions/functions5.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/primitive_types/primitive_types1.rs");
|
||||||
|
compile_only("exercises/primitive_types/primitive_types2.rs");
|
||||||
|
compile_only("exercises/primitive_types/primitive_types3.rs");
|
||||||
|
compile_only("exercises/primitive_types/primitive_types4.rs");
|
||||||
|
compile_only("exercises/primitive_types/primitive_types5.rs");
|
||||||
|
compile_only("exercises/primitive_types/primitive_types6.rs");
|
||||||
|
|
||||||
|
test("exercises/tests/tests1.rs");
|
||||||
|
test("exercises/tests/tests2.rs");
|
||||||
|
test("exercises/tests/tests3.rs");
|
||||||
|
test("exercises/tests/tests4.rs");
|
||||||
|
|
||||||
|
test("exercises/if/if1.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/strings/strings1.rs");
|
||||||
|
compile_only("exercises/strings/strings2.rs");
|
||||||
|
compile_only("exercises/strings/strings3.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/move_semantics/move_semantics1.rs");
|
||||||
|
compile_only("exercises/move_semantics/move_semantics2.rs");
|
||||||
|
compile_only("exercises/move_semantics/move_semantics3.rs");
|
||||||
|
compile_only("exercises/move_semantics/move_semantics4.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/modules/modules1.rs");
|
||||||
|
compile_only("exercises/modules/modules2.rs");
|
||||||
|
|
||||||
|
compile_only("exercises/macros/macros1.rs");
|
||||||
|
compile_only("exercises/macros/macros2.rs");
|
||||||
|
compile_only("exercises/macros/macros3.rs");
|
||||||
|
compile_only("exercises/macros/macros4.rs");
|
||||||
|
|
||||||
|
test("exercises/error_handling/errors1.rs");
|
||||||
|
test("exercises/error_handling/errors2.rs");
|
||||||
|
test("exercises/error_handling/errors3.rs");
|
||||||
|
test("exercises/error_handling/errorsn.rs");
|
||||||
|
compile_only("exercises/error_handling/option1.rs");
|
||||||
|
test("exercises/error_handling/result1.rs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(filename: &str) {
|
fn compile_only(filename: &str) {
|
||||||
let bar = ProgressBar::new_spinner();
|
let bar = ProgressBar::new_spinner();
|
||||||
bar.set_message(format!("Compiling {}...", filename).as_str());
|
bar.set_message(format!("Compiling {}...", filename).as_str());
|
||||||
bar.enable_steady_tick(100);
|
bar.enable_steady_tick(100);
|
||||||
|
@ -36,9 +86,35 @@ fn execute(filename: &str) {
|
||||||
bar.finish_and_clear();
|
bar.finish_and_clear();
|
||||||
if compilecmd.status.success() {
|
if compilecmd.status.success() {
|
||||||
println!("{} Successfully compiled {}!", Emoji("✅", "✓"), style(filename).italic());
|
println!("{} Successfully compiled {}!", Emoji("✅", "✓"), style(filename).italic());
|
||||||
|
clean().unwrap();
|
||||||
} else {
|
} else {
|
||||||
println!("{} Compilation of {} failed! Compiler error message:\n", Emoji("⚠️ ", "!"), style(filename).italic());
|
println!("{} Compilation of {} failed! Compiler error message:\n", Emoji("⚠️ ", "!"), style(filename).italic());
|
||||||
println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
|
println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
|
||||||
|
clean().unwrap();
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test(filename: &str) {
|
||||||
|
let bar = ProgressBar::new_spinner();
|
||||||
|
bar.set_message(format!("Testing {}...", filename).as_str());
|
||||||
|
bar.enable_steady_tick(100);
|
||||||
|
let testcmd = Command::new("rustc")
|
||||||
|
.args(&["--test", filename, "-o", "temp"])
|
||||||
|
.output()
|
||||||
|
.expect("fail");
|
||||||
|
bar.finish_and_clear();
|
||||||
|
if testcmd.status.success() {
|
||||||
|
println!("{} Successfully tested {}!", Emoji("✅", "✓"), style(filename).italic());
|
||||||
|
clean().unwrap();
|
||||||
|
} else {
|
||||||
|
println!("{} Testing of {} failed! Please try again.", Emoji("⚠️ ", "!"), style(filename).italic());
|
||||||
|
clean().unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clean() -> Result<(), std::io::Error> {
|
||||||
|
remove_file("temp")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue