diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-05-01 14:44:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-01 14:44:55 -0400 |
commit | de33017a8bc3ddc79664df0fae3ded5607b38180 (patch) | |
tree | fc730a65fe488b1e8e5b380734ff0550aeda3681 /runtime/ops/io.rs | |
parent | 671f56f8ff512fcf4ad016f2b2fdd36c2ac7237f (diff) |
fix(test): actually capture stdout and stderr in workers (#14435)
Diffstat (limited to 'runtime/ops/io.rs')
-rw-r--r-- | runtime/ops/io.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index f18624eb2..a357dd6f1 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -111,6 +111,10 @@ pub fn init_stdio(stdio: Stdio) -> Extension { let stdio = Rc::new(RefCell::new(Some(stdio))); Extension::builder() + .middleware(|op| match op.name { + "op_print" => op_print::decl(), + _ => op, + }) .state(move |state| { let stdio = stdio .borrow_mut() @@ -419,6 +423,24 @@ impl Resource for StdFileResource { } } +// override op_print to use the stdout and stderr in the resource table +#[op] +pub fn op_print( + state: &mut OpState, + msg: String, + is_err: bool, +) -> Result<(), AnyError> { + let rid = if is_err { 2 } else { 1 }; + StdFileResource::with(state, rid, move |r| match r { + Ok(std_file) => { + std_file.write_all(msg.as_bytes())?; + std_file.flush().unwrap(); + Ok(()) + } + Err(_) => Err(not_supported()), + }) +} + #[op] fn op_read_sync( state: &mut OpState, |