mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-19 12:35:07 +00:00
Support compiling programs with test mode in test_mono
This commit is contained in:
parent
2ec473ba11
commit
935255d06b
2 changed files with 41 additions and 20 deletions
|
@ -1,14 +1,30 @@
|
|||
//! Macros for use in `test_mono`.
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::{TokenStream, TokenTree};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn mono_test(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let no_check = args
|
||||
.into_iter()
|
||||
.any(|tok| matches!(tok, TokenTree::Ident(id) if id.to_string() == "no_check"));
|
||||
let mut no_check = false;
|
||||
let mut mode = "exec".to_owned();
|
||||
for arg in syn::parse_macro_input!(args as syn::AttributeArgs) {
|
||||
use syn::{Lit, Meta, MetaNameValue, NestedMeta};
|
||||
if matches!(&arg, NestedMeta::Meta(Meta::Path(p)) if p.is_ident("no_check")) {
|
||||
no_check = true;
|
||||
}
|
||||
if let NestedMeta::Meta(Meta::NameValue(MetaNameValue {
|
||||
path,
|
||||
eq_token: _,
|
||||
lit: Lit::Str(s),
|
||||
})) = arg
|
||||
{
|
||||
if path.is_ident("mode") {
|
||||
mode = s.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let task_fn = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
|
||||
let args = task_fn.sig.inputs.clone();
|
||||
|
@ -24,7 +40,7 @@ pub fn mono_test(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||
#[test]
|
||||
#(#attributes)*
|
||||
#visibility fn #name(#args) {
|
||||
compiles_to_ir(#name_str, #body, #no_check);
|
||||
compiles_to_ir(#name_str, #body, &#mode, #no_check);
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue