Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
43 changes: 28 additions & 15 deletions tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(pattern: S) -> RegexPredicate
where
Expand Down
19 changes: 11 additions & 8 deletions tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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")
Expand All @@ -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();
}

Expand Down