diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-03-04 17:31:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 17:31:14 +0100 |
commit | 8d96dffa410a149d0fff6115bd97f41fc1fe7459 (patch) | |
tree | b00dc7a78e5030b68741de8bf9dde83b9fa07364 /cli/js/os_test.ts | |
parent | 30682cf74fa039d3493c74101dca2dbb3a8d49b6 (diff) |
refactor: rewrite testPerm into unitTest (#4231)
Rewrite "testPerm" helper function used for testing of internal
runtime code. It's been renamed to "unitTest" and provides API that
is extensible in the future by accepting optional "UnitTestOptions"
argument. "test" helper was also removed and replaced by
overloaded version of "unitTest" that takes only function argument.
"UnitTestOptions" currently supports "perms" and "skip"
options, where former works exactly as first argument to "testPerm"
did, while the latter allows to conditionally skip tests.
Diffstat (limited to 'cli/js/os_test.ts')
-rw-r--r-- | cli/js/os_test.ts | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts index 35b9f126a..0c851be51 100644 --- a/cli/js/os_test.ts +++ b/cli/js/os_test.ts @@ -1,14 +1,13 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { - test, - testPerm, assert, assertEquals, assertNotEquals, - assertThrows + assertThrows, + unitTest } from "./test_util.ts"; -testPerm({ env: true }, function envSuccess(): void { +unitTest({ perms: { env: true } }, function envSuccess(): void { const env = Deno.env(); assert(env !== null); // eslint-disable-next-line @typescript-eslint/camelcase @@ -18,12 +17,12 @@ testPerm({ env: true }, function envSuccess(): void { assertEquals(Deno.env("test_var"), env.test_var); }); -testPerm({ env: true }, function envNotFound(): void { +unitTest({ perms: { env: true } }, function envNotFound(): void { const r = Deno.env("env_var_does_not_exist!"); assertEquals(r, undefined); }); -test(function envPermissionDenied1(): void { +unitTest(function envPermissionDenied1(): void { let err; try { Deno.env(); @@ -35,7 +34,7 @@ test(function envPermissionDenied1(): void { assertEquals(err.name, "PermissionDenied"); }); -test(function envPermissionDenied2(): void { +unitTest(function envPermissionDenied2(): void { let err; try { Deno.env("PATH"); @@ -47,11 +46,12 @@ test(function envPermissionDenied2(): void { assertEquals(err.name, "PermissionDenied"); }); -if (Deno.build.os === "win") { - // This test verifies that on Windows, environment variables are - // case-insensitive. Case normalization needs be done using the collation - // that Windows uses, rather than naively using String.toLowerCase(). - testPerm({ env: true, run: true }, async function envCaseInsensitive() { +// This test verifies that on Windows, environment variables are +// case-insensitive. Case normalization needs be done using the collation +// that Windows uses, rather than naively using String.toLowerCase(). +unitTest( + { skip: Deno.build.os !== "win", perms: { env: true, run: true } }, + async function envCaseInsensitive() { // Utility function that runs a Deno subprocess with the environment // specified in `inputEnv`. The subprocess reads the environment variables // which are in the keys of `expectedEnv` and writes them to stdout as JSON. @@ -61,9 +61,9 @@ if (Deno.build.os === "win") { expectedEnv: Record<string, string> ): Promise<void> => { const src = ` - console.log( - ${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k)) - )`; + console.log( + ${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k)) + )`; const proc = Deno.run({ args: [Deno.execPath(), "eval", src], env: inputEnv, @@ -108,14 +108,14 @@ if (Deno.build.os === "win") { { [c2]: "Dz", [uc2]: "DZ" }, { [c2]: "Dz", [uc2]: "DZ", [lc2]: "DZ" } ); - }); -} + } +); -test(function osPid(): void { +unitTest(function osPid(): void { assert(Deno.pid > 0); }); -testPerm({ env: true }, function getDir(): void { +unitTest({ perms: { env: true } }, function getDir(): void { type supportOS = "mac" | "win" | "linux"; interface Runtime { @@ -263,7 +263,7 @@ testPerm({ env: true }, function getDir(): void { } }); -testPerm({}, function getDirWithoutPermission(): void { +unitTest(function getDirWithoutPermission(): void { assertThrows( () => Deno.dir("home"), Deno.errors.PermissionDenied, @@ -271,11 +271,11 @@ testPerm({}, function getDirWithoutPermission(): void { ); }); -testPerm({ env: true }, function execPath(): void { +unitTest({ perms: { env: true } }, function execPath(): void { assertNotEquals(Deno.execPath(), ""); }); -testPerm({ env: false }, function execPathPerm(): void { +unitTest({ perms: { env: false } }, function execPathPerm(): void { let caughtError = false; try { Deno.execPath(); @@ -287,12 +287,12 @@ testPerm({ env: false }, function execPathPerm(): void { assert(caughtError); }); -testPerm({ env: true }, function loadavgSuccess(): void { +unitTest({ perms: { env: true } }, function loadavgSuccess(): void { const load = Deno.loadavg(); assertEquals(load.length, 3); }); -testPerm({ env: false }, function loadavgPerm(): void { +unitTest({ perms: { env: false } }, function loadavgPerm(): void { let caughtError = false; try { Deno.loadavg(); @@ -304,11 +304,11 @@ testPerm({ env: false }, function loadavgPerm(): void { assert(caughtError); }); -testPerm({ env: true }, function hostnameDir(): void { +unitTest({ perms: { env: true } }, function hostnameDir(): void { assertNotEquals(Deno.hostname(), ""); }); -testPerm({ env: false }, function hostnamePerm(): void { +unitTest({ perms: { env: false } }, function hostnamePerm(): void { let caughtError = false; try { Deno.hostname(); @@ -320,11 +320,11 @@ testPerm({ env: false }, function hostnamePerm(): void { assert(caughtError); }); -testPerm({ env: true }, function releaseDir(): void { +unitTest({ perms: { env: true } }, function releaseDir(): void { assertNotEquals(Deno.osRelease(), ""); }); -testPerm({ env: false }, function releasePerm(): void { +unitTest({ perms: { env: false } }, function releasePerm(): void { let caughtError = false; try { Deno.osRelease(); |