From 3f114cc0699e2600e92acb466ae2dd90e0626715 Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Wed, 13 Mar 2019 13:50:54 -0700 Subject: [PATCH 1/5] Start verification at most recently modified file --- src/main.rs | 6 +++--- src/verify.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0e2c975..19c0ae0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ fn main() { } if matches.subcommand_matches("verify").is_some() { - match verify() { + match verify(None) { Ok(_) => {} Err(_) => std::process::exit(1), } @@ -81,14 +81,14 @@ fn watch() -> notify::Result<()> { let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?; watcher.watch("./exercises", RecursiveMode::Recursive)?; - let _ignored = verify(); + let _ignored = verify(None); loop { match rx.recv() { Ok(event) => match event { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) { - let _ignored = verify(); + let _ignored = verify(Some(b.as_path().to_str().unwrap())); } } _ => {} diff --git a/src/verify.rs b/src/verify.rs index ab08a27..877a2aa 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -5,10 +5,22 @@ use std::fs; use std::process::Command; use toml::Value; -pub fn verify() -> Result<(), ()> { +pub fn verify(start_at: Option<&str>) -> Result<(), ()> { let toml: Value = fs::read_to_string("info.toml").unwrap().parse().unwrap(); let tomlvec: &Vec = toml.get("exercises").unwrap().as_array().unwrap(); + let mut hit_start_at = false; + for i in tomlvec { + let path = i.get("path").unwrap().as_str().unwrap(); + + if let Some(start_at) = start_at { + if start_at.ends_with(path) { + hit_start_at = true; + } else if !hit_start_at { + continue; + } + } + match i.get("mode").unwrap().as_str().unwrap() { "test" => test(i.get("path").unwrap().as_str().unwrap())?, "compile" => compile_only(i.get("path").unwrap().as_str().unwrap())?, From 4d7ce6e5718ccea4a879e40c9946a1dcd3195653 Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Wed, 13 Mar 2019 13:53:24 -0700 Subject: [PATCH 2/5] deduplicate --- src/verify.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/verify.rs b/src/verify.rs index 877a2aa..5aa2f5c 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -22,8 +22,8 @@ pub fn verify(start_at: Option<&str>) -> Result<(), ()> { } match i.get("mode").unwrap().as_str().unwrap() { - "test" => test(i.get("path").unwrap().as_str().unwrap())?, - "compile" => compile_only(i.get("path").unwrap().as_str().unwrap())?, + "test" => test(path)?, + "compile" => compile_only(path)?, _ => (), } } From 6cd42bb8210b0e687942e388d66b07f286fe6bb6 Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Wed, 13 Mar 2019 14:08:28 -0700 Subject: [PATCH 3/5] Add clear break between verify executions --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 19c0ae0..1b62e28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,10 +84,12 @@ fn watch() -> notify::Result<()> { let _ignored = verify(None); loop { - match rx.recv() { + match rx.recv() { Ok(event) => match event { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) { + println!("----------**********----------"); + println!(); let _ignored = verify(Some(b.as_path().to_str().unwrap())); } } From a6a8b61b12173291e59dbf854b35a0601f04a6e9 Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Fri, 15 Mar 2019 12:47:06 -0700 Subject: [PATCH 4/5] Change to \n --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1b62e28..9451f11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,8 +88,7 @@ fn watch() -> notify::Result<()> { Ok(event) => match event { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) { - println!("----------**********----------"); - println!(); + println!("----------**********----------\n"); let _ignored = verify(Some(b.as_path().to_str().unwrap())); } } From 3b5dfac44e881c10b0ee47c320e5e7825aed4ddb Mon Sep 17 00:00:00 2001 From: Andrew Bagshaw Date: Fri, 15 Mar 2019 16:01:45 -0700 Subject: [PATCH 5/5] Remove unnessecary whitespace --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9451f11..3418685 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,7 +84,7 @@ fn watch() -> notify::Result<()> { let _ignored = verify(None); loop { - match rx.recv() { + match rx.recv() { Ok(event) => match event { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) {