1#[macro_export]
40macro_rules! assert_data_eq {
41 ($actual: expr, $expected: expr $(,)?) => {{
42 let actual = $crate::IntoData::into_data($actual);
43 let expected = $crate::IntoData::into_data($expected);
44 $crate::Assert::new()
45 .action_env($crate::assert::DEFAULT_ACTION_ENV)
46 .eq(actual, expected);
47 }};
48}
49
50#[doc(hidden)] #[macro_export]
53macro_rules! current_dir {
54 () => {{
55 let root = $crate::utils::cargo_rustc_current_dir!();
56 let file = ::std::file!();
57 let rel_path = ::std::path::Path::new(file).parent().unwrap();
58 root.join(rel_path)
59 }};
60}
61
62#[doc(hidden)] #[macro_export]
65macro_rules! current_rs {
66 () => {{
67 let root = $crate::utils::cargo_rustc_current_dir!();
68 let file = ::std::file!();
69 let rel_path = ::std::path::Path::new(file);
70 root.join(rel_path)
71 }};
72}
73
74#[doc(hidden)] #[macro_export]
77macro_rules! cargo_rustc_current_dir {
78 () => {{
79 if let Some(rustc_root) = ::std::option_env!("CARGO_RUSTC_CURRENT_DIR") {
80 ::std::path::Path::new(rustc_root)
81 } else {
82 let manifest_dir = ::std::path::Path::new(::std::env!("CARGO_MANIFEST_DIR"));
83 manifest_dir
84 .ancestors()
85 .filter(|it| it.join("Cargo.toml").exists())
86 .last()
87 .unwrap()
88 }
89 }};
90}
91
92#[doc(hidden)]
96#[macro_export]
97macro_rules! fn_path {
98 () => {{
99 fn f() {}
100 fn type_name_of_val<T>(_: T) -> &'static str {
101 std::any::type_name::<T>()
102 }
103 let mut name = type_name_of_val(f).strip_suffix("::f").unwrap_or("");
104 while let Some(rest) = name.strip_suffix("::{{closure}}") {
105 name = rest;
106 }
107 name
108 }};
109}
110
111#[cfg(test)]
112mod test {
113 #[test]
114 fn direct_fn_path() {
115 assert_eq!(fn_path!(), "snapbox::macros::test::direct_fn_path");
116 }
117
118 #[test]
119 #[allow(clippy::redundant_closure_call)]
120 fn closure_fn_path() {
121 (|| {
122 assert_eq!(fn_path!(), "snapbox::macros::test::closure_fn_path");
123 })();
124 }
125
126 #[test]
127 fn nested_fn_path() {
128 fn nested() {
129 assert_eq!(fn_path!(), "snapbox::macros::test::nested_fn_path::nested");
130 }
131 nested();
132 }
133}