From 244926e83c7d3cae3c3ae3fc14e996e3066da43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 15 Apr 2022 14:24:41 +0200 Subject: feat(test): format user code output (#14271) This commit changes "deno test" to better denote user output coming from test cases. This is done by printing "---- output ----" and "---- output end ----" markers if an output is produced. The output from "console" and "Deno.core.print" is captured, as well as direct writes to "Deno.stdout" and "Deno.stderr". To achieve that new APIs were added to "deno_core" crate, that allow to replace an existing resource with a different one (while keeping resource ids intact). Resources for stdout and stderr are replaced by pipes. Co-authored-by: David Sherret --- core/resources.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core/resources.rs') diff --git a/core/resources.rs b/core/resources.rs index 07d4e7041..9a1447392 100644 --- a/core/resources.rs +++ b/core/resources.rs @@ -147,6 +147,16 @@ impl ResourceTable { .ok_or_else(bad_resource_id) } + /// Replaces a resource with a new resource. + /// + /// Panics if the resource does not exist. + pub fn replace(&mut self, rid: ResourceId, resource: T) { + let result = self + .index + .insert(rid, Rc::new(resource) as Rc); + assert!(result.is_some()); + } + /// Removes a resource of type `T` from the resource table and returns it. /// If a resource with the given `rid` exists but its type does not match `T`, /// it is not removed from the resource table. Note that the resource's -- cgit v1.2.3