1 use test_programs::p3::wasi::cli::{ 2 environment, stderr, stdin, stdout, terminal_stderr, terminal_stdin, terminal_stdout, 3 }; 4 use test_programs::p3::wit_stream; 5 use wit_bindgen::StreamResult; 6 7 struct Component; 8 9 test_programs::p3::export!(Component); 10 11 impl test_programs::p3::exports::wasi::cli::run::Guest for Component { 12 async fn run() -> Result<(), ()> { 13 assert_eq!(environment::get_arguments(), ["p3_cli.component", "."]); 14 assert_ne!(environment::get_environment(), []); 15 assert_eq!(environment::get_initial_cwd(), None); 16 17 assert!(terminal_stdin::get_terminal_stdin().is_none()); 18 assert!(terminal_stdout::get_terminal_stdout().is_none()); 19 assert!(terminal_stderr::get_terminal_stderr().is_none()); 20 21 let (mut stdin, result) = stdin::read_via_stream(); 22 assert!(stdin.next().await.is_none()); 23 24 let (mut stdout_tx, stdout_rx) = wit_stream::new(); 25 futures::join!( 26 async { 27 stdout::write_via_stream(stdout_rx).await.unwrap(); 28 }, 29 async { 30 let (res, buf) = stdout_tx.write(b"hello stdout\n".into()).await; 31 assert_eq!(res, StreamResult::Complete(13)); 32 assert_eq!(buf.into_vec(), []); 33 drop(stdout_tx); 34 } 35 ); 36 37 let (mut stderr_tx, stderr_rx) = wit_stream::new(); 38 futures::join!( 39 async { 40 stderr::write_via_stream(stderr_rx).await.unwrap(); 41 }, 42 async { 43 let (res, buf) = stderr_tx.write(b"hello stderr\n".into()).await; 44 assert_eq!(res, StreamResult::Complete(13)); 45 assert_eq!(buf.into_vec(), []); 46 drop(stderr_tx); 47 } 48 ); 49 50 drop(stdin); 51 result.await.unwrap(); 52 53 Ok(()) 54 } 55 } 56 57 fn main() {} 58