diff --git a/src/lib.rs b/src/lib.rs index d0db1d7..6b83e24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,8 +42,7 @@ impl Parse for ForEachFile { let path_span = path.span(); let path = path.value(); - let module = if input.peek(Token![as]) { - input.parse::()?; + let module = if let Ok(_) = input.parse::() { Some(input.parse::()?) } else { None @@ -151,6 +150,10 @@ fn generate_from_tree(tree: &Tree, parsed: &ForEachFile, stream: &mut TokenStrea pub fn test_each_file(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let parsed = parse_macro_input!(input as ForEachFile); + if !Path::new(&parsed.path).is_dir() { + abort!(parsed.path_span, "Given directory does not exist"); + } + let mut tokens = TokenStream::new(); let files = Tree::new(parsed.path.as_ref(), !parsed.extensions.is_empty()); generate_from_tree(&files, &parsed, &mut tokens);