dir_assert/
lib.rs

1//! Compare contents of two directories.
2//!
3//! This crate provides macro and function for asserting whether two directories or files are equal.
4//!
5//! Example usage:
6//! ```rust,ignore
7//! #[test]
8//! fn test_macro() {
9//!     assert_paths!("actual", "expected");
10//! }
11//!
12//! #[test]
13//! fn test_fn() {
14//!     assert_paths("actual", "expected").unwrap();
15//! }
16//! ```
17//!
18//! These functions will panic yielding detailed information about which paths didn't match during comparison.
19//! Moreover, line at which each file differs, when other with same name is found also will be reported.
20//!
21//! To do before 1.0:
22//! * [ ] assert should `println!` or `debug!` all paths it went through
23//! * [x] we need to follow symlinks
24//! * [ ] we need to add optional configuration to:
25//!     * [ ] know if follow symlinks or just compare their names
26//!     * [ ] compare `actual` with stringified dir (no `expected` folder, only &str as input)
27//!     * [ ] provide file comparison function (we may use hashing comparers or just check file metadata)
28//! * [ ] unit test error `new_*` functions
29//! * [ ] change acceptance tests to compare `Debug` instead of `Display`
30//! * [ ] hide `Debug` and `Clone` implementations behind feature
31
32mod assert_paths;
33mod error;
34
35pub use crate::assert_paths::assert_paths;
36pub use crate::error::Error;
37
38/// Recursively scan contents of two directories and find differences.
39///
40/// eg.:
41/// ```rust,ignore
42/// #[test]
43/// fn should_directories_be_equal() {
44///     assert_paths!("actual", "expected");
45/// }
46/// ```
47///
48/// This macro will panic if directories "actual" and "expected" differ at any depth.
49///
50/// It can accept both file names and directory names as arguments.
51#[macro_export]
52macro_rules! assert_paths {
53    ($actual: expr, $expected: expr) => {{
54        match $crate::assert_paths($actual, $expected) {
55            Ok(_) => { /* do nothing */ }
56            Err(test_result) => panic!("file mismatch\n{:#?}", test_result),
57        }
58    }};
59}