Skip to content

Commit 04a9056

Browse files
committed
run_make_support: move assert_recursive_eq into assertion_helpers
1 parent ea8f0e4 commit 04a9056

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

src/tools/run-make-support/src/assertion_helpers.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Collection of assertions and assertion-related helpers.
22
3-
use std::path::{Path, PathBuf};
43
use std::panic;
4+
use std::path::{Path, PathBuf};
55

6+
use crate::fs_helpers;
67
use crate::fs_wrapper;
78
use crate::path_helpers::cwd;
89

@@ -140,3 +141,28 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
140141
panic!("needle was unexpectedly found in haystack");
141142
}
142143
}
144+
145+
/// Assert that all files in `dir1` exist and have the same content in `dir2`
146+
pub fn assert_recursive_eq(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
147+
let dir2 = dir2.as_ref();
148+
fs_helpers::read_dir(dir1, |entry_path| {
149+
let entry_name = entry_path.file_name().unwrap();
150+
if entry_path.is_dir() {
151+
assert_recursive_eq(&entry_path, &dir2.join(entry_name));
152+
} else {
153+
let path2 = dir2.join(entry_name);
154+
let file1 = fs_wrapper::read(&entry_path);
155+
let file2 = fs_wrapper::read(&path2);
156+
157+
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
158+
// Why not using String? Because there might be minified files or even potentially
159+
// binary ones, so that would display useless output.
160+
assert!(
161+
file1 == file2,
162+
"`{}` and `{}` have different content",
163+
entry_path.display(),
164+
path2.display(),
165+
);
166+
}
167+
});
168+
}

src/tools/run-make-support/src/lib.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use fs_helpers::{copy_dir_all, create_symlink, read_dir};
7878
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
7979

8080
pub use assertion_helpers::{
81-
assert_contains, assert_equals, assert_not_contains,
81+
assert_contains, assert_equals, assert_not_contains, assert_recursive_eq,
8282
count_regex_matches_in_files_with_extension, filename_not_in_denylist, has_extension,
8383
has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains,
8484
shallow_find_files,
@@ -116,28 +116,3 @@ pub fn set_host_rpath(cmd: &mut Command) {
116116
std::env::join_paths(paths.iter()).unwrap()
117117
});
118118
}
119-
120-
/// Assert that all files in `dir1` exist and have the same content in `dir2`
121-
pub fn assert_recursive_eq(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
122-
let dir2 = dir2.as_ref();
123-
read_dir(dir1, |entry_path| {
124-
let entry_name = entry_path.file_name().unwrap();
125-
if entry_path.is_dir() {
126-
assert_recursive_eq(&entry_path, &dir2.join(entry_name));
127-
} else {
128-
let path2 = dir2.join(entry_name);
129-
let file1 = fs_wrapper::read(&entry_path);
130-
let file2 = fs_wrapper::read(&path2);
131-
132-
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
133-
// Why not using String? Because there might be minified files or even potentially
134-
// binary ones, so that would display useless output.
135-
assert!(
136-
file1 == file2,
137-
"`{}` and `{}` have different content",
138-
entry_path.display(),
139-
path2.display(),
140-
);
141-
}
142-
});
143-
}

0 commit comments

Comments
 (0)