summaryrefslogtreecommitdiff
path: root/tests/testdata/test/sanitizer
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-02-16 10:49:42 -0700
committerGitHub <noreply@github.com>2024-02-16 10:49:42 -0700
commitc92717a1a43d31951cd8a1161afb766ef339aa21 (patch)
tree48a8fa58531d525c87824d55a6a934e42037815e /tests/testdata/test/sanitizer
parent88d7c50cd559b9fd0189d2a2c1df6e2f1b790ddb (diff)
chore(cli): pre-factor the sanitizer tests (#22436)
Moving tests around so that we can make #22413 smaller
Diffstat (limited to 'tests/testdata/test/sanitizer')
-rw-r--r--tests/testdata/test/sanitizer/exit_sanitizer.out38
-rw-r--r--tests/testdata/test/sanitizer/exit_sanitizer.ts11
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.out19
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.ts5
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.out45
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts10
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests_no_trace.out25
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_nexttick.out6
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_nexttick.ts11
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_step_leak.out10
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_step_leak.ts10
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.out6
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.ts22
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_unstable.out22
-rw-r--r--tests/testdata/test/sanitizer/ops_sanitizer_unstable.ts10
-rw-r--r--tests/testdata/test/sanitizer/resource_sanitizer.out20
-rw-r--r--tests/testdata/test/sanitizer/resource_sanitizer.ts4
-rw-r--r--tests/testdata/test/sanitizer/trace_ops_caught_error/main.out6
-rw-r--r--tests/testdata/test/sanitizer/trace_ops_caught_error/main.ts13
19 files changed, 293 insertions, 0 deletions
diff --git a/tests/testdata/test/sanitizer/exit_sanitizer.out b/tests/testdata/test/sanitizer/exit_sanitizer.out
new file mode 100644
index 000000000..305d51cc8
--- /dev/null
+++ b/tests/testdata/test/sanitizer/exit_sanitizer.out
@@ -0,0 +1,38 @@
+Check [WILDCARD]/exit_sanitizer.ts
+running 3 tests from [WILDCARD]/exit_sanitizer.ts
+exit(0) ... FAILED ([WILDCARD])
+exit(1) ... FAILED ([WILDCARD])
+exit(2) ... FAILED ([WILDCARD])
+
+ ERRORS
+
+exit(0) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+error: Error: Test case attempted to exit with exit code: 0
+ Deno.exit(0);
+ ^
+ at [WILDCARD]
+ at [WILDCARD]/exit_sanitizer.ts:2:8
+
+exit(1) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+error: Error: Test case attempted to exit with exit code: 1
+ Deno.exit(1);
+ ^
+ at [WILDCARD]
+ at [WILDCARD]/exit_sanitizer.ts:6:8
+
+exit(2) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+error: Error: Test case attempted to exit with exit code: 2
+ Deno.exit(2);
+ ^
+ at [WILDCARD]
+ at [WILDCARD]/exit_sanitizer.ts:10:8
+
+ FAILURES
+
+exit(0) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+exit(1) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+exit(2) => [WILDCARD]/exit_sanitizer.ts:[WILDCARD]
+
+FAILED | 0 passed | 3 failed ([WILDCARD])
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/exit_sanitizer.ts b/tests/testdata/test/sanitizer/exit_sanitizer.ts
new file mode 100644
index 000000000..186406a9d
--- /dev/null
+++ b/tests/testdata/test/sanitizer/exit_sanitizer.ts
@@ -0,0 +1,11 @@
+Deno.test("exit(0)", function () {
+ Deno.exit(0);
+});
+
+Deno.test("exit(1)", function () {
+ Deno.exit(1);
+});
+
+Deno.test("exit(2)", function () {
+ Deno.exit(2);
+});
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.out b/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.out
new file mode 100644
index 000000000..823f4704e
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.out
@@ -0,0 +1,19 @@
+Check [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts
+running 1 test from [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts
+test 1 ... FAILED [WILDCARD]
+
+ ERRORS
+
+test 1 => [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD]
+error: Leaking async ops:
+ - 1 async operation to sleep for a duration was started before this test, but was completed during the test. Async operations should not complete in a test if they were not started in that test. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operation was started here:
+ at [WILDCARD]
+ at [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD]
+
+ FAILURES
+
+test 1 => [WILDCARD]/ops_sanitizer_closed_inside_started_before.ts:[WILDCARD]
+
+FAILED | 0 passed | 1 failed [WILDCARD]
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.ts b/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.ts
new file mode 100644
index 000000000..97d3d72c8
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_closed_inside_started_before.ts
@@ -0,0 +1,5 @@
+const timer = setTimeout(() => {}, 10000000000);
+
+Deno.test("test 1", () => {
+ clearTimeout(timer);
+});
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.out b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.out
new file mode 100644
index 000000000..6af59da90
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.out
@@ -0,0 +1,45 @@
+Check [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts
+running 2 tests from [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts
+test 1 ... FAILED ([WILDCARD])
+test 2 ... FAILED ([WILDCARD])
+
+ ERRORS
+
+test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+error: Leaking async ops:
+ - 2 async operations to sleep for a duration were started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operations were started here:
+ at [WILDCARD]
+ at setTimeout ([WILDCARD])
+ at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD])
+ at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:8:27
+ at [WILDCARD]
+
+ at [WILDCARD]
+ at setTimeout ([WILDCARD])
+ at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD])
+ at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:8:27
+ at [WILDCARD]
+
+test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+error: Leaking async ops:
+ - 2 async operations to sleep for a duration were started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operations were started here:
+ at [WILDCARD]
+ at setTimeout ([WILDCARD])
+ at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD])
+ at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:10:27
+ at [WILDCARD]
+
+ at [WILDCARD]
+ at setTimeout ([WILDCARD])
+ at test ([WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD])
+ at [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:10:27
+ at [WILDCARD]
+
+ FAILURES
+
+test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+
+FAILED | 0 passed | 2 failed ([WILDCARD])
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts
new file mode 100644
index 000000000..1f52d481f
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts
@@ -0,0 +1,10 @@
+// https://github.com/denoland/deno/issues/8965
+
+function test() {
+ setTimeout(() => {}, 10000);
+ setTimeout(() => {}, 10001);
+}
+
+Deno.test("test 1", () => test());
+
+Deno.test("test 2", () => test());
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests_no_trace.out b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests_no_trace.out
new file mode 100644
index 000000000..ae5f68f2f
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_multiple_timeout_tests_no_trace.out
@@ -0,0 +1,25 @@
+Check [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts
+running 2 tests from [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts
+test 1 ... FAILED ([WILDCARD])
+test 2 ... FAILED ([WILDCARD])
+
+ ERRORS
+
+test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+error: Leaking async ops:
+ - 2 async operations to sleep for a duration were started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call.
+To get more details where ops were leaked, run again with --trace-ops flag.
+
+test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+error: Leaking async ops:
+ - 2 async operations to sleep for a duration were started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call.
+To get more details where ops were leaked, run again with --trace-ops flag.
+
+ FAILURES
+
+test 1 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+test 2 => [WILDCARD]/ops_sanitizer_multiple_timeout_tests.ts:[WILDCARD]
+
+FAILED | 0 passed | 2 failed ([WILDCARD])
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.out b/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.out
new file mode 100644
index 000000000..407699b6a
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.out
@@ -0,0 +1,6 @@
+running 2 tests from [WILDCARD]/ops_sanitizer_nexttick.ts
+test 1 ... ok ([WILDCARD])
+test 2 ... ok ([WILDCARD])
+
+ok | 2 passed | 0 failed ([WILDCARD])
+
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.ts b/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.ts
new file mode 100644
index 000000000..9ad3a7b28
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_nexttick.ts
@@ -0,0 +1,11 @@
+import { nextTick } from "node:process";
+
+// https://github.com/denoland/deno_std/issues/1651
+
+Deno.test("test 1", async () => {
+ await new Promise<void>((resolve) => nextTick(resolve));
+});
+
+Deno.test("test 2", async () => {
+ await new Promise<void>((resolve) => nextTick(resolve));
+});
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.out b/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.out
new file mode 100644
index 000000000..be88a6e1d
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.out
@@ -0,0 +1,10 @@
+Check [WILDCARD]/ops_sanitizer_step_leak.ts
+running 1 test from [WILDCARD]/ops_sanitizer_step_leak.ts
+timeout ...
+ step ... ok [WILDCARD]
+------- output -------
+done
+----- output end -----
+timeout ... ok [WILDCARD]
+
+ok | 1 passed (1 step) | 0 failed [WILDCARD] \ No newline at end of file
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.ts b/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.ts
new file mode 100644
index 000000000..3fb9b397e
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_step_leak.ts
@@ -0,0 +1,10 @@
+Deno.test("timeout", async (t) => {
+ const timer = setTimeout(() => {
+ console.log("timeout");
+ }, 10000);
+ clearTimeout(timer);
+ await t.step("step", async () => {
+ await new Promise<void>((resolve) => setTimeout(() => resolve(), 10));
+ });
+ console.log("done");
+});
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.out b/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.out
new file mode 100644
index 000000000..e6e527112
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.out
@@ -0,0 +1,6 @@
+Check [WILDCARD]/ops_sanitizer_timeout_failure.ts
+running 1 test from [WILDCARD]/ops_sanitizer_timeout_failure.ts
+wait ... ok ([WILDCARD])
+
+ok | 1 passed | 0 failed ([WILDCARD])
+
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.ts b/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.ts
new file mode 100644
index 000000000..d40a5a258
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_timeout_failure.ts
@@ -0,0 +1,22 @@
+let intervalHandle: number;
+let firstIntervalPromise: Promise<void>;
+
+addEventListener("load", () => {
+ firstIntervalPromise = new Promise((resolve) => {
+ let firstIntervalCalled = false;
+ intervalHandle = setInterval(() => {
+ if (!firstIntervalCalled) {
+ resolve();
+ firstIntervalCalled = true;
+ }
+ }, 5);
+ });
+});
+
+addEventListener("unload", () => {
+ clearInterval(intervalHandle);
+});
+
+Deno.test("wait", async function () {
+ await firstIntervalPromise;
+});
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_unstable.out b/tests/testdata/test/sanitizer/ops_sanitizer_unstable.out
new file mode 100644
index 000000000..f7c391b7c
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_unstable.out
@@ -0,0 +1,22 @@
+Check [WILDCARD]/ops_sanitizer_unstable.ts
+running 2 tests from [WILDCARD]/ops_sanitizer_unstable.ts
+no-op ... ok ([WILDCARD])
+leak interval ... FAILED ([WILDCARD])
+
+ ERRORS
+
+leak interval => [WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD]
+error: Leaking async ops:
+ - 1 async operation to sleep for a duration was started in this test, but never completed. This is often caused by not cancelling a `setTimeout` or `setInterval` call. The operation was started here:
+ at [WILDCARD]
+ at setInterval ([WILDCARD])
+ at fn ([WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD])
+ at [WILDCARD]
+
+ FAILURES
+
+leak interval => [WILDCARD]/ops_sanitizer_unstable.ts:[WILDCARD]
+
+FAILED | 1 passed | 1 failed ([WILDCARD])
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/ops_sanitizer_unstable.ts b/tests/testdata/test/sanitizer/ops_sanitizer_unstable.ts
new file mode 100644
index 000000000..1deb1d5a7
--- /dev/null
+++ b/tests/testdata/test/sanitizer/ops_sanitizer_unstable.ts
@@ -0,0 +1,10 @@
+Deno.test("no-op", function () {});
+Deno.test({
+ name: "leak interval",
+ // regression test for sanitizer errors being swallowed with permissions.
+ // https://github.com/denoland/deno/pull/18550
+ permissions: {},
+ fn() {
+ setInterval(function () {}, 100000);
+ },
+});
diff --git a/tests/testdata/test/sanitizer/resource_sanitizer.out b/tests/testdata/test/sanitizer/resource_sanitizer.out
new file mode 100644
index 000000000..50f98511c
--- /dev/null
+++ b/tests/testdata/test/sanitizer/resource_sanitizer.out
@@ -0,0 +1,20 @@
+Check [WILDCARD]/resource_sanitizer.ts
+running 1 test from [WILDCARD]/resource_sanitizer.ts
+leak ... FAILED ([WILDCARD])
+
+ ERRORS
+
+leak => [WILDCARD]/resource_sanitizer.ts:[WILDCARD]
+error: Leaking resources:
+[UNORDERED_START]
+ - The stdin pipe was opened before the test started, but was closed during the test. Do not close resources in a test that were not created during that test.
+ - A file was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`.
+[UNORDERED_END]
+
+ FAILURES
+
+leak => [WILDCARD]/resource_sanitizer.ts:[WILDCARD]
+
+FAILED | 0 passed | 1 failed ([WILDCARD])
+
+error: Test failed
diff --git a/tests/testdata/test/sanitizer/resource_sanitizer.ts b/tests/testdata/test/sanitizer/resource_sanitizer.ts
new file mode 100644
index 000000000..93c9222c5
--- /dev/null
+++ b/tests/testdata/test/sanitizer/resource_sanitizer.ts
@@ -0,0 +1,4 @@
+Deno.test("leak", function () {
+ Deno.openSync("run/001_hello.js");
+ Deno.stdin.close();
+});
diff --git a/tests/testdata/test/sanitizer/trace_ops_caught_error/main.out b/tests/testdata/test/sanitizer/trace_ops_caught_error/main.out
new file mode 100644
index 000000000..4e591adf1
--- /dev/null
+++ b/tests/testdata/test/sanitizer/trace_ops_caught_error/main.out
@@ -0,0 +1,6 @@
+Check file:///[WILDCARD]/trace_ops_caught_error/main.ts
+running 1 test from [WILDCARD]/trace_ops_caught_error/main.ts
+handle thrown error in async function ... ok ([WILDCARD])
+
+ok | 1 passed | 0 failed ([WILDCARD])
+
diff --git a/tests/testdata/test/sanitizer/trace_ops_caught_error/main.ts b/tests/testdata/test/sanitizer/trace_ops_caught_error/main.ts
new file mode 100644
index 000000000..043018688
--- /dev/null
+++ b/tests/testdata/test/sanitizer/trace_ops_caught_error/main.ts
@@ -0,0 +1,13 @@
+// https://github.com/denoland/deno/pull/16970
+Deno.test("handle thrown error in async function", async () => {
+ const dirPath = Deno.makeTempDirSync();
+ const filePath = `${dirPath}/file.txt`;
+ try {
+ await Deno.stat(filePath);
+ } catch {
+ await Deno.writeTextFile(filePath, "");
+ } finally {
+ await Deno.remove(filePath);
+ await Deno.remove(dirPath);
+ }
+});