Add new Rust-based tests
There's a lot going on here. First, this is intended to run nicely as part of the new [cosa/kola ext-tests](https://github.com/coreos/coreos-assembler/pull/1252). With Rust we can get one big static binary that we can upload, and include a webserver as part of the binary. This way we don't need to do the hack of running a container with Python or whatever. Now, what's even better about Rust for this is that it has macros, and specifically we are using [commandspec](https://github.com/tcr/commandspec/) which allows us to "inline" shell script. I think the macros could be even better, but this shows how we can intermix pure Rust code along with using shell safely enough. We're using my fork of commandspec because the upstream hasn't merged [a few PRs](https://github.com/tcr/commandspec/pulls?q=is%3Apr+author%3Acgwalters+). This model is intended to replace *both* some of our `make check` tests as well. Oh, and this takes the obvious step of using the Rust OSTree bindings as part of our tests. Currently the "commandspec tests" and "API tests" are separate, but nothing stops us from intermixing them if we wanted. I haven't yet tried to write destructive tests with this but I think it will go well.
This commit is contained in:
1 parent
854099802f
commit
1f637bf341
13 files changed
+495
-33
No files matched your search
@@ -0,0 +1,32 @@
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use quote::quote;
|
||||
|
||||
/// Wraps function using `procspawn` to allocate a new temporary directory,
|
||||
/// make it the process' working directory, and run the function.
|
||||
#[proc_macro_attribute]
|
||||
pub fn itest(attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let attrs = syn::parse_macro_input!(attrs as syn::AttributeArgs);
|
||||
if attrs.len() > 0 {
|
||||
return syn::Error::new_spanned(&attrs[0], "itest takes no attributes")
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
let func = syn::parse_macro_input!(input as syn::ItemFn);
|
||||
let fident = func.sig.ident.clone();
|
||||
let varident = quote::format_ident!("ITEST_{}", fident);
|
||||
let fidentstrbuf = format!(r#"{}"#, fident);
|
||||
let fidentstr = syn::LitStr::new(&fidentstrbuf, Span::call_site());
|
||||
let output = quote! {
|
||||
#[linkme::distributed_slice(TESTS)]
|
||||
#[allow(non_upper_case_globals)]
|
||||
static #varident : Test = Test {
|
||||
name: #fidentstr,
|
||||
f: #fident,
|
||||
};
|
||||
#func
|
||||
};
|
||||
output.into()
|
||||
}
|
||||
Reference in new issue
Block a user