From b53997273d1bc3ece8eaecfe32b10fd8102290b1 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 25 Jan 2022 17:03:38 +0100 Subject: 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. --- cli/tests/integration/test_tests.rs | 6 ++++++ cli/tests/testdata/test/resource_sanitizer.out | 21 +++++++++++++++++++++ cli/tests/testdata/test/resource_sanitizer.ts | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 cli/tests/testdata/test/resource_sanitizer.out create mode 100644 cli/tests/testdata/test/resource_sanitizer.ts (limited to 'cli/tests') 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(); +}); -- cgit v1.2.3