summaryrefslogtreecommitdiff
path: root/cli/tests/unit/dispatch_bin_test.ts
blob: ca18646219c22a69e693765d458018b06eb350eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
  assert,
  assertEquals,
  assertMatch,
  unitTest,
  unreachable,
} from "./test_util.ts";

const readErrorStackPattern = new RegExp(
  `^.*
    at processErr \\(.*core\\.js:.*\\)
    at opAsyncHandler \\(.*core\\.js:.*\\)
    at handleAsyncMsgFromRust \\(.*core\\.js:.*\\).*$`,
  "ms",
);

unitTest(async function sendAsyncStackTrace(): Promise<void> {
  const buf = new Uint8Array(10);
  const rid = 10;
  try {
    await Deno.read(rid, buf);
    unreachable();
  } catch (error) {
    assertMatch(error.stack, readErrorStackPattern);
  }
});

declare global {
  // deno-lint-ignore no-namespace
  namespace Deno {
    // deno-lint-ignore no-explicit-any
    var core: any; // eslint-disable-line no-var
  }
}

unitTest(async function binOpsAsyncBadResource(): Promise<void> {
  try {
    const nonExistingRid = 9999;
    await Deno.core.binOpAsync(
      "op_read_async",
      nonExistingRid,
      new Uint8Array(0),
    );
  } catch (e) {
    if (!(e instanceof Deno.errors.BadResource)) {
      throw e;
    }
  }
});

unitTest(function binOpsSyncBadResource(): void {
  try {
    const nonExistingRid = 9999;
    Deno.core.binOpSync("op_read_sync", nonExistingRid, new Uint8Array(0));
  } catch (e) {
    if (!(e instanceof Deno.errors.BadResource)) {
      throw e;
    }
  }
});