From 3f309610272107d246be82aba37ed9c8ad7573fe Mon Sep 17 00:00:00 2001 From: increno Date: Wed, 26 Aug 2026 21:44:29 +0200 Subject: [PATCH] Handle whitespace between fn and main --- src/manifest.rs | 2 +- .../data/script-main-with-spaces-between-fn-and-name.rs | 4 ++++ tests/tests/script.rs | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/data/script-main-with-spaces-between-fn-and-name.rs diff --git a/src/manifest.rs b/src/manifest.rs index 5c2085b..48f2260 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -33,7 +33,7 @@ pub fn split_input( ) -> MainResult<(String, PathBuf, Option)> { fn contains_main_method(source: &str) -> bool { let re_main: Regex = - Regex::new(r#"(?m)^ *(pub )?(async )?(extern "C" )?fn main *\("#).unwrap(); + Regex::new(r#"(?m)^ *(pub )?(async )?(extern "C" )?fn +main *\("#).unwrap(); re_main.is_match(source) } diff --git a/tests/data/script-main-with-spaces-between-fn-and-name.rs b/tests/data/script-main-with-spaces-between-fn-and-name.rs new file mode 100644 index 0000000..f57def5 --- /dev/null +++ b/tests/data/script-main-with-spaces-between-fn-and-name.rs @@ -0,0 +1,4 @@ +fn main() { + println!("--output--"); + println!("Hello, World!"); +} diff --git a/tests/tests/script.rs b/tests/tests/script.rs index 5facc4f..f81bbc7 100644 --- a/tests/tests/script.rs +++ b/tests/tests/script.rs @@ -47,6 +47,15 @@ fn test_script_main_with_space() { .unwrap() } +#[test] +fn test_script_main_with_spaces_between_fn_and_name() { + let out = rust_script!("tests/data/script-main-with-spaces-between-fn-and-name.rs").unwrap(); + scan!(out.stdout_output(); + ("Hello, World!") => () + ) + .unwrap() +} + #[test] fn test_script_invalid_doc_comment() { let out = rust_script!("tests/data/script-invalid-doc-comment.rs").unwrap();