Skip to content

Commit 85cd116

Browse files
committed
fix unix tests
1 parent acaae8a commit 85cd116

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

crates/core/src/commands/backup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub(crate) fn backup<P: ProgressBars, S: IndexedIds>(
223223

224224
let as_path = match &opts.as_path {
225225
Some(p) => Some(p),
226-
None if backup_path.len() == 1 => Some(&backup_path[0]),
226+
None if !backup_stdin && backup_path.len() == 1 => Some(&backup_path[0]),
227227
None => None,
228228
}
229229
.map(|p| UnixPath::new(p.as_os_str().as_encoded_bytes()).normalize());

crates/core/src/util.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use globset::GlobMatcher;
2+
use serde::{Serialize, Serializer};
3+
use typed_path::{UnixPath, UnixPathBuf};
24

35
/// Extend `globset::GlobMatcher` to allow mathing on unix paths (on every platform)
46
pub trait GlobMatcherExt {
@@ -27,3 +29,16 @@ impl GlobMatcherExt for GlobMatcher {
2729
self.is_match(path)
2830
}
2931
}
32+
33+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
34+
#[serde(transparent)]
35+
/// Like `UnixPathBuf` , but implements `Serialize`
36+
pub struct SerializablePath(#[serde(serialize_with = "serialize_unix_path")] pub UnixPathBuf);
37+
38+
fn serialize_unix_path<S>(path: &UnixPath, serializer: S) -> Result<S::Ok, S::Error>
39+
where
40+
S: Serializer,
41+
{
42+
let s = format!("{}", path.display());
43+
serializer.serialize_str(&s)
44+
}

crates/core/tests/integration/find.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use std::{path::PathBuf, str::FromStr};
55

66
use anyhow::Result;
77
use globset::Glob;
8-
use insta::assert_debug_snapshot;
98
use rstest::rstest;
109

1110
use rustic_core::{
1211
repofile::{Node, SnapshotFile},
13-
util::GlobMatcherExt,
12+
util::{GlobMatcherExt, SerializablePath},
1413
BackupOptions, FindMatches, FindNode,
1514
};
1615
use typed_path::UnixPath;
@@ -37,9 +36,10 @@ fn test_find(tar_gz_testdata: Result<TestSource>, set_up_repo: Result<RepoOpen>)
3736
assert_with_win("find-nodes-not-found", not_found);
3837
// test non-existing match
3938
let glob = Glob::new("not_existing")?.compile_matcher();
40-
let not_found =
39+
let FindMatches { paths, matches, .. } =
4140
repo.find_matching_nodes(vec![snapshot.tree], &|path, _| glob.is_unix_match(path))?;
42-
assert_debug_snapshot!("find-matching-nodes-not-found", not_found);
41+
assert!(paths.is_empty());
42+
assert_eq!(matches, [[]]);
4343

4444
// test existing path
4545
let FindNode { matches, .. } =
@@ -52,14 +52,16 @@ fn test_find(tar_gz_testdata: Result<TestSource>, set_up_repo: Result<RepoOpen>)
5252
};
5353
let FindMatches { paths, matches, .. } =
5454
repo.find_matching_nodes(vec![snapshot.tree], &match_func)?;
55-
assert_debug_snapshot!("find-matching-existing", (paths, matches));
55+
let paths: Vec<_> = paths.into_iter().map(SerializablePath).collect();
56+
assert_with_win("find-matching-existing", (paths, matches));
5657
// test existing match
5758
let glob = Glob::new("testfile*")?.compile_matcher();
5859
let match_func = |path: &UnixPath, _: &Node| {
5960
glob.is_unix_match(path) || path.file_name().is_some_and(|f| glob.is_unix_match(f))
6061
};
6162
let FindMatches { paths, matches, .. } =
6263
repo.find_matching_nodes(vec![snapshot.tree], &match_func)?;
63-
assert_debug_snapshot!("find-matching-wildcard-existing", (paths, matches));
64+
let paths: Vec<_> = paths.into_iter().map(SerializablePath).collect();
65+
assert_with_win("find-matching-wildcard-existing", (paths, matches));
6466
Ok(())
6567
}

crates/core/tests/integration/ls.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ use std::collections::BTreeMap;
22
use std::{path::PathBuf, str::FromStr};
33

44
use anyhow::Result;
5-
use insta::{assert_debug_snapshot, Settings};
5+
use insta::Settings;
6+
use itertools::Itertools;
67
use rstest::rstest;
78

89
use rustic_core::{
910
repofile::{Metadata, Node, SnapshotFile},
11+
util::SerializablePath,
1012
BackupOptions, LsOptions, RusticResult,
1113
};
1214

13-
use super::{insta_node_redaction, set_up_repo, tar_gz_testdata, RepoOpen, TestSource};
15+
use super::{
16+
assert_with_win, insta_node_redaction, set_up_repo, tar_gz_testdata, RepoOpen, TestSource,
17+
};
1418

1519
#[rstest]
1620
fn test_ls(
@@ -40,10 +44,11 @@ fn test_ls(
4044

4145
let entries: BTreeMap<_, _> = repo
4246
.ls(&node, &LsOptions::default())?
47+
.map_ok(|(path, node)| (SerializablePath(path), node))
4348
.collect::<RusticResult<_>>()?;
4449

4550
insta_node_redaction.bind(|| {
46-
assert_debug_snapshot!("ls", &entries);
51+
assert_with_win("ls", &entries);
4752
});
4853

4954
Ok(())

crates/core/tests/integration/vfs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn test_vfs(
3535
let vfs = Vfs::from_dir_node(&node);
3636

3737
// test reading a directory using vfs
38-
let entries = vfs.dir_entries_from_path(&repo, UnixPath::new("test/0/tests/testfile"))?;
38+
let entries = vfs.dir_entries_from_path(&repo, UnixPath::new("test/0/tests"))?;
3939
insta_node_redaction.bind(|| {
4040
assert_with_win("vfs", &entries);
4141
});

0 commit comments

Comments
 (0)