[[exercises]] name = "variables1" path = "exercises/variables/variables1.rs" mode = "compile" hint = """ Hint: The declaration on line 5 is missing a keyword that is needed in Rust to create a new variable binding."""
verify(exercises): for exercise in exercises: let is_done = match exercise.mode: Mode::Test => compile_and_test_interactively(exercise), Mode::Compile => compile_only(exercise),
compile_and_test(exercise, skip_prompt): let compile_output = exercise.compile(); if compile_output.status.success(): let run_cmd = exercise.run(); if run_cmd.success(): println!(green("✅✓ Successfully tested" + exercise)); skip_prompt || prompt_for_completion(exercise) else: println!(red("⚠️! Compiling of " + exercise + " failed! Please try again. Here's the output:") + run_cmd.stdout); else: println!(red("⚠️! Compiling of " + exercise + " failed! Please try again. Here's the output:") + compile_output.stderr);
compile_only(exercise): let compilecmd = exercise.compile(); if compilecmd.status.success(): println!("✅✓ Successfully compiled " + filename); prompt_for_completion(exercise) else: println!("⚠️! Compilation of " + filename + " failed! Compiler error message:\n");
prompt_for_completion(exercise): let context = match exercise.state(): State::Done => returntrue, State::Pending(context) => context,
let success_msg = match exercise.mode: Mode::Compile => "The code is compiling!", Mode::Test => "The code is compiling, and the tests pass!",
println!("or jump into the next one by removing the " + style("`I AM NOT DONE`").bold() +" comment:");
for context_line in context: let formatted_line = if context_line.important: style(context_line.line).bold() else context_line.line show_error(formatted_line);
watch
2 秒执行一行 verify(),有错误就报错,没有就再次执行 verify()。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
watch(): let (tx, rx) = channel(); let watch = Watcher::new(tx, Duration::from_secs(2))?; watcher.watch("./exercises", RecursiveMode::Recursive)?;
verify();
loop { match rx.recv() { OK { verify(); }, Err(e): println!(watch error: " + e); } }