| 7 | /// `codegen_test!` macro then does what's necessary to actually run the test. |
| 8 | #[proc_macro] |
| 9 | pub 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 | } |