Skip to content

Add support for async main #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}