diff options
Diffstat (limited to 'cli/js/rename_test.ts')
-rw-r--r-- | cli/js/rename_test.ts | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/cli/js/rename_test.ts b/cli/js/rename_test.ts index 504a351ee..288f24bd7 100644 --- a/cli/js/rename_test.ts +++ b/cli/js/rename_test.ts @@ -1,74 +1,84 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { testPerm, assert, assertEquals } from "./test_util.ts"; +import { unitTest, assert, assertEquals } from "./test_util.ts"; -testPerm({ read: true, write: true }, function renameSyncSuccess(): void { - const testDir = Deno.makeTempDirSync(); - const oldpath = testDir + "/oldpath"; - const newpath = testDir + "/newpath"; - Deno.mkdirSync(oldpath); - Deno.renameSync(oldpath, newpath); - const newPathInfo = Deno.statSync(newpath); - assert(newPathInfo.isDirectory()); +unitTest( + { perms: { read: true, write: true } }, + function renameSyncSuccess(): void { + const testDir = Deno.makeTempDirSync(); + const oldpath = testDir + "/oldpath"; + const newpath = testDir + "/newpath"; + Deno.mkdirSync(oldpath); + Deno.renameSync(oldpath, newpath); + const newPathInfo = Deno.statSync(newpath); + assert(newPathInfo.isDirectory()); - let caughtErr = false; - let oldPathInfo; + let caughtErr = false; + let oldPathInfo; - try { - oldPathInfo = Deno.statSync(oldpath); - } catch (e) { - caughtErr = true; - assert(e instanceof Deno.errors.NotFound); + try { + oldPathInfo = Deno.statSync(oldpath); + } catch (e) { + caughtErr = true; + assert(e instanceof Deno.errors.NotFound); + } + assert(caughtErr); + assertEquals(oldPathInfo, undefined); } - assert(caughtErr); - assertEquals(oldPathInfo, undefined); -}); +); -testPerm({ read: false, write: true }, function renameSyncReadPerm(): void { - let err; - try { - const oldpath = "/oldbaddir"; - const newpath = "/newbaddir"; - Deno.renameSync(oldpath, newpath); - } catch (e) { - err = e; +unitTest( + { perms: { read: false, write: true } }, + function renameSyncReadPerm(): void { + let err; + try { + const oldpath = "/oldbaddir"; + const newpath = "/newbaddir"; + Deno.renameSync(oldpath, newpath); + } catch (e) { + err = e; + } + assert(err instanceof Deno.errors.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); } - assert(err instanceof Deno.errors.PermissionDenied); - assertEquals(err.name, "PermissionDenied"); -}); +); -testPerm({ read: true, write: false }, function renameSyncWritePerm(): void { - let err; - try { - const oldpath = "/oldbaddir"; - const newpath = "/newbaddir"; - Deno.renameSync(oldpath, newpath); - } catch (e) { - err = e; +unitTest( + { perms: { read: true, write: false } }, + function renameSyncWritePerm(): void { + let err; + try { + const oldpath = "/oldbaddir"; + const newpath = "/newbaddir"; + Deno.renameSync(oldpath, newpath); + } catch (e) { + err = e; + } + assert(err instanceof Deno.errors.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); } - assert(err instanceof Deno.errors.PermissionDenied); - assertEquals(err.name, "PermissionDenied"); -}); +); -testPerm({ read: true, write: true }, async function renameSuccess(): Promise< - void -> { - const testDir = Deno.makeTempDirSync(); - const oldpath = testDir + "/oldpath"; - const newpath = testDir + "/newpath"; - Deno.mkdirSync(oldpath); - await Deno.rename(oldpath, newpath); - const newPathInfo = Deno.statSync(newpath); - assert(newPathInfo.isDirectory()); +unitTest( + { perms: { read: true, write: true } }, + async function renameSuccess(): Promise<void> { + const testDir = Deno.makeTempDirSync(); + const oldpath = testDir + "/oldpath"; + const newpath = testDir + "/newpath"; + Deno.mkdirSync(oldpath); + await Deno.rename(oldpath, newpath); + const newPathInfo = Deno.statSync(newpath); + assert(newPathInfo.isDirectory()); - let caughtErr = false; - let oldPathInfo; + let caughtErr = false; + let oldPathInfo; - try { - oldPathInfo = Deno.statSync(oldpath); - } catch (e) { - caughtErr = true; - assert(e instanceof Deno.errors.NotFound); + try { + oldPathInfo = Deno.statSync(oldpath); + } catch (e) { + caughtErr = true; + assert(e instanceof Deno.errors.NotFound); + } + assert(caughtErr); + assertEquals(oldPathInfo, undefined); } - assert(caughtErr); - assertEquals(oldPathInfo, undefined); -}); +); |