aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/util.rs b/src/util.rs
index 2d2d911..373d784 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,15 +1,41 @@
-#[cfg(not(test))]
-macro_rules! use_dependency_history {
- () => {
- use $crate::dependency_history::DependencyHistory;
+//! Internal utilities.
+
+/// Imports the specified item, prepending 'Mock' to the item identifier if the `test`
+/// configuration option is set.
+///
+/// # Examples
+/// ```ignore
+/// use_double!(crate::dependency_history::DependencyHistory);
+/// ```
+/// <br>
+///
+/// Expands to the following when `cfg(not(test))`
+/// ```ignore
+/// use crate::dependency_history::DependencyHistory;
+/// ```
+/// <br>
+///
+/// Expands to the following when `cfg(test)`
+/// ```ignore
+/// use crate::dependency_history::MockDependencyHistory as DependencyHistory;
+/// ```
+macro_rules! use_double {
+ ($([$($part: ident),*])? $item_path_part: ident :: $($next_part: tt)+) => {
+ use_double!(
+ [$($($part,)*)? $item_path_part]
+ $($next_part)+
+ );
};
-}
-#[cfg(test)]
-macro_rules! use_dependency_history {
- () => {
- use $crate::dependency_history::MockDependencyHistory as DependencyHistory;
+ ([$($part: ident),*] $item_path_part: ident) => {
+ #[cfg(not(test))]
+ use $($part::)* $item_path_part;
+
+ ::paste::paste! {
+ #[cfg(test)]
+ use $($part::)* [<Mock $item_path_part>] as $item_path_part;
+ }
};
}
-pub(crate) use use_dependency_history;
+pub(crate) use use_double;