diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-03-11 23:07:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-11 23:07:02 +0100 |
| commit | 09ae512ccb4d8a36a0c6c1a700b48fdd3f9fc6c2 (patch) | |
| tree | 90f5bc5a9d48f5279208eecf985dcf7f777e87c5 /cli/tests/testdata/bench | |
| parent | 32c059544be40987a445f13cc3c7ba585f47889e (diff) | |
feat: "deno bench" subcommand (#13713)
This commit adds "deno bench" subcommand and "Deno.bench()"
API that allows to register bench cases.
The API is modelled after "Deno.test()" and "deno test" subcommand.
Currently the output is rudimentary and bench cases and not
subject to "ops" and "resource" sanitizers.
Co-authored-by: evan <github@evan.lol>
Diffstat (limited to 'cli/tests/testdata/bench')
48 files changed, 615 insertions, 0 deletions
diff --git a/cli/tests/testdata/bench/allow_all.out b/cli/tests/testdata/bench/allow_all.out new file mode 100644 index 000000000..eb7d2005c --- /dev/null +++ b/cli/tests/testdata/bench/allow_all.out @@ -0,0 +1,18 @@ +[WILDCARD] +running 14 benches from [WILDCARD] +bench read false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench read true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench write false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench write true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench net false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench net true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench env false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench env true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench run false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench run true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench ffi false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench ffi true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench hrtime false ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench hrtime true ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] + +bench result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD] diff --git a/cli/tests/testdata/bench/allow_all.ts b/cli/tests/testdata/bench/allow_all.ts new file mode 100644 index 000000000..110e4621f --- /dev/null +++ b/cli/tests/testdata/bench/allow_all.ts @@ -0,0 +1,35 @@ +import { assertEquals } from "../../../../test_util/std/testing/asserts.ts"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", + "hrtime", +]; + +for (const name of permissions) { + Deno.bench({ + name: `${name} false`, + permissions: { + [name]: false, + }, + async fn() { + const status = await Deno.permissions.query({ name }); + assertEquals(status.state, "prompt"); + }, + }); + + Deno.bench({ + name: `${name} true`, + permissions: { + [name]: true, + }, + async fn() { + const status = await Deno.permissions.query({ name }); + assertEquals(status.state, "granted"); + }, + }); +} diff --git a/cli/tests/testdata/bench/allow_none.out b/cli/tests/testdata/bench/allow_none.out new file mode 100644 index 000000000..0eb2ba5a3 --- /dev/null +++ b/cli/tests/testdata/bench/allow_none.out @@ -0,0 +1,51 @@ +[WILDCARD] +running 7 benches from [WILDCARD] +bench read ... 1000 iterations FAILED [WILDCARD] +bench write ... 1000 iterations FAILED [WILDCARD] +bench net ... 1000 iterations FAILED [WILDCARD] +bench env ... 1000 iterations FAILED [WILDCARD] +bench run ... 1000 iterations FAILED [WILDCARD] +bench ffi ... 1000 iterations FAILED [WILDCARD] +bench hrtime ... 1000 iterations FAILED [WILDCARD] + +failures: + +read +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +write +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +net +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +env +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +run +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +ffi +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +hrtime +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +failures: + + read + write + net + env + run + ffi + hrtime + +bench result: FAILED. 0 passed; 7 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD] diff --git a/cli/tests/testdata/bench/allow_none.ts b/cli/tests/testdata/bench/allow_none.ts new file mode 100644 index 000000000..778e98420 --- /dev/null +++ b/cli/tests/testdata/bench/allow_none.ts @@ -0,0 +1,23 @@ +import { unreachable } from "../../../../test_util/std/testing/asserts.ts"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", + "hrtime", +]; + +for (const name of permissions) { + Deno.bench({ + name, + permissions: { + [name]: true, + }, + fn() { + unreachable(); + }, + }); +} diff --git a/cli/tests/testdata/bench/clear_timeout.out b/cli/tests/testdata/bench/clear_timeout.out new file mode 100644 index 000000000..10aa47d75 --- /dev/null +++ b/cli/tests/testdata/bench/clear_timeout.out @@ -0,0 +1,8 @@ +Check [WILDCARD]/bench/clear_timeout.ts +running 3 benches from [WILDCARD]/bench/clear_timeout.ts +bench bench1 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench2 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench3 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +bench result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/clear_timeout.ts b/cli/tests/testdata/bench/clear_timeout.ts new file mode 100644 index 000000000..4148263ac --- /dev/null +++ b/cli/tests/testdata/bench/clear_timeout.ts @@ -0,0 +1,5 @@ +clearTimeout(setTimeout(() => {}, 1000)); + +Deno.bench("bench1", () => {}); +Deno.bench("bench2", () => {}); +Deno.bench("bench3", () => {}); diff --git a/cli/tests/testdata/bench/collect.out b/cli/tests/testdata/bench/collect.out new file mode 100644 index 000000000..570b2e4f2 --- /dev/null +++ b/cli/tests/testdata/bench/collect.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/bench/collect/bench.ts +running 0 benches from [WILDCARD]/bench/collect/bench.ts + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/collect/bench.ts b/cli/tests/testdata/bench/collect/bench.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/bench/collect/bench.ts diff --git a/cli/tests/testdata/bench/collect/ignore/bench.ts b/cli/tests/testdata/bench/collect/ignore/bench.ts new file mode 100644 index 000000000..16fb63ba7 --- /dev/null +++ b/cli/tests/testdata/bench/collect/ignore/bench.ts @@ -0,0 +1 @@ +throw new Error("this module should be ignored"); diff --git a/cli/tests/testdata/bench/exit_sanitizer.out b/cli/tests/testdata/bench/exit_sanitizer.out new file mode 100644 index 000000000..23ce871fc --- /dev/null +++ b/cli/tests/testdata/bench/exit_sanitizer.out @@ -0,0 +1,35 @@ +Check [WILDCARD]/bench/exit_sanitizer.ts +running 3 benches from [WILDCARD]/bench/exit_sanitizer.ts +bench exit(0) ... 1000 iterations FAILED ([WILDCARD]) +bench exit(1) ... 1000 iterations FAILED ([WILDCARD]) +bench exit(2) ... 1000 iterations FAILED ([WILDCARD]) + +failures: + +exit(0) +AssertionError: Bench attempted to exit with exit code: 0 + at [WILDCARD] + at [WILDCARD]/bench/exit_sanitizer.ts:2:8 + at [WILDCARD] + +exit(1) +AssertionError: Bench attempted to exit with exit code: 1 + at [WILDCARD] + at [WILDCARD]/bench/exit_sanitizer.ts:6:8 + at [WILDCARD] + +exit(2) +AssertionError: Bench attempted to exit with exit code: 2 + at [WILDCARD] + at [WILDCARD]/bench/exit_sanitizer.ts:10:8 + at [WILDCARD] + +failures: + + exit(0) + exit(1) + exit(2) + +bench result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Bench failed diff --git a/cli/tests/testdata/bench/exit_sanitizer.ts b/cli/tests/testdata/bench/exit_sanitizer.ts new file mode 100644 index 000000000..8e596b310 --- /dev/null +++ b/cli/tests/testdata/bench/exit_sanitizer.ts @@ -0,0 +1,11 @@ +Deno.bench("exit(0)", function () { + Deno.exit(0); +}); + +Deno.bench("exit(1)", function () { + Deno.exit(1); +}); + +Deno.bench("exit(2)", function () { + Deno.exit(2); +}); diff --git a/cli/tests/testdata/bench/fail.out b/cli/tests/testdata/bench/fail.out new file mode 100644 index 000000000..9779a27fe --- /dev/null +++ b/cli/tests/testdata/bench/fail.out @@ -0,0 +1,81 @@ +Check [WILDCARD]/bench/fail.ts +running 10 benches from [WILDCARD]/bench/fail.ts +bench bench0 ... 1000 iterations FAILED ([WILDCARD]) +bench bench1 ... 1000 iterations FAILED ([WILDCARD]) +bench bench2 ... 1000 iterations FAILED ([WILDCARD]) +bench bench3 ... 1000 iterations FAILED ([WILDCARD]) +bench bench4 ... 1000 iterations FAILED ([WILDCARD]) +bench bench5 ... 1000 iterations FAILED ([WILDCARD]) +bench bench6 ... 1000 iterations FAILED ([WILDCARD]) +bench bench7 ... 1000 iterations FAILED ([WILDCARD]) +bench bench8 ... 1000 iterations FAILED ([WILDCARD]) +bench bench9 ... 1000 iterations FAILED ([WILDCARD]) + +failures: + +bench0 +Error + at [WILDCARD]/bench/fail.ts:2:9 + at [WILDCARD] + +bench1 +Error + at [WILDCARD]/bench/fail.ts:5:9 + at [WILDCARD] + +bench2 +Error + at [WILDCARD]/bench/fail.ts:8:9 + at [WILDCARD] + +bench3 +Error + at [WILDCARD]/bench/fail.ts:11:9 + at [WILDCARD] + +bench4 +Error + at [WILDCARD]/bench/fail.ts:14:9 + at [WILDCARD] + +bench5 +Error + at [WILDCARD]/bench/fail.ts:17:9 + at [WILDCARD] + +bench6 +Error + at [WILDCARD]/bench/fail.ts:20:9 + at [WILDCARD] + +bench7 +Error + at [WILDCARD]/bench/fail.ts:23:9 + at [WILDCARD] + +bench8 +Error + at [WILDCARD]/bench/fail.ts:26:9 + at [WILDCARD] + +bench9 +Error + at [WILDCARD]/bench/fail.ts:29:9 + at [WILDCARD] + +failures: + + bench0 + bench1 + bench2 + bench3 + bench4 + bench5 + bench6 + bench7 + bench8 + bench9 + +bench result: FAILED. 0 passed; 10 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Bench failed diff --git a/cli/tests/testdata/bench/fail.ts b/cli/tests/testdata/bench/fail.ts new file mode 100644 index 000000000..33d70ce55 --- /dev/null +++ b/cli/tests/testdata/bench/fail.ts @@ -0,0 +1,30 @@ +Deno.bench("bench0", () => { + throw new Error(); +}); +Deno.bench("bench1", () => { + throw new Error(); +}); +Deno.bench("bench2", () => { + throw new Error(); +}); +Deno.bench("bench3", () => { + throw new Error(); +}); +Deno.bench("bench4", () => { + throw new Error(); +}); +Deno.bench("bench5", () => { + throw new Error(); +}); +Deno.bench("bench6", () => { + throw new Error(); +}); +Deno.bench("bench7", () => { + throw new Error(); +}); +Deno.bench("bench8", () => { + throw new Error(); +}); +Deno.bench("bench9", () => { + throw new Error(); +}); diff --git a/cli/tests/testdata/bench/filter.out b/cli/tests/testdata/bench/filter.out new file mode 100644 index 000000000..8657e56cc --- /dev/null +++ b/cli/tests/testdata/bench/filter.out @@ -0,0 +1,12 @@ +Check [WILDCARD]/bench/filter/a_bench.ts +Check [WILDCARD]/bench/filter/b_bench.ts +Check [WILDCARD]/bench/filter/c_bench.ts +running 1 bench from [WILDCARD]/bench/filter/a_bench.ts +bench foo ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +running 1 bench from [WILDCARD]/bench/filter/b_bench.ts +bench foo ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +running 1 bench from [WILDCARD]/bench/filter/c_bench.ts +bench foo ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +bench result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 6 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/filter/a_bench.ts b/cli/tests/testdata/bench/filter/a_bench.ts new file mode 100644 index 000000000..fc4ef859c --- /dev/null +++ b/cli/tests/testdata/bench/filter/a_bench.ts @@ -0,0 +1,3 @@ +Deno.bench("foo", function () {}); +Deno.bench("bar", function () {}); +Deno.bench("baz", function () {}); diff --git a/cli/tests/testdata/bench/filter/b_bench.ts b/cli/tests/testdata/bench/filter/b_bench.ts new file mode 100644 index 000000000..fc4ef859c --- /dev/null +++ b/cli/tests/testdata/bench/filter/b_bench.ts @@ -0,0 +1,3 @@ +Deno.bench("foo", function () {}); +Deno.bench("bar", function () {}); +Deno.bench("baz", function () {}); diff --git a/cli/tests/testdata/bench/filter/c_bench.ts b/cli/tests/testdata/bench/filter/c_bench.ts new file mode 100644 index 000000000..fc4ef859c --- /dev/null +++ b/cli/tests/testdata/bench/filter/c_bench.ts @@ -0,0 +1,3 @@ +Deno.bench("foo", function () {}); +Deno.bench("bar", function () {}); +Deno.bench("baz", function () {}); diff --git a/cli/tests/testdata/bench/finally_timeout.out b/cli/tests/testdata/bench/finally_timeout.out new file mode 100644 index 000000000..dfae4607d --- /dev/null +++ b/cli/tests/testdata/bench/finally_timeout.out @@ -0,0 +1,19 @@ +Check [WILDCARD]/bench/finally_timeout.ts +running 2 benches from [WILDCARD]/bench/finally_timeout.ts +bench error ... 1000 iterations FAILED ([WILDCARD]) +bench success ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +failures: + +error +Error: fail + at [WILDCARD]/bench/finally_timeout.ts:4:11 + at [WILDCARD] + +failures: + + error + +bench result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Bench failed diff --git a/cli/tests/testdata/bench/finally_timeout.ts b/cli/tests/testdata/bench/finally_timeout.ts new file mode 100644 index 000000000..c49eb8da2 --- /dev/null +++ b/cli/tests/testdata/bench/finally_timeout.ts @@ -0,0 +1,11 @@ +Deno.bench("error", function () { + const timer = setTimeout(() => null, 10000); + try { + throw new Error("fail"); + } finally { + clearTimeout(timer); + } +}); + +Deno.bench("success", function () { +}); diff --git a/cli/tests/testdata/bench/ignore.out b/cli/tests/testdata/bench/ignore.out new file mode 100644 index 000000000..cda77ea52 --- /dev/null +++ b/cli/tests/testdata/bench/ignore.out @@ -0,0 +1,15 @@ +Check [WILDCARD]/bench/ignore.ts +running 10 benches from [WILDCARD]/bench/ignore.ts +bench bench0 ... 1000 iterations ignored ([WILDCARD]) +bench bench1 ... 1000 iterations ignored ([WILDCARD]) +bench bench2 ... 1000 iterations ignored ([WILDCARD]) +bench bench3 ... 1000 iterations ignored ([WILDCARD]) +bench bench4 ... 1000 iterations ignored ([WILDCARD]) +bench bench5 ... 1000 iterations ignored ([WILDCARD]) +bench bench6 ... 1000 iterations ignored ([WILDCARD]) +bench bench7 ... 1000 iterations ignored ([WILDCARD]) +bench bench8 ... 1000 iterations ignored ([WILDCARD]) +bench bench9 ... 1000 iterations ignored ([WILDCARD]) + +bench result: ok. 0 passed; 0 failed; 10 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/ignore.ts b/cli/tests/testdata/bench/ignore.ts new file mode 100644 index 000000000..0226fe76f --- /dev/null +++ b/cli/tests/testdata/bench/ignore.ts @@ -0,0 +1,9 @@ +for (let i = 0; i < 10; i++) { + Deno.bench({ + name: `bench${i}`, + ignore: true, + fn() { + throw new Error("unreachable"); + }, + }); +} diff --git a/cli/tests/testdata/bench/ignore_permissions.out b/cli/tests/testdata/bench/ignore_permissions.out new file mode 100644 index 000000000..c55ccaa21 --- /dev/null +++ b/cli/tests/testdata/bench/ignore_permissions.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/bench/ignore_permissions.ts +running 1 bench from [WILDCARD]/bench/ignore_permissions.ts +bench ignore ... 1000 iterations ignored ([WILDCARD]) + +bench result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/ignore_permissions.ts b/cli/tests/testdata/bench/ignore_permissions.ts new file mode 100644 index 000000000..0dcd9299f --- /dev/null +++ b/cli/tests/testdata/bench/ignore_permissions.ts @@ -0,0 +1,16 @@ +Deno.bench({ + name: "ignore", + permissions: { + read: true, + write: true, + net: true, + env: true, + run: true, + ffi: true, + hrtime: true, + }, + ignore: true, + fn() { + throw new Error("unreachable"); + }, +}); diff --git a/cli/tests/testdata/bench/interval.out b/cli/tests/testdata/bench/interval.out new file mode 100644 index 000000000..dec5549ef --- /dev/null +++ b/cli/tests/testdata/bench/interval.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/bench/interval.ts +running 0 benches from [WILDCARD]/bench/interval.ts + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/interval.ts b/cli/tests/testdata/bench/interval.ts new file mode 100644 index 000000000..7eb588c59 --- /dev/null +++ b/cli/tests/testdata/bench/interval.ts @@ -0,0 +1 @@ +setInterval(function () {}, 0); diff --git a/cli/tests/testdata/bench/load_unload.out b/cli/tests/testdata/bench/load_unload.out new file mode 100644 index 000000000..9b73341d4 --- /dev/null +++ b/cli/tests/testdata/bench/load_unload.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/bench/load_unload.ts +running 1 bench from [WILDCARD]/bench/load_unload.ts +bench bench ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +bench result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/load_unload.ts b/cli/tests/testdata/bench/load_unload.ts new file mode 100644 index 000000000..3653c135d --- /dev/null +++ b/cli/tests/testdata/bench/load_unload.ts @@ -0,0 +1,22 @@ +let interval: number | null = null; +addEventListener("load", () => { + if (interval) { + throw new Error("Interval is already set"); + } + + interval = setInterval(() => {}, 0); +}); + +addEventListener("unload", () => { + if (!interval) { + throw new Error("Interval was not set"); + } + + clearInterval(interval); +}); + +Deno.bench("bench", () => { + if (!interval) { + throw new Error("Interval was not set"); + } +}); diff --git a/cli/tests/testdata/bench/meta.out b/cli/tests/testdata/bench/meta.out new file mode 100644 index 000000000..e62172eb3 --- /dev/null +++ b/cli/tests/testdata/bench/meta.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/bench/meta.ts +import.meta.main: false +import.meta.url: [WILDCARD]/bench/meta.ts +running 0 benches from [WILDCARD]/bench/meta.ts + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/meta.ts b/cli/tests/testdata/bench/meta.ts new file mode 100644 index 000000000..e32fdeea6 --- /dev/null +++ b/cli/tests/testdata/bench/meta.ts @@ -0,0 +1,2 @@ +console.log("import.meta.main: %s", import.meta.main); +console.log("import.meta.url: %s", import.meta.url); diff --git a/cli/tests/testdata/bench/no_check.out b/cli/tests/testdata/bench/no_check.out new file mode 100644 index 000000000..ceb8b22fc --- /dev/null +++ b/cli/tests/testdata/bench/no_check.out @@ -0,0 +1,8 @@ + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Uncaught TypeError: Cannot read properties of undefined (reading 'fn') +Deno.bench(); + ^ + at [WILDCARD] + at [WILDCARD]/bench/no_check.ts:1:6 diff --git a/cli/tests/testdata/bench/no_check.ts b/cli/tests/testdata/bench/no_check.ts new file mode 100644 index 000000000..b159cabd6 --- /dev/null +++ b/cli/tests/testdata/bench/no_check.ts @@ -0,0 +1 @@ +Deno.bench(); diff --git a/cli/tests/testdata/bench/no_color.ts b/cli/tests/testdata/bench/no_color.ts new file mode 100644 index 000000000..d15bf3572 --- /dev/null +++ b/cli/tests/testdata/bench/no_color.ts @@ -0,0 +1,17 @@ +Deno.bench({ + name: "success", + fn() {}, +}); + +Deno.bench({ + name: "fail", + fn() { + throw new Error("fail"); + }, +}); + +Deno.bench({ + name: "ignored", + ignore: true, + fn() {}, +}); diff --git a/cli/tests/testdata/bench/no_prompt_by_default.out b/cli/tests/testdata/bench/no_prompt_by_default.out new file mode 100644 index 000000000..3fe67b720 --- /dev/null +++ b/cli/tests/testdata/bench/no_prompt_by_default.out @@ -0,0 +1,17 @@ +Check [WILDCARD]no_prompt_by_default.ts +running 1 bench from [WILDCARD]no_prompt_by_default.ts +bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms) + +failures: + +no prompt +PermissionDenied: Requires read access to "./some_file.txt", run again with the --allow-read flag +[WILDCARD] + +failures: + + no prompt + +bench result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]ms) + +error: Bench failed diff --git a/cli/tests/testdata/bench/no_prompt_by_default.ts b/cli/tests/testdata/bench/no_prompt_by_default.ts new file mode 100644 index 000000000..59359eebd --- /dev/null +++ b/cli/tests/testdata/bench/no_prompt_by_default.ts @@ -0,0 +1,3 @@ +Deno.bench("no prompt", async () => { + await Deno.readTextFile("./some_file.txt"); +}); diff --git a/cli/tests/testdata/bench/no_prompt_with_denied_perms.out b/cli/tests/testdata/bench/no_prompt_with_denied_perms.out new file mode 100644 index 000000000..f6aec6226 --- /dev/null +++ b/cli/tests/testdata/bench/no_prompt_with_denied_perms.out @@ -0,0 +1,17 @@ +Check [WILDCARD]/no_prompt_with_denied_perms.ts +running 1 bench from [WILDCARD]/no_prompt_with_denied_perms.ts +bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms) + +failures: + +no prompt +PermissionDenied: Requires read access to "./some_file.txt", run again with the --allow-read flag +[WILDCARD] + +failures: + + no prompt + +bench result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]ms) + +error: Bench failed diff --git a/cli/tests/testdata/bench/no_prompt_with_denied_perms.ts b/cli/tests/testdata/bench/no_prompt_with_denied_perms.ts new file mode 100644 index 000000000..2f0d63bbe --- /dev/null +++ b/cli/tests/testdata/bench/no_prompt_with_denied_perms.ts @@ -0,0 +1,3 @@ +Deno.bench("no prompt", { permissions: { read: false } }, async () => { + await Deno.readTextFile("./some_file.txt"); +}); diff --git a/cli/tests/testdata/bench/only.out b/cli/tests/testdata/bench/only.out new file mode 100644 index 000000000..3c9855560 --- /dev/null +++ b/cli/tests/testdata/bench/only.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/bench/only.ts +running 1 bench from [WILDCARD]/bench/only.ts +bench only ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +bench result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out ([WILDCARD]) + +error: Bench failed because the "only" option was used diff --git a/cli/tests/testdata/bench/only.ts b/cli/tests/testdata/bench/only.ts new file mode 100644 index 000000000..0129c024c --- /dev/null +++ b/cli/tests/testdata/bench/only.ts @@ -0,0 +1,15 @@ +Deno.bench({ + name: "before", + fn() {}, +}); + +Deno.bench({ + only: true, + name: "only", + fn() {}, +}); + +Deno.bench({ + name: "after", + fn() {}, +}); diff --git a/cli/tests/testdata/bench/overloads.out b/cli/tests/testdata/bench/overloads.out new file mode 100644 index 000000000..a736b2e98 --- /dev/null +++ b/cli/tests/testdata/bench/overloads.out @@ -0,0 +1,11 @@ +Check [WILDCARD]/bench/overloads.ts +running 6 benches from [WILDCARD]/bench/overloads.ts +bench bench0 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench1 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench2 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench3 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench4 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench5 ... 1000 iterations ignored ([WILDCARD]) + +bench result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/overloads.ts b/cli/tests/testdata/bench/overloads.ts new file mode 100644 index 000000000..4f5887f79 --- /dev/null +++ b/cli/tests/testdata/bench/overloads.ts @@ -0,0 +1,6 @@ +Deno.bench("bench0", () => {}); +Deno.bench(function bench1() {}); +Deno.bench({ name: "bench2", fn: () => {} }); +Deno.bench("bench3", { permissions: "none" }, () => {}); +Deno.bench({ name: "bench4" }, () => {}); +Deno.bench({ ignore: true }, function bench5() {}); diff --git a/cli/tests/testdata/bench/pass.out b/cli/tests/testdata/bench/pass.out new file mode 100644 index 000000000..99320e666 --- /dev/null +++ b/cli/tests/testdata/bench/pass.out @@ -0,0 +1,15 @@ +Check [WILDCARD]/bench/pass.ts +running 10 benches from [WILDCARD]/bench/pass.ts +bench bench0 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench1 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench2 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench3 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench4 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench5 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench6 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench7 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench8 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) +bench bench9 ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok ([WILDCARD]) + +bench result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/pass.ts b/cli/tests/testdata/bench/pass.ts new file mode 100644 index 000000000..48348d447 --- /dev/null +++ b/cli/tests/testdata/bench/pass.ts @@ -0,0 +1,10 @@ +Deno.bench("bench0", () => {}); +Deno.bench("bench1", () => {}); +Deno.bench("bench2", () => {}); +Deno.bench("bench3", () => {}); +Deno.bench("bench4", () => {}); +Deno.bench("bench5", () => {}); +Deno.bench("bench6", () => {}); +Deno.bench("bench7", () => {}); +Deno.bench("bench8", () => {}); +Deno.bench("bench9", () => {}); diff --git a/cli/tests/testdata/bench/quiet.out b/cli/tests/testdata/bench/quiet.out new file mode 100644 index 000000000..e214980e6 --- /dev/null +++ b/cli/tests/testdata/bench/quiet.out @@ -0,0 +1,8 @@ +running 4 benches from [WILDCARD]/bench/quiet.ts +bench console.log ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench console.error ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench console.info ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] +bench console.warn ... 1000 iterations [WILDCARD] ns/iter ([WILDCARD]..[WILDCARD] ns/iter) ok [WILDCARD] + +bench result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/bench/quiet.ts b/cli/tests/testdata/bench/quiet.ts new file mode 100644 index 000000000..efeb366ff --- /dev/null +++ b/cli/tests/testdata/bench/quiet.ts @@ -0,0 +1,15 @@ +Deno.bench("console.log", function () { + console.log("log"); +}); + +Deno.bench("console.error", function () { + console.error("error"); +}); + +Deno.bench("console.info", function () { + console.info("info"); +}); + +Deno.bench("console.warn", function () { + console.info("warn"); +}); diff --git a/cli/tests/testdata/bench/unhandled_rejection.out b/cli/tests/testdata/bench/unhandled_rejection.out new file mode 100644 index 000000000..0e2b03c3e --- /dev/null +++ b/cli/tests/testdata/bench/unhandled_rejection.out @@ -0,0 +1,10 @@ +Check [WILDCARD]/bench/unhandled_rejection.ts + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Uncaught (in promise) Error: rejection + reject(new Error("rejection")); + ^ + at [WILDCARD]/bench/unhandled_rejection.ts:2:10 + at new Promise (<anonymous>) + at [WILDCARD]/bench/unhandled_rejection.ts:1:1 diff --git a/cli/tests/testdata/bench/unhandled_rejection.ts b/cli/tests/testdata/bench/unhandled_rejection.ts new file mode 100644 index 000000000..32f3111ea --- /dev/null +++ b/cli/tests/testdata/bench/unhandled_rejection.ts @@ -0,0 +1,3 @@ +new Promise((_resolve, reject) => { + reject(new Error("rejection")); +}); diff --git a/cli/tests/testdata/bench/unresolved_promise.out b/cli/tests/testdata/bench/unresolved_promise.out new file mode 100644 index 000000000..b3c3d65f9 --- /dev/null +++ b/cli/tests/testdata/bench/unresolved_promise.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/bench/unresolved_promise.ts + +bench result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promises. diff --git a/cli/tests/testdata/bench/unresolved_promise.ts b/cli/tests/testdata/bench/unresolved_promise.ts new file mode 100644 index 000000000..25fe70762 --- /dev/null +++ b/cli/tests/testdata/bench/unresolved_promise.ts @@ -0,0 +1 @@ +await new Promise((_resolve, _reject) => {}); |
