diff --git a/justfile b/justfile index 5df6d95e..a36b2204 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,8 @@ -watch +args='test': +watch +args='ltest': cargo watch --clear --exec '{{ args }}' +clippy: (watch 'lclippy --all-targets -- --deny warnings') + ci: lint cargo test --workspace diff --git a/tests/create.rs b/tests/create.rs index 4b12799d..efdeb843 100644 --- a/tests/create.rs +++ b/tests/create.rs @@ -171,38 +171,41 @@ fn file_in_subdirectory() { .success(); } -// disable test on macos, since it does not allow non-unicode filenames -#[cfg(not(target_os = "macos"))] #[test] fn non_unicode_path_error() { use std::path::PathBuf; + // macos does not allow non-unicode filenames + if cfg!(target_os = "macos") { + return; + } + let dir = TempDir::new().unwrap(); - let path: PathBuf; + let invalid: PathBuf; #[cfg(unix)] { use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; - path = OsStr::from_bytes(&[0x80]).into(); + invalid = OsStr::from_bytes(&[0x80]).into(); }; #[cfg(windows)] { use std::{ffi::OsString, os::windows::ffi::OsStringExt}; - path = OsString::from_wide(&[0xd800]).into(); + invalid = OsString::from_wide(&[0xd800]).into(); }; - dir.child(path).touch().unwrap(); + dir.child(invalid).touch().unwrap(); Command::cargo_bin("filepack") .unwrap() .args(["create", "."]) .current_dir(&dir) .assert() - .stderr(format!("error: path not valid unicode: `.{SEPARATOR}�`\n")) + .stderr(path("error: path not valid unicode: `./�`\n")) .failure(); } @@ -268,13 +271,16 @@ fn only_leaf_empty_directory_is_reported() { .args(["create", "."]) .current_dir(&dir) .assert() - .stderr(format!("error: empty directory `foo{SEPARATOR}bar`\n")) + .stderr(path("error: empty directory `foo/bar`\n")) .failure(); } -#[cfg(not(windows))] #[test] fn backslash_error() { + if cfg!(windows) { + return; + } + let dir = TempDir::new().unwrap(); dir.child("\\").touch().unwrap(); @@ -293,9 +299,12 @@ error: invalid path `\\` .failure(); } -#[cfg(all(not(windows), not(target_os = "macos")))] #[test] fn deny_case_insensitive_filesystem_path_conflict() { + if cfg!(windows) || cfg!(target_os = "macos") { + return; + } + let dir = TempDir::new().unwrap(); dir.child("foo").touch().unwrap(); @@ -317,9 +326,12 @@ error: 1 lint error .failure(); } -#[cfg(not(windows))] #[test] fn deny_lint() { + if cfg!(windows) { + return; + } + let dir = TempDir::new().unwrap(); dir.child("aux").touch().unwrap(); @@ -339,9 +351,12 @@ error: 1 lint error .failure(); } -#[cfg(not(windows))] #[test] fn allow_lint() { + if cfg!(windows) { + return; + } + let dir = TempDir::new().unwrap(); dir.child("aux").touch().unwrap(); @@ -617,9 +632,7 @@ fn metadata_already_exists() { .args(["create", "foo", "--metadata", "metadata.yaml"]) .current_dir(&dir) .assert() - .stderr(format!( - "error: metadata `foo{SEPARATOR}metadata.json` already exists\n" - )) + .stderr(path("error: metadata `foo/metadata.json` already exists\n")) .failure(); Command::cargo_bin("filepack") diff --git a/tests/lib.rs b/tests/lib.rs index 05b391c3..f6b35dda 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -10,7 +10,9 @@ use { std::{collections::BTreeMap, fs, path::Path, str}, }; -const SEPARATOR: char = if cfg!(windows) { '\\' } else { '/' }; +fn path(message: &str) -> String { + message.replace('/', std::path::MAIN_SEPARATOR_STR) +} fn is_match(pattern: S) -> RegexPredicate where diff --git a/tests/verify.rs b/tests/verify.rs index b08cb7b6..9cd0295b 100644 --- a/tests/verify.rs +++ b/tests/verify.rs @@ -200,7 +200,7 @@ fn only_leaf_empty_directory_is_reported() { .args(["verify", "."]) .current_dir(&dir) .assert() - .stderr(format!("error: empty directory `foo{SEPARATOR}bar`\n")) + .stderr(path("error: empty directory `foo/bar`\n")) .failure(); } @@ -302,31 +302,34 @@ error: 2 mismatched files .failure(); } -// disable test on macos, since it does not allow non-unicode filenames -#[cfg(not(target_os = "macos"))] #[test] fn non_unicode_path_error() { use std::path::PathBuf; + // macos does not allow non-unicode filenames + if cfg!(target_os = "macos") { + return; + } + let dir = TempDir::new().unwrap(); - let path: PathBuf; + let invalid: PathBuf; #[cfg(unix)] { use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; - path = OsStr::from_bytes(&[0x80]).into(); + invalid = OsStr::from_bytes(&[0x80]).into(); }; #[cfg(windows)] { use std::{ffi::OsString, os::windows::ffi::OsStringExt}; - path = OsString::from_wide(&[0xd800]).into(); + invalid = OsString::from_wide(&[0xd800]).into(); }; - dir.child(path).touch().unwrap(); + dir.child(invalid).touch().unwrap(); dir .child("filepack.json") @@ -338,7 +341,7 @@ fn non_unicode_path_error() { .args(["verify", "."]) .current_dir(&dir) .assert() - .stderr(format!("error: path not valid unicode: `.{SEPARATOR}�`\n")) + .stderr(path("error: path not valid unicode: `./�`\n")) .failure(); }