MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / codegen_tests

Function codegen_tests

crates/test-helpers/codegen-macro/src/lib.rs:9–37  ·  view source on GitHub ↗
(_input: TokenStream)

Source from the content-addressed store, hash-verified

7/// `codegen_test!` macro then does what's necessary to actually run the test.
8#[proc_macro]
9pub fn codegen_tests(_input: TokenStream) -> TokenStream {
10 let tests_dir = env::current_dir().unwrap().join("tests/codegen");
11 let tests = tests_dir
12 .read_dir()
13 .unwrap()
14 .filter_map(|entry| {
15 let entry = entry.ok()?;
16 let path = entry.path();
17 let is_dir = entry.file_type().unwrap().is_dir();
18 if is_dir || path.extension().and_then(|s| s.to_str()) == Some("wit") {
19 let test_path = if is_dir {
20 path.join("wit")
21 } else {
22 path.clone()
23 };
24 let name = path.file_stem().unwrap().to_str().unwrap();
25 let ident = quote::format_ident!("{}", name.to_snake_case());
26 let path = test_path.to_str().unwrap();
27 Some(quote::quote! {
28 codegen_test!(#ident #name #path);
29 })
30 } else {
31 None
32 }
33 })
34 .collect::<Vec<_>>();
35
36 (quote::quote!(#(#tests)*)).into()
37}

Callers

nothing calls this directly

Calls 2

joinMethod · 0.80
and_thenMethod · 0.80

Tested by

no test coverage detected