Skip to content

Commit 88fd1df

Browse files
committed
run_make_support: move assert_recursive_eq into assertion_helpers
1 parent 56cbfa8 commit 88fd1df

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

Lines changed: 27 additions & 1 deletion
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

Lines changed: 1 addition & 26 deletions
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,
@@ -136,28 +136,3 @@ pub fn set_host_rpath(cmd: &mut Command) {
136136
std::env::join_paths(paths.iter()).unwrap()
137137
});
138138
}
139-
140-
/// Assert that all files in `dir1` exist and have the same content in `dir2`
141-
pub fn assert_recursive_eq(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
142-
let dir2 = dir2.as_ref();
143-
read_dir(dir1, |entry_path| {
144-
let entry_name = entry_path.file_name().unwrap();
145-
if entry_path.is_dir() {
146-
assert_recursive_eq(&entry_path, &dir2.join(entry_name));
147-
} else {
148-
let path2 = dir2.join(entry_name);
149-
let file1 = fs_wrapper::read(&entry_path);
150-
let file2 = fs_wrapper::read(&path2);
151-
152-
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
153-
// Why not using String? Because there might be minified files or even potentially
154-
// binary ones, so that would display useless output.
155-
assert!(
156-
file1 == file2,
157-
"`{}` and `{}` have different content",
158-
entry_path.display(),
159-
path2.display(),
160-
);
161-
}
162-
});
163-
}

0 commit comments

Comments
 (0)