mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-28 00:00:03 +03:00
Merge 6b6f0312a3
into 9c6f56b836
This commit is contained in:
commit
ae91b883de
|
@ -54,6 +54,8 @@ pub struct Exercise {
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
// The hint text associated with the exercise
|
// The hint text associated with the exercise
|
||||||
pub hint: String,
|
pub hint: String,
|
||||||
|
// The path of the next exercise
|
||||||
|
pub next_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// An enum to track of the state of an Exercise.
|
// An enum to track of the state of an Exercise.
|
||||||
|
@ -287,6 +289,7 @@ mod test {
|
||||||
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
||||||
mode: Mode::Compile,
|
mode: Mode::Compile,
|
||||||
hint: String::from(""),
|
hint: String::from(""),
|
||||||
|
next_path: None,
|
||||||
};
|
};
|
||||||
let compiled = exercise.compile().unwrap();
|
let compiled = exercise.compile().unwrap();
|
||||||
drop(compiled);
|
drop(compiled);
|
||||||
|
@ -305,6 +308,7 @@ mod test {
|
||||||
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
||||||
mode: *mode,
|
mode: *mode,
|
||||||
hint: String::from(""),
|
hint: String::from(""),
|
||||||
|
next_path: None,
|
||||||
};
|
};
|
||||||
let _ = exercise.compile().unwrap();
|
let _ = exercise.compile().unwrap();
|
||||||
assert!(!Path::new(&format!("{}.pdb", temp_file())).exists());
|
assert!(!Path::new(&format!("{}.pdb", temp_file())).exists());
|
||||||
|
@ -318,6 +322,7 @@ mod test {
|
||||||
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
path: PathBuf::from("tests/fixture/state/pending_exercise.rs"),
|
||||||
mode: Mode::Compile,
|
mode: Mode::Compile,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
|
next_path: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = exercise.state();
|
let state = exercise.state();
|
||||||
|
@ -359,6 +364,7 @@ mod test {
|
||||||
path: PathBuf::from("tests/fixture/state/finished_exercise.rs"),
|
path: PathBuf::from("tests/fixture/state/finished_exercise.rs"),
|
||||||
mode: Mode::Compile,
|
mode: Mode::Compile,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
|
next_path: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(exercise.state(), State::Done);
|
assert_eq!(exercise.state(), State::Done);
|
||||||
|
@ -371,6 +377,7 @@ mod test {
|
||||||
path: PathBuf::from("tests/fixture/success/testSuccess.rs"),
|
path: PathBuf::from("tests/fixture/success/testSuccess.rs"),
|
||||||
mode: Mode::Test,
|
mode: Mode::Test,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
|
next_path: None,
|
||||||
};
|
};
|
||||||
let out = exercise.compile().unwrap().run().unwrap();
|
let out = exercise.compile().unwrap().run().unwrap();
|
||||||
assert!(out.stdout.contains("THIS TEST TOO SHALL PASS"));
|
assert!(out.stdout.contains("THIS TEST TOO SHALL PASS"));
|
||||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -9,7 +9,7 @@ use notify_debouncer_mini::{new_debouncer, DebouncedEventKind};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, prelude::*};
|
use std::io::{self, prelude::*};
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::{channel, RecvTimeoutError};
|
use std::sync::mpsc::{channel, RecvTimeoutError};
|
||||||
|
@ -108,9 +108,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let toml_str = &fs::read_to_string("info.toml").unwrap();
|
let toml_str = &fs::read_to_string("info.toml").unwrap();
|
||||||
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
|
let mut exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
|
||||||
let verbose = args.nocapture;
|
let verbose = args.nocapture;
|
||||||
|
|
||||||
|
edit_exercises(&mut exercises);
|
||||||
|
|
||||||
let command = args.command.unwrap_or_else(|| {
|
let command = args.command.unwrap_or_else(|| {
|
||||||
println!("{DEFAULT_OUT}\n");
|
println!("{DEFAULT_OUT}\n");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
@ -245,6 +247,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn edit_exercises(exercises: &mut Vec<Exercise>) {
|
||||||
|
let siz = exercises.len();
|
||||||
|
for i in 0..siz {
|
||||||
|
if i == siz - 1 {
|
||||||
|
exercises[i].next_path = None;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let next_path = &exercises[i + 1].path;
|
||||||
|
let mut x = PathBuf::new();
|
||||||
|
x.push(next_path);
|
||||||
|
exercises[i].next_path = Some(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn spawn_watch_shell(
|
fn spawn_watch_shell(
|
||||||
failed_exercise_hint: &Arc<Mutex<Option<String>>>,
|
failed_exercise_hint: &Arc<Mutex<Option<String>>>,
|
||||||
should_quit: Arc<AtomicBool>,
|
should_quit: Arc<AtomicBool>,
|
||||||
|
|
|
@ -180,6 +180,13 @@ fn prompt_for_completion(
|
||||||
|
|
||||||
let no_emoji = env::var("NO_EMOJI").is_ok();
|
let no_emoji = env::var("NO_EMOJI").is_ok();
|
||||||
|
|
||||||
|
match &exercise.next_path {
|
||||||
|
Some(path) => {
|
||||||
|
println!("Next up: {:?}", path);
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
let clippy_success_msg = if no_emoji {
|
let clippy_success_msg = if no_emoji {
|
||||||
"The code is compiling, and Clippy is happy!"
|
"The code is compiling, and Clippy is happy!"
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue