Skip to content

Fix tests for a future nightly #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 43 additions & 50 deletions stdsimd-test/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,48 @@ pub fn assert_instr(
&format!("assert_{}_{}", name.as_ref(), instr.as_ref())[..],
);
let shim_name = syn::Ident::from(format!("{}_shim", name.as_ref()));
let (to_test, test_name) = if invoc.args.len() == 0 {
(TokenStream::empty(), &func.ident)
} else {
let mut inputs = Vec::new();
let mut input_vals = Vec::new();
let ret = &func.decl.output;
for arg in func.decl.inputs.iter() {
let capture = match *arg {
syn::FnArg::Captured(ref c) => c,
_ => panic!("arguments must not have patterns"),
};
let ident = match capture.pat {
syn::Pat::Ident(ref i) => &i.ident,
_ => panic!("must have bare arguments"),
};
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
Some(&(_, ref tts)) => {
input_vals.push(quote! { #tts });
}
None => {
inputs.push(capture);
input_vals.push(quote! { #ident });
}
};
}
let mut inputs = Vec::new();
let mut input_vals = Vec::new();
let ret = &func.decl.output;
for arg in func.decl.inputs.iter() {
let capture = match *arg {
syn::FnArg::Captured(ref c) => c,
_ => panic!("arguments must not have patterns"),
};
let ident = match capture.pat {
syn::Pat::Ident(ref i) => &i.ident,
_ => panic!("must have bare arguments"),
};
match invoc.args.iter().find(|a| a.0 == ident.as_ref()) {
Some(&(_, ref tts)) => {
input_vals.push(quote! { #tts });
}
None => {
inputs.push(capture);
input_vals.push(quote! { #ident });
}
};
}

let attrs = func.attrs
.iter()
.filter(|attr| {
attr.path
.segments
.first()
.unwrap()
.value()
.ident
.as_ref()
.starts_with("target")
})
.collect::<Vec<_>>();
let attrs = Append(&attrs);
(
quote! {
#attrs
unsafe fn #shim_name(#(#inputs),*) #ret {
#name(#(#input_vals),*)
}
}.into(),
&shim_name,
)
let attrs = func.attrs
.iter()
.filter(|attr| {
attr.path
.segments
.first()
.unwrap()
.value()
.ident
.as_ref()
.starts_with("target")
})
.collect::<Vec<_>>();
let attrs = Append(&attrs);
let to_test = quote! {
#attrs
unsafe extern fn #shim_name(#(#inputs),*) #ret {
#name(#(#input_vals),*)
}
};

let tts: TokenStream = quote_spanned! {
Expand All @@ -102,8 +95,8 @@ pub fn assert_instr(
fn #assert_name() {
#to_test

::stdsimd_test::assert(#test_name as usize,
stringify!(#test_name),
::stdsimd_test::assert(#shim_name as usize,
stringify!(#shim_name),
stringify!(#instr));
}
}.into();
Expand Down