Skip to content

Commit

Permalink
Merge?
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed Apr 17, 2024
1 parent 4b74121 commit 87c8c32
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ fn generate_from_tree(
parsed: &TestEachArgs,
stream: &mut TokenStream,
invocation_type: &Type,
) {
) -> Result<(), String> {
let mut taken_names_folders = HashSet::new();
for (name, directory) in tree.children.iter() {
let file_name = name.file_name().unwrap().to_str().unwrap();
let file_name = sanitize_ident(file_name);
let file_name = generate_name(file_name, &mut taken_names_folders);

let mut sub_stream = TokenStream::new();
generate_from_tree(directory, parsed, &mut sub_stream, invocation_type);
generate_from_tree(directory, parsed, &mut sub_stream, invocation_type)?;
stream.extend(quote! {
mod #file_name {
use super::*;
Expand Down Expand Up @@ -203,10 +203,13 @@ fn generate_from_tree(
let mut arguments = TokenStream::new();

for extension in &parsed.extensions {
let input = file.with_extension(extension).canonicalize().unwrap();
let input = match file.with_extension(extension).canonicalize() {
Ok(path) => path,
Err(e) => return Err(format!("Failed to read expected file {}.{extension}: {e}", file.display())),
};
if !input.exists() {
abort_call_site!(format!(
"Expected file {:?} with extension {}, but it does not exist.",
return Err(format!(
"Expected file {:?}.{}, but it does not exist.",
file, extension
))
}
Expand All @@ -228,6 +231,8 @@ fn generate_from_tree(
}
});
}

Ok(())
}

fn test_each(input: proc_macro::TokenStream, invocation_type: &Type) -> proc_macro::TokenStream {
Expand All @@ -247,8 +252,6 @@ fn test_each(input: proc_macro::TokenStream, invocation_type: &Type) -> proc_mac
if let Err(e) = generate_from_tree(&files, &parsed, &mut tokens, invocation_type) {
abort_token_stream!(parsed.path.span(), e)
}
let files = Tree::new(parsed.path.value().as_ref(), &parsed.extensions);
generate_from_tree(&files, &parsed, &mut tokens, invocation_type);

if let Some(module) = parsed.module {
tokens = quote! {
Expand Down

0 comments on commit 87c8c32

Please sign in to comment.