From acf135620be13a602d7d3de6beebb52e362c45c9 Mon Sep 17 00:00:00 2001 From: Patrik Kaprinay Date: Sun, 14 Jan 2024 01:28:00 +0100 Subject: [PATCH 1/4] feat: added next up message with the path of next exercise Added a new property to Exercise, next_path. I populate this property, when loading the exercises. --- src/exercise.rs | 2 ++ src/main.rs | 20 ++++++++++++++++++-- src/verify.rs | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 664b362b..26995295 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -54,6 +54,8 @@ pub struct Exercise { pub mode: Mode, // The hint text associated with the exercise pub hint: String, + // The path of the next exercise + pub next_path: Option } // An enum to track of the state of an Exercise. diff --git a/src/main.rs b/src/main.rs index a06f0c56..83dbe006 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use notify_debouncer_mini::{new_debouncer, DebouncedEventKind}; use std::ffi::OsStr; use std::fs; use std::io::{self, prelude::*}; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{channel, RecvTimeoutError}; @@ -108,9 +108,11 @@ fn main() { } let toml_str = &fs::read_to_string("info.toml").unwrap(); - let exercises = toml::from_str::(toml_str).unwrap().exercises; + let mut exercises = toml::from_str::(toml_str).unwrap().exercises; let verbose = args.nocapture; + edit_exercises(&mut exercises); + let command = args.command.unwrap_or_else(|| { println!("{DEFAULT_OUT}\n"); std::process::exit(0); @@ -245,6 +247,20 @@ fn main() { } } +fn edit_exercises(exercises: &mut Vec){ + 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( failed_exercise_hint: &Arc>>, should_quit: Arc, diff --git a/src/verify.rs b/src/verify.rs index 8a2ad49f..3cfe0f05 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -171,6 +171,13 @@ fn prompt_for_completion( 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 { "The code is compiling, and Clippy is happy!" } else { From 3526f9dec55b8f7a330e60a2ca01a7faaff7c908 Mon Sep 17 00:00:00 2001 From: Patrik Kaprinay Date: Sun, 14 Jan 2024 11:40:56 +0100 Subject: [PATCH 2/4] fix: github actions fmt and test fixes --- src/exercise.rs | 6 +++++- src/main.rs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 26995295..d8b55d8f 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -55,7 +55,7 @@ pub struct Exercise { // The hint text associated with the exercise pub hint: String, // The path of the next exercise - pub next_path: Option + pub next_path: Option, } // An enum to track of the state of an Exercise. @@ -289,6 +289,7 @@ mod test { path: PathBuf::from("tests/fixture/state/pending_exercise.rs"), mode: Mode::Compile, hint: String::from(""), + next_path: None, }; let compiled = exercise.compile().unwrap(); drop(compiled); @@ -320,6 +321,7 @@ mod test { path: PathBuf::from("tests/fixture/state/pending_exercise.rs"), mode: Mode::Compile, hint: String::new(), + next_path: None, }; let state = exercise.state(); @@ -361,6 +363,7 @@ mod test { path: PathBuf::from("tests/fixture/state/finished_exercise.rs"), mode: Mode::Compile, hint: String::new(), + next_path: None, }; assert_eq!(exercise.state(), State::Done); @@ -373,6 +376,7 @@ mod test { path: PathBuf::from("tests/fixture/success/testSuccess.rs"), mode: Mode::Test, hint: String::new(), + next_path: None, }; let out = exercise.compile().unwrap().run().unwrap(); assert!(out.stdout.contains("THIS TEST TOO SHALL PASS")); diff --git a/src/main.rs b/src/main.rs index 83dbe006..e31488d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,9 +247,9 @@ fn main() { } } -fn edit_exercises(exercises: &mut Vec){ +fn edit_exercises(exercises: &mut Vec) { let siz = exercises.len(); - for i in 0.. siz { + for i in 0..siz { if i == siz - 1 { exercises[i].next_path = None; break; From c7ba0048e030a7d61058a2dc6b1683cab15668eb Mon Sep 17 00:00:00 2001 From: Patrik Kaprinay Date: Sun, 14 Jan 2024 11:46:22 +0100 Subject: [PATCH 3/4] fix: fixed windows only test issue --- src/exercise.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index d8b55d8f..4c3994c5 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -168,7 +168,7 @@ path = "{}.rs""#, .output() } } - .expect("Failed to run 'compile' command."); + .expect("Failed to run 'compile' command."); if cmd.status.success() { Ok(CompiledExercise { @@ -308,6 +308,7 @@ mod test { path: PathBuf::from("tests/fixture/state/pending_exercise.rs"), mode: *mode, hint: String::from(""), + next_path: None, }; let _ = exercise.compile().unwrap(); assert!(!Path::new(&format!("{}.pdb", temp_file())).exists()); From 6b6f0312a353d166a8bae84878a8cf30f98a2061 Mon Sep 17 00:00:00 2001 From: Patrik Kaprinay Date: Sun, 14 Jan 2024 11:49:38 +0100 Subject: [PATCH 4/4] fix: fmt issue --- src/exercise.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index 4c3994c5..aea9a715 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -168,7 +168,7 @@ path = "{}.rs""#, .output() } } - .expect("Failed to run 'compile' command."); + .expect("Failed to run 'compile' command."); if cmd.status.success() { Ok(CompiledExercise {