Skip to content

Commit

Permalink
Add support for async main
Browse files Browse the repository at this point in the history
  • Loading branch information
imbolc committed Dec 26, 2020
1 parent 225560c commit ef8013c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ pub fn split_input(
let (manifest, source) =
find_embedded_manifest(content).unwrap_or((Manifest::Toml(""), content));

let source = if source.lines().any(|line| line.starts_with("fn main()")) {
let source = if source
.lines()
.any(|line| line.starts_with("fn main()") || line.starts_with("async fn main()"))
{
source.to_string()
} else {
format!("fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {{\n {{\n {} }}\n Ok(())\n}}", source)
Expand Down
14 changes: 14 additions & 0 deletions tests/data/script-async-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! This is merged into a default manifest in order to form the full package manifest:
//!
//! ```cargo
//! [dependencies]
//! boolinator = "=0.1.0"
//! tokio = { version = "1", features = ["full"] }
//! ```
use boolinator::Boolinator;

#[tokio::main]
async fn main() {
println!("--output--");
println!("{:?}", true.as_some(1));
}
9 changes: 9 additions & 0 deletions tests/tests/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ fn script_without_main_question_mark() {
.stderr
.starts_with("Error: Os { code: 2, kind: NotFound, message:"));
}

#[test]
fn test_script_async_main() {
let out = rust_script!("tests/data/script-async-main.rs").unwrap();
scan!(out.stdout_output();
("Some(1)") => ()
)
.unwrap()
}

0 comments on commit ef8013c

Please sign in to comment.