-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't rely on a thread local to uniquely create test roots
- Loading branch information
Showing
6 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/target | ||
/tests/testsuite/support/cargo-test-macro/target | ||
Cargo.lock | ||
.cargo | ||
/config.stamp | ||
|
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,12 @@ | ||
[package] | ||
name = "cargo-test-macro" | ||
version = "0.1.0" | ||
authors = ["Jethro Beekman <jethro@fortanix.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
quote = "0.6" | ||
syn = { version = "0.15", features = ["full"] } |
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 @@ | ||
extern crate proc_macro; | ||
|
||
use quote::{quote, ToTokens}; | ||
use syn::{*, parse::Parser}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn cargo_test( | ||
_attr: proc_macro::TokenStream, | ||
item: proc_macro::TokenStream, | ||
) -> proc_macro::TokenStream { | ||
let mut fn_def = parse_macro_input!(item as ItemFn); | ||
|
||
let attr = quote! { | ||
#[test] | ||
}; | ||
fn_def.attrs.extend(Attribute::parse_outer.parse2(attr).unwrap()); | ||
|
||
let stmt = quote! { | ||
let _test_guard = crate::support::paths::init_root(); | ||
}; | ||
fn_def.block.stmts.insert(0, parse2(stmt).unwrap()); | ||
|
||
fn_def.into_token_stream().into() | ||
} |
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