diff options
| author | Gus Power <gus@infinitesidequests.com> | 2025-05-21 16:23:55 +0100 |
|---|---|---|
| committer | Gus Power <gus@infinitesidequests.com> | 2025-05-21 16:23:55 +0100 |
| commit | d7ce374a1741fdbb5c3aeef1218058a3d1060e88 (patch) | |
| tree | ac4297e69ce670155fcd3c37c29b085d3707decc /src/test_macros.rs | |
| parent | 9ce9c101a10327b1eb6902133173119c3e0f3732 (diff) | |
config fallback w/ tests. introduced a macro to remove some test boilerplate around Result<T,E> and having return Ok(())
Diffstat (limited to 'src/test_macros.rs')
| -rw-r--r-- | src/test_macros.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/test_macros.rs b/src/test_macros.rs index 9f3ff2b..e1998cd 100644 --- a/src/test_macros.rs +++ b/src/test_macros.rs @@ -1,4 +1,17 @@ #[macro_export] +macro_rules! test { + (fn $name:ident() $body:block) => { + #[test] + fn $name() -> Result<(), Box<dyn std::error::Error>> { + (|| -> Result<(), Box<dyn std::error::Error>> { + $body; + Ok(()) + })() + } + }; +} + +#[macro_export] macro_rules! assert_error { ($result:expr, $pattern:pat => $body:block) => { match $result { @@ -12,9 +25,9 @@ macro_rules! assert_error { } #[macro_export] -macro_rules! assert_file_not_found { +macro_rules! assert_config_file_not_found { ($result:expr, $expected_path:expr) => { - assert_error!($result, AppError::FileNotFound(path) => { + assert_error!($result, AppError::ConfigFileNotFound(path) => { assert_eq!(path, $expected_path, "Expected file not found for path {:?}, but got path {:?}", $expected_path, path); |
