From a27808a6b5c21ab998ad3862295630d3a1d8d24a Mon Sep 17 00:00:00 2001 From: Haruaki Tamada Date: Thu, 26 Dec 2024 10:59:26 +0900 Subject: [PATCH 1/3] fix panicked for specifying dir in args use absolute path for given path with fs::canonicalize. --- src/dirs.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dirs.rs b/src/dirs.rs index 4d8f773..e0b0022 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::{fs, path::{Path, PathBuf}}; use crate::cli::{Result, SiblingError}; @@ -20,7 +20,8 @@ impl Dirs { } } else if current_dir.exists() { if current_dir.is_dir() { - build_dirs(current_dir.clone().parent(), current_dir) + let current = fs::canonicalize(¤t_dir).unwrap(); + build_dirs(current.clone().parent(), current) } else { Err(SiblingError::NotDir(current_dir)) } @@ -48,7 +49,7 @@ fn build_dirs(parent: Option<&Path>, current: PathBuf) -> Result { None => return Err(SiblingError::NoParent(current)), }; let mut errs = vec![]; - let dirs = collect_dirs(parent, &mut errs); + let dirs = collect_dirs(&parent, &mut errs); if !errs.is_empty() { Err(SiblingError::Array(errs)) } else { From e733ca2fda0dba876a6947ba617fc6e6f00acfe0 Mon Sep 17 00:00:00 2001 From: Haruaki Tamada Date: Thu, 26 Dec 2024 10:59:39 +0900 Subject: [PATCH 2/3] add launch configuration for Rust debugging in VSCode --- .vscode/launch.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c8b38f4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Rust Debug Launch", + "program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}", + "args": ["docs"], + "cwd": "${workspaceRoot}", + "sourceLanguages": ["rust"] + } + ] +} \ No newline at end of file From 58fb9a14509996c536022a148a16debc0d853c0d Mon Sep 17 00:00:00 2001 From: Haruaki Tamada Date: Thu, 26 Dec 2024 12:23:12 +0900 Subject: [PATCH 3/3] refactor tests: update assertions to use ends_with for path validation --- src/nexter.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/nexter.rs b/src/nexter.rs index ebd0868..46e6668 100644 --- a/src/nexter.rs +++ b/src/nexter.rs @@ -98,7 +98,7 @@ mod tests { let mut dirs = Dirs::new("testdata/c".into()).unwrap(); let nexter = build_nexter(NexterType::First); match nexter.next(&mut dirs, 1) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/a")), + Some(p) => assert!(p.ends_with("testdata/a")), None => panic!("unexpected None"), } } @@ -108,7 +108,7 @@ mod tests { let mut dirs = Dirs::new("testdata/k".into()).unwrap(); let nexter = build_nexter(NexterType::Last); match nexter.next(&mut dirs, 1) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/z")), + Some(p) => assert!(p.ends_with("testdata/z")), None => panic!("unexpected None"), } } @@ -118,15 +118,15 @@ mod tests { let mut dirs = Dirs::new("testdata/c".into()).unwrap(); let nexter = build_nexter(NexterType::Next); match nexter.next(&mut dirs, 1) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/d")), + Some(p) => assert!(p.ends_with("testdata/d")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 2) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/e")), + Some(p) => assert!(p.ends_with("testdata/e")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 26) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/z")), + Some(p) => assert!(p.ends_with("testdata/z")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 1) { @@ -140,19 +140,19 @@ mod tests { let mut dirs = Dirs::new("testdata/k".into()).unwrap(); let nexter = build_nexter(NexterType::Previous); match nexter.next(&mut dirs, 1) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/j")), + Some(p) => assert!(p.ends_with("testdata/j")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 1) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/j")), + Some(p) => assert!(p.ends_with("testdata/j")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 4) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/g")), + Some(p) => assert!(p.ends_with("testdata/g")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 26) { - Some(p) => assert_eq!(p, PathBuf::from("testdata/a")), + Some(p) => assert!(p.ends_with("testdata/a")), None => panic!("unexpected None"), } match nexter.next(&mut dirs, 1) {