summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-01-25 17:03:38 +0100
committerGitHub <noreply@github.com>2022-01-25 17:03:38 +0100
commitb53997273d1bc3ece8eaecfe32b10fd8102290b1 (patch)
treeb097e3246de655e2ff3ad4042acca3ba8903e9b4 /cli/tests
parentd4dd9ae4cfbcf83da952bf1ed99198c073f3e6d1 (diff)
feat(test): better errors for resource sanitizer (#13296)
This commit makes the errors produced from the resource sanitizer much more human readable. It does this by using real words rather than our "resource names" when referring to resources, and by giving helpful hints on how to clean up each of the resources.
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/test_tests.rs6
-rw-r--r--cli/tests/testdata/test/resource_sanitizer.out21
-rw-r--r--cli/tests/testdata/test/resource_sanitizer.ts4
3 files changed, 31 insertions, 0 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 53dbb07d3..0697fc69c 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -167,6 +167,12 @@ itest!(ops_sanitizer_nexttick {
output: "test/ops_sanitizer_nexttick.out",
});
+itest!(resource_sanitizer {
+ args: "test --allow-read test/resource_sanitizer.ts",
+ exit_code: 1,
+ output: "test/resource_sanitizer.out",
+});
+
itest!(exit_sanitizer {
args: "test test/exit_sanitizer.ts",
output: "test/exit_sanitizer.out",
diff --git a/cli/tests/testdata/test/resource_sanitizer.out b/cli/tests/testdata/test/resource_sanitizer.out
new file mode 100644
index 000000000..632b75292
--- /dev/null
+++ b/cli/tests/testdata/test/resource_sanitizer.out
@@ -0,0 +1,21 @@
+Check [WILDCARD]/test/resource_sanitizer.ts
+running 1 test from [WILDCARD]/test/resource_sanitizer.ts
+test leak ... FAILED ([WILDCARD])
+
+failures:
+
+leak
+AssertionError: Test case is leaking 2 resources:
+
+ - The stdin pipe (rid 0) 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 (rid 3) was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`.
+
+ at [WILDCARD]
+
+failures:
+
+ leak
+
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
+
+error: Test failed
diff --git a/cli/tests/testdata/test/resource_sanitizer.ts b/cli/tests/testdata/test/resource_sanitizer.ts
new file mode 100644
index 000000000..c1291b89a
--- /dev/null
+++ b/cli/tests/testdata/test/resource_sanitizer.ts
@@ -0,0 +1,4 @@
+Deno.test("leak", function () {
+ Deno.openSync("001_hello.js");
+ Deno.stdin.close();
+});