diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-06-25 06:57:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 00:57:08 +0200 |
commit | 87f8f99c49e62c06f85bb453a7c12b32634c3bef (patch) | |
tree | e8f966f981a9f825ca1f22fe8d39642c448a9c62 /cli/tests/unit/process_test.ts | |
parent | 6bbe52fba33e440e113bca423b5eae0d1f320c49 (diff) |
refactor(cli/tests/unit) to use assertThrows (#6459)
Diffstat (limited to 'cli/tests/unit/process_test.ts')
-rw-r--r-- | cli/tests/unit/process_test.ts | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index cf512eea5..f2e6e01e7 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -3,18 +3,14 @@ import { assert, assertEquals, assertStringContains, + assertThrows, unitTest, } from "./test_util.ts"; unitTest(function runPermissions(): void { - let caughtError = false; - try { + assertThrows(() => { Deno.run({ cmd: ["python", "-c", "print('hello world')"] }); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> { @@ -325,18 +321,13 @@ unitTest(function signalNumbers(): void { }); unitTest(function killPermissions(): void { - let caughtError = false; - try { + assertThrows(() => { // Unlike the other test cases, we don't have permission to spawn a // subprocess we can safely kill. Instead we send SIGCONT to the current // process - assuming that Deno does not have a special handler set for it // and will just continue even if a signal is erroneously sent. Deno.kill(Deno.pid, Deno.Signal.SIGCONT); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> { @@ -368,14 +359,9 @@ unitTest({ perms: { run: true } }, function killFailed(): void { assert(!p.stdin); assert(!p.stdout); - let err; - try { + assertThrows(() => { Deno.kill(p.pid, 12345); - } catch (e) { - err = e; - } - assert(!!err); - assert(err instanceof TypeError); + }, TypeError); p.close(); }); |