aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-08-18 21:53:36 +0200
committerHampusM <hampus@hampusmat.com>2023-08-18 21:53:36 +0200
commitd9fb89865165bdd31807c3fbec2def6d3ebb7b53 (patch)
tree6bc1c5d92e6d2737c1525c933efbc19f632b0dde /src/util.rs
parent055a98aec1fe534d78414d630ab5ba2b789cba64 (diff)
refactor: replace use_dependency_history with a more generic macro
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;