Skip to content

Commit

Permalink
Add valid given path check and small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenvdmeulen committed Nov 5, 2023
1 parent b637561 commit c97b032
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Token![as]>()?;
let module = if let Ok(_) = input.parse::<Token![as]>() {
Some(input.parse::<Ident>()?)
} else {
None
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c97b032

Please sign in to comment.