mirror of https://github.com/aya-rs/aya
integration-test: Remove integration-test-macros
This doesn't add any value; use `cargo build --tests` with `--message-format=json` instead; parse the output using `cargo_metadata` to discover the location of the test binary. Move test/integration-test/src/tests -> test/integration-test/tests to conform to https://doc.rust-lang.org/book/ch11-03-test-organization.html#integration-tests.reviewable/pr640/r6
parent
ecc03ecfad
commit
9ca0af1a79
@ -1,13 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "integration-test-macros"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
quote = "1"
|
|
||||||
proc-macro2 = "1.0"
|
|
||||||
syn = {version = "2.0", features = ["full"]}
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
@ -1,46 +0,0 @@
|
|||||||
use proc_macro::TokenStream;
|
|
||||||
use proc_macro2::Span;
|
|
||||||
use quote::quote;
|
|
||||||
use syn::{parse_macro_input, Ident, ItemFn};
|
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
|
||||||
pub fn integration_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
||||||
let item = parse_macro_input!(item as ItemFn);
|
|
||||||
let name = &item.sig.ident;
|
|
||||||
let name_str = &item.sig.ident.to_string();
|
|
||||||
let expanded = quote! {
|
|
||||||
#item
|
|
||||||
|
|
||||||
inventory::submit!(crate::IntegrationTest {
|
|
||||||
name: concat!(module_path!(), "::", #name_str),
|
|
||||||
test_fn: #name,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
|
||||||
pub fn tokio_integration_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|
||||||
let item = parse_macro_input!(item as ItemFn);
|
|
||||||
let name = &item.sig.ident;
|
|
||||||
let name_str = &item.sig.ident.to_string();
|
|
||||||
let sync_name_str = format!("sync_{name_str}");
|
|
||||||
let sync_name = Ident::new(&sync_name_str, Span::call_site());
|
|
||||||
let expanded = quote! {
|
|
||||||
#item
|
|
||||||
|
|
||||||
fn #sync_name() {
|
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
rt.block_on(#name());
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory::submit!(crate::IntegrationTest {
|
|
||||||
name: concat!(module_path!(), "::", #sync_name_str),
|
|
||||||
test_fn: #sync_name,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
@ -0,0 +1 @@
|
|||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
use libtest_mimic::{Arguments, Trial};
|
|
||||||
|
|
||||||
mod tests;
|
|
||||||
use tests::IntegrationTest;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
env_logger::init();
|
|
||||||
let mut args = Arguments::from_args();
|
|
||||||
// Force to run single-threaded
|
|
||||||
args.test_threads = Some(1);
|
|
||||||
let tests = inventory::iter::<IntegrationTest>
|
|
||||||
.into_iter()
|
|
||||||
.map(|test| {
|
|
||||||
Trial::test(test.name, move || {
|
|
||||||
(test.test_fn)();
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
libtest_mimic::run(&args, tests).exit();
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
use super::integration_test;
|
|
||||||
|
|
||||||
use aya::include_bytes_aligned;
|
use aya::include_bytes_aligned;
|
||||||
use object::{Object, ObjectSymbol};
|
use object::{Object, ObjectSymbol};
|
||||||
|
|
||||||
#[integration_test]
|
#[test]
|
||||||
fn test_maps() {
|
fn test_maps() {
|
||||||
let bytes = include_bytes_aligned!("../../../../target/bpfel-unknown-none/release/map_test");
|
let bytes = include_bytes_aligned!("../../../target/bpfel-unknown-none/release/map_test");
|
||||||
let obj_file = object::File::parse(bytes).unwrap();
|
let obj_file = object::File::parse(bytes).unwrap();
|
||||||
if obj_file.section_by_name("maps").is_none() {
|
if obj_file.section_by_name("maps").is_none() {
|
||||||
panic!("No 'maps' ELF section");
|
panic!("No 'maps' ELF section");
|
Loading…
Reference in New Issue