diff --git a/examples/macro_main.rs b/examples/macro_main.rs new file mode 100644 index 0000000..d301547 --- /dev/null +++ b/examples/macro_main.rs @@ -0,0 +1,9 @@ +#![cfg_attr(not(target_os = "wasi"), no_main)] +#![cfg(target_os = "wasi")] + +//! Verifies that the `main` macro is compiling. + +#[wstd::main] +async fn main() { + println!("Hello world"); +} diff --git a/src/lib.rs b/src/lib.rs index e7abd6f..c884ad2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,15 +69,25 @@ pub mod net; pub mod rand; #[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod runtime; +#[cfg(all(target_os = "wasi", target_env = "p3"))] +pub mod runtime { + pub fn block_on(fut: F) -> F::Output + where + F: Future, + T: 'static, + { + wasip3::wit_bindgen::block_on(fut) + } +} #[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod task; #[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod time; #[cfg(all(target_os = "wasi", target_env = "p2"))] -pub use wstd_macro::{ - attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test, -}; +pub use wstd_macro::attr_macro_http_server as http_server; + +pub use wstd_macro::{attr_macro_main as main, attr_macro_test as test}; // Re-export the active WASI backend crate for use only by `wstd-macro` macros. // The proc macros need to generate code that uses these definitions, but we diff --git a/tests/http_first_byte_timeout.rs b/tests/http_first_byte_timeout.rs index 2162294..11d381a 100644 --- a/tests/http_first_byte_timeout.rs +++ b/tests/http_first_byte_timeout.rs @@ -2,7 +2,7 @@ use wstd::http::{Body, Client, Request, error::ErrorCode}; -#[wstd::main] +#[wstd::test] async fn main() -> Result<(), Box> { // Set first byte timeout to 1/2 second. let mut client = Client::new(); diff --git a/tests/macro_test.rs b/tests/macro_test.rs new file mode 100644 index 0000000..5dd0a22 --- /dev/null +++ b/tests/macro_test.rs @@ -0,0 +1,12 @@ +// Verify that the test macro is acutally running. + +#[wstd::test] +async fn computation() -> Result<(), String> { + assert_eq!(1 + 1, 2); + Ok(()) +} + +#[wstd::test] +async fn second_computation() { + assert_eq!(1 + 1, 2); +}