async function assertCallbackErrorUncaught(
  { prelude, invocation, cleanup },
) {
  // Since the error has to be uncaught, and that will kill the Deno process,
  // the only way to test this is to spawn a subprocess.
  const p = Deno.run({
    cmd: [
      Deno.execPath(),
      "eval",
      "--no-check",
      "--unstable",
      `${prelude ??
        ""}\n\n      ${invocation}(err) => {\n        // If the bug is present and the callback is called again with an error,\n        // don't throw another error, so if the subprocess fails we know it had the correct behaviour.\n        if (!err) throw new Error("success");\n      });`,
    ],
    stderr: "piped",
  });
  const status = await p.status();
  const stderr = new TextDecoder().decode(await readAll(p.stderr));
  p.close();
  p.stderr.close();
  await cleanup?.();
  assert(!status.success);
  assertStringIncludes(stderr, "Error: success");
}
/** Asserts that an error thrown in a callback will not be wrongly caught. */
Asserts that an error thrown in a callback will not be wrongly caught.
Asserts that an error thrown in a callback will not be wrongly caught .
async function assertCallbackErrorUncaught(
  { prelude, invocation, cleanup },
) {
  const p = Deno.run({
    cmd: [
      Deno.execPath(),
      "eval",
      "--no-check",
      "--unstable",
      `${prelude ??
        ""}\n\n      ${invocation}(err) => {\n        // If the bug is present and the callback is called again with an error,\n        // don't throw another error, so if the subprocess fails we know it had the correct behaviour.\n        if (!err) throw new Error("success");\n      });`,
    ],
    stderr: "piped",
  });
  const status = await p.status();
  const stderr = new TextDecoder().decode(await readAll(p.stderr));
  p.close();
  p.stderr.close();
  await cleanup?.();
  assert(!status.success);
  assertStringIncludes(stderr, "Error: success");
}
async function assertCallbackErrorUncaught ( { prelude , invocation , cleanup } , ) { const p = Deno . run ( { cmd : [ Deno . execPath ( ) , "eval" , "--no-check" , "--unstable" , ` ${ prelude ?? "" } \n \n ${ invocation } \n \n \n \n ` , ] , stderr : "piped" , } ) ; const status = await p . status ( ) ; const stderr = new TextDecoder ( ) . decode ( await readAll ( p . stderr ) ) ; p . close ( ) ; p . stderr . close ( ) ; await cleanup ?. ( ) ; assert ( ! status . success ) ; assertStringIncludes ( stderr , "Error: success" ) ; }
Asserts that an error thrown in a callback will not be wrongly caught.
Asserts that an error thrown in a callback will not be wrongly caught .
// Since the error has to be uncaught, and that will kill the Deno process, // the only way to test this is to spawn a subprocess.