diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-06-03 10:29:01 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-02 21:29:01 -0400 |
commit | eda43c46de12ed589fdbe62ba0574887cfbb3574 (patch) | |
tree | 9703b6c92b2e3ca21768d9ae6d82730c41e41157 /cli/tests | |
parent | 754f21f0cd6b788ded48238c5acc3f635329d473 (diff) |
fix: validate integer values in `Deno.exitCode` setter (#24068)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/os_test.ts | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/cli/tests/unit/os_test.ts b/cli/tests/unit/os_test.ts deleted file mode 100644 index af6ef219a..000000000 --- a/cli/tests/unit/os_test.ts +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -import { assertEquals, assertThrows } from "../../testing/asserts.ts"; - -Deno.test("Deno.exitCode getter and setter", () => { - // Initial value is 0 - assertEquals(Deno.exitCode, 0); - - // Set a new value - Deno.exitCode = 5; - assertEquals(Deno.exitCode, 5); - - // Reset to initial value - Deno.exitCode = 0; - assertEquals(Deno.exitCode, 0); -}); - -Deno.test("Setting Deno.exitCode to NaN throws TypeError", () => { - // @ts-expect-error; - Deno.exitCode = "123"; - assertEquals(Deno.exitCode, 123); - - // Reset - Deno.exitCode = 0; - assertEquals(Deno.exitCode, 0); - - // Throws on non-number values - assertThrows( - () => { - // @ts-expect-error Testing for runtime error - Deno.exitCode = "not a number"; - }, - TypeError, - "Exit code must be a number.", - ); -}); - -Deno.test("Setting Deno.exitCode does not cause an immediate exit", () => { - let exited = false; - const originalExit = Deno.exit; - - // @ts-expect-error; read-only - Deno.exit = () => { - exited = true; - }; - - Deno.exitCode = 1; - assertEquals(exited, false); - - // @ts-expect-error; read-only - Deno.exit = originalExit; -}); - -Deno.test("Running Deno.exit(value) overrides Deno.exitCode", () => { - let args: unknown[] | undefined; - - const originalExit = Deno.exit; - // @ts-expect-error; read-only - Deno.exit = (...x) => { - args = x; - }; - - Deno.exitCode = 42; - Deno.exit(0); - - assertEquals(args, [0]); - // @ts-expect-error; read-only - Deno.exit = originalExit; -}); - -Deno.test("Running Deno.exit() uses Deno.exitCode as fallback", () => { - let args: unknown[] | undefined; - - const originalExit = Deno.exit; - // @ts-expect-error; read-only - Deno.exit = (...x) => { - args = x; - }; - - Deno.exitCode = 42; - Deno.exit(); - - assertEquals(args, [42]); - // @ts-expect-error; read-only - Deno.exit = originalExit; -}); - -Deno.test("Retrieving the set exit code before process termination", () => { - Deno.exitCode = 42; - assertEquals(Deno.exitCode, 42); - - // Reset to initial value - Deno.exitCode = 0; -}); |