Skip to content

Commit

Permalink
test: Patch compiler-test to create the feature name correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed May 28, 2021
1 parent 79d5f20 commit e11fc26
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions tests/lib/compiler-test-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
};
let construct_engine_test = |func: &::syn::ItemFn,
compiler_name: &str,
engine_name: &str|
engine_name: &str,
engine_feature_name: &str|
-> ::proc_macro2::TokenStream {
let config_compiler = ::quote::format_ident!("{}", compiler_name);
let config_engine = ::quote::format_ident!("{}", engine_name);
let engine_name_lowercase = engine_name.to_lowercase();
let test_name = ::quote::format_ident!("{}", engine_name_lowercase);
let test_name = ::quote::format_ident!("{}", engine_name.to_lowercase());
let mut new_sig = func.sig.clone();
let attrs = func
.attrs
Expand All @@ -87,7 +87,7 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
let f = quote! {
#[test]
#attrs
#[cfg(feature = #engine_name_lowercase)]
#[cfg(feature = #engine_feature_name)]
#new_sig {
#fn_name(crate::Config::new(crate::Engine::#config_engine, crate::Compiler::#config_compiler))
}
Expand All @@ -107,24 +107,25 @@ pub fn compiler_test(attrs: TokenStream, input: TokenStream) -> TokenStream {
}
};

let construct_compiler_test = |func: &::syn::ItemFn,
compiler_name: &str|
-> ::proc_macro2::TokenStream {
let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase());
let universal_engine_test = construct_engine_test(func, compiler_name, "Universal");
let shared_object_engine_test = construct_engine_test(func, compiler_name, "SharedObject");
let compiler_name_lowercase = compiler_name.to_lowercase();

quote! {
#[cfg(feature = #compiler_name_lowercase)]
mod #mod_name {
use super::*;

#universal_engine_test
#shared_object_engine_test
let construct_compiler_test =
|func: &::syn::ItemFn, compiler_name: &str| -> ::proc_macro2::TokenStream {
let mod_name = ::quote::format_ident!("{}", compiler_name.to_lowercase());
let universal_engine_test =
construct_engine_test(func, compiler_name, "Universal", "universal");
let shared_object_engine_test =
construct_engine_test(func, compiler_name, "SharedObject", "shared-object");
let compiler_name_lowercase = compiler_name.to_lowercase();

quote! {
#[cfg(feature = #compiler_name_lowercase)]
mod #mod_name {
use super::*;

#universal_engine_test
#shared_object_engine_test
}
}
}
};
};

let singlepass_compiler_test = construct_compiler_test(&my_fn, "Singlepass");
let cranelift_compiler_test = construct_compiler_test(&my_fn, "Cranelift");
Expand Down

0 comments on commit e11fc26

Please sign in to comment.