-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test: making it cooler! (#1821)
* basic structure * add macro impl * adapt example test cases * add macro to tests * minor doc change * taplo
- Loading branch information
Showing
18 changed files
with
183 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "runtime-integration-tests-proc-macro" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
documentation.workspace = true | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
prettyplease = "0.2" | ||
proc-macro2 = "1.0" | ||
quote = "1.0" | ||
syn = { version = "2.0", features = ["full", "extra-traits"] } | ||
|
||
[features] | ||
default = [] | ||
|
||
# Enable this macro to show the proc macros unrolled when compiling | ||
debug-proc-macros = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, Expr, ItemFn}; | ||
|
||
/// Test the function against different runtimes | ||
/// | ||
/// ```rust,ignore | ||
/// use crate::generic::config::Runtime; | ||
/// | ||
/// #[test_runtimes([development, altair, centrifuge])] | ||
/// fn foo<T: Runtime> { | ||
/// // Your test here... | ||
/// } | ||
/// ``` | ||
/// You can test all runtimes also as: | ||
/// ```rust,ignore | ||
/// use crate::generic::config::Runtime; | ||
/// | ||
/// #[test_runtimes(all)] | ||
/// fn foo<T: Runtime> { | ||
/// // Your test here... | ||
/// } | ||
/// ``` | ||
/// | ||
/// You can test for fudge support adding the bound: | ||
/// ```rust,ignore | ||
/// use crate::generic::{config::Runtime, envs::fudge_env::FudgeSupport}; | ||
/// | ||
/// #[test_runtimes(all)] | ||
/// fn foo<T: Runtime + FudgeSupport> { | ||
/// // Your test here... | ||
/// } | ||
/// ``` | ||
/// | ||
/// For the following command: `cargo test -p runtime-integration-tests foo`, | ||
/// it will generate the following output: | ||
/// | ||
/// ```text | ||
/// test generic::foo::altair ... ok | ||
/// test generic::foo::development ... ok | ||
/// test generic::foo::centrifuge ... ok | ||
/// ``` | ||
/// | ||
/// Available input for the argument is: | ||
/// - Any combination of `development`, `altair`, `centrifuge` inside `[]`. | ||
/// - The world `all`. | ||
#[proc_macro_attribute] | ||
pub fn test_runtimes(args: TokenStream, input: TokenStream) -> TokenStream { | ||
let args = parse_macro_input!(args as Expr); | ||
let func = parse_macro_input!(input as ItemFn); | ||
|
||
let func_name = &func.sig.ident; | ||
|
||
quote! { | ||
crate::test_for_runtimes!(#args, #func_name); | ||
#func | ||
} | ||
.into() | ||
} | ||
|
||
/// Wrapper over test_runtime to print the output | ||
#[proc_macro_attribute] | ||
pub fn __dbg_test_runtimes(args: TokenStream, input: TokenStream) -> TokenStream { | ||
let tokens = test_runtimes(args, input); | ||
let file = syn::parse_file(&tokens.to_string()).unwrap(); | ||
|
||
println!("{}", prettyplease::unparse(&file)); | ||
|
||
TokenStream::default() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![allow(unused)] | ||
#![cfg(feature = "debug-proc-macros")] | ||
|
||
#[macro_use] | ||
extern crate runtime_integration_tests_proc_macro; | ||
|
||
#[__dbg_test_runtimes(all)] | ||
fn macro_runtimes() {} | ||
|
||
#[__dbg_test_runtimes([development, altair, centrifuge])] | ||
fn macro_runtimes_list() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.