summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-24 20:55:50 +0800
committerGitHub <noreply@github.com>2021-02-24 13:55:50 +0100
commit9cc7e32e37e6708980abc051f2cb71526c175d88 (patch)
tree42728035073e98745ebd022c6788ba4d4ba520fd /cli/tests
parentdc3683c7a433bf44656063c9eee87709fbe1e7d4 (diff)
feat: add exit sanitizer to Deno.test (#9529)
This adds an exit sanitizer to ensure that code being tested or dependencies of that code can't accidentally call "Deno.exit" leading to partial test runs and false results.
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/exit_sanitizer_test.out28
-rw-r--r--cli/tests/exit_sanitizer_test.ts11
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tests/test_finally_cleartimeout.out8
4 files changed, 46 insertions, 7 deletions
diff --git a/cli/tests/exit_sanitizer_test.out b/cli/tests/exit_sanitizer_test.out
new file mode 100644
index 000000000..351453928
--- /dev/null
+++ b/cli/tests/exit_sanitizer_test.out
@@ -0,0 +1,28 @@
+Check [WILDCARD]/$deno$test.ts
+running 3 tests
+test exit(0) ... FAILED ([WILDCARD])
+test exit(1) ... FAILED ([WILDCARD])
+test exit(2) ... FAILED ([WILDCARD])
+
+failures:
+
+exit(0)
+AssertionError: Test case attempted to exit with exit code: 0
+ [WILDCARD]
+
+exit(1)
+AssertionError: Test case attempted to exit with exit code: 1
+ [WILDCARD]
+
+exit(2)
+AssertionError: Test case attempted to exit with exit code: 2
+ [WILDCARD]
+
+failures:
+
+ exit(0)
+ exit(1)
+ exit(2)
+
+test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
+
diff --git a/cli/tests/exit_sanitizer_test.ts b/cli/tests/exit_sanitizer_test.ts
new file mode 100644
index 000000000..186406a9d
--- /dev/null
+++ b/cli/tests/exit_sanitizer_test.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/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index d47c8d1e9..78cecf2fb 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2252,6 +2252,12 @@ mod integration {
assert!(out.contains("test result: FAILED. 1 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out"));
}
+ itest!(test_exit_sanitizer {
+ args: "test exit_sanitizer_test.ts",
+ output: "exit_sanitizer_test.out",
+ exit_code: 1,
+ });
+
itest!(stdout_write_all {
args: "run --quiet stdout_write_all.ts",
output: "stdout_write_all.out",
diff --git a/cli/tests/test_finally_cleartimeout.out b/cli/tests/test_finally_cleartimeout.out
index c8f412bf0..c88b8242b 100644
--- a/cli/tests/test_finally_cleartimeout.out
+++ b/cli/tests/test_finally_cleartimeout.out
@@ -7,13 +7,7 @@ failures:
error
Error: fail
- at [WILDCARD]/test_finally_cleartimeout.ts:4:11
- at asyncOpSanitizer (deno:runtime/js/40_testing.js:38:15)
- at Object.resourceSanitizer [as fn] (deno:runtime/js/40_testing.js:74:13)
- at TestRunner.[Symbol.asyncIterator] (deno:runtime/js/40_testing.js:249:24)
- at AsyncGenerator.next (<anonymous>)
- at Object.runTests (deno:runtime/js/40_testing.js:326:22)
- at async [WILDCARD]/$deno$test.ts:3:1
+ [WILDCARD]
failures: