diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 96f6296b304c..3fdcc94a034f 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -1,8 +1,9 @@ //! Collection of assertions and assertion-related helpers. -use std::path::{Path, PathBuf}; use std::panic; +use std::path::{Path, PathBuf}; +use crate::fs_helpers; use crate::fs_wrapper; use crate::path_helpers::cwd; @@ -140,3 +141,28 @@ pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) panic!("needle was unexpectedly found in haystack"); } } + +/// Assert that all files in `dir1` exist and have the same content in `dir2` +pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { + let dir2 = dir2.as_ref(); + fs_helpers::read_dir(dir1, |entry_path| { + let entry_name = entry_path.file_name().unwrap(); + if entry_path.is_dir() { + assert_recursive_eq(&entry_path, &dir2.join(entry_name)); + } else { + let path2 = dir2.join(entry_name); + let file1 = fs_wrapper::read(&entry_path); + let file2 = fs_wrapper::read(&path2); + + // We don't use `assert_eq!` because they are `Vec`, so not great for display. + // Why not using String? Because there might be minified files or even potentially + // binary ones, so that would display useless output. + assert!( + file1 == file2, + "`{}` and `{}` have different content", + entry_path.display(), + path2.display(), + ); + } + }); +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 1a2a648c47ad..658b6cc3559b 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -78,7 +78,7 @@ pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; pub use scoped_run::{run_in_tmpdir, test_while_readonly}; pub use assertion_helpers::{ - assert_contains, assert_equals, assert_not_contains, + assert_contains, assert_equals, assert_not_contains, assert_recursive_eq, count_regex_matches_in_files_with_extension, filename_not_in_denylist, has_extension, has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, shallow_find_files, @@ -136,28 +136,3 @@ pub fn set_host_rpath(cmd: &mut Command) { std::env::join_paths(paths.iter()).unwrap() }); } - -/// Assert that all files in `dir1` exist and have the same content in `dir2` -pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { - let dir2 = dir2.as_ref(); - read_dir(dir1, |entry_path| { - let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() { - assert_recursive_eq(&entry_path, &dir2.join(entry_name)); - } else { - let path2 = dir2.join(entry_name); - let file1 = fs_wrapper::read(&entry_path); - let file2 = fs_wrapper::read(&path2); - - // We don't use `assert_eq!` because they are `Vec`, so not great for display. - // Why not using String? Because there might be minified files or even potentially - // binary ones, so that would display useless output. - assert!( - file1 == file2, - "`{}` and `{}` have different content", - entry_path.display(), - path2.display(), - ); - } - }); -}