From bc792c02674cc22459a3016b271f9c5b70e9d573 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 29 Apr 2020 16:39:37 -0400 Subject: make camel case readDir, readLink, realPath (#4995) --- cli/js/tests/read_dir_test.ts | 24 ++++----- cli/js/tests/read_link_test.ts | 20 ++++---- cli/js/tests/real_path_test.ts | 108 +++++++++++++++++++++++++++++++++++++++++ cli/js/tests/realpath_test.ts | 108 ----------------------------------------- cli/js/tests/test_util.ts | 2 +- cli/js/tests/unit_tests.ts | 2 +- 6 files changed, 132 insertions(+), 132 deletions(-) create mode 100644 cli/js/tests/real_path_test.ts delete mode 100644 cli/js/tests/realpath_test.ts (limited to 'cli/js/tests') diff --git a/cli/js/tests/read_dir_test.ts b/cli/js/tests/read_dir_test.ts index f1c7ea121..79e2a1507 100644 --- a/cli/js/tests/read_dir_test.ts +++ b/cli/js/tests/read_dir_test.ts @@ -14,15 +14,15 @@ function assertSameContent(files: Deno.DirEntry[]): void { assertEquals(counter, 1); } -unitTest({ perms: { read: true } }, function readdirSyncSuccess(): void { - const files = [...Deno.readdirSync("cli/tests/")]; +unitTest({ perms: { read: true } }, function readDirSyncSuccess(): void { + const files = [...Deno.readDirSync("cli/tests/")]; assertSameContent(files); }); -unitTest({ perms: { read: false } }, function readdirSyncPerm(): void { +unitTest({ perms: { read: false } }, function readDirSyncPerm(): void { let caughtError = false; try { - Deno.readdirSync("tests/"); + Deno.readDirSync("tests/"); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.PermissionDenied); @@ -30,12 +30,12 @@ unitTest({ perms: { read: false } }, function readdirSyncPerm(): void { assert(caughtError); }); -unitTest({ perms: { read: true } }, function readdirSyncNotDir(): void { +unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void { let caughtError = false; let src; try { - src = Deno.readdirSync("cli/tests/fixture.json"); + src = Deno.readDirSync("cli/tests/fixture.json"); } catch (err) { caughtError = true; assert(err instanceof Error); @@ -44,12 +44,12 @@ unitTest({ perms: { read: true } }, function readdirSyncNotDir(): void { assertEquals(src, undefined); }); -unitTest({ perms: { read: true } }, function readdirSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void { let caughtError = false; let src; try { - src = Deno.readdirSync("bad_dir_name"); + src = Deno.readDirSync("bad_dir_name"); } catch (err) { caughtError = true; assert(err instanceof Deno.errors.NotFound); @@ -58,22 +58,22 @@ unitTest({ perms: { read: true } }, function readdirSyncNotFound(): void { assertEquals(src, undefined); }); -unitTest({ perms: { read: true } }, async function readdirSuccess(): Promise< +unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise< void > { const files = []; - for await (const dirEntry of Deno.readdir("cli/tests/")) { + for await (const dirEntry of Deno.readDir("cli/tests/")) { files.push(dirEntry); } assertSameContent(files); }); -unitTest({ perms: { read: false } }, async function readdirPerm(): Promise< +unitTest({ perms: { read: false } }, async function readDirPerm(): Promise< void > { let caughtError = false; try { - await Deno.readdir("tests/")[Symbol.asyncIterator]().next(); + await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.PermissionDenied); diff --git a/cli/js/tests/read_link_test.ts b/cli/js/tests/read_link_test.ts index 6e8c29a61..6821d8dc8 100644 --- a/cli/js/tests/read_link_test.ts +++ b/cli/js/tests/read_link_test.ts @@ -3,7 +3,7 @@ import { unitTest, assert, assertEquals } from "./test_util.ts"; unitTest( { perms: { write: true, read: true } }, - function readlinkSyncSuccess(): void { + function readLinkSyncSuccess(): void { const testDir = Deno.makeTempDirSync(); const target = testDir + "/target"; const symlink = testDir + "/symln"; @@ -12,16 +12,16 @@ unitTest( // See https://github.com/denoland/deno/issues/815. if (Deno.build.os !== "windows") { Deno.symlinkSync(target, symlink); - const targetPath = Deno.readlinkSync(symlink); + const targetPath = Deno.readLinkSync(symlink); assertEquals(targetPath, target); } } ); -unitTest({ perms: { read: false } }, function readlinkSyncPerm(): void { +unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void { let caughtError = false; try { - Deno.readlinkSync("/symlink"); + Deno.readLinkSync("/symlink"); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.PermissionDenied); @@ -29,11 +29,11 @@ unitTest({ perms: { read: false } }, function readlinkSyncPerm(): void { assert(caughtError); }); -unitTest({ perms: { read: true } }, function readlinkSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void { let caughtError = false; let data; try { - data = Deno.readlinkSync("bad_filename"); + data = Deno.readLinkSync("bad_filename"); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.NotFound); @@ -44,7 +44,7 @@ unitTest({ perms: { read: true } }, function readlinkSyncNotFound(): void { unitTest( { perms: { write: true, read: true } }, - async function readlinkSuccess(): Promise { + async function readLinkSuccess(): Promise { const testDir = Deno.makeTempDirSync(); const target = testDir + "/target"; const symlink = testDir + "/symln"; @@ -53,18 +53,18 @@ unitTest( // See https://github.com/denoland/deno/issues/815. if (Deno.build.os !== "windows") { Deno.symlinkSync(target, symlink); - const targetPath = await Deno.readlink(symlink); + const targetPath = await Deno.readLink(symlink); assertEquals(targetPath, target); } } ); -unitTest({ perms: { read: false } }, async function readlinkPerm(): Promise< +unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise< void > { let caughtError = false; try { - await Deno.readlink("/symlink"); + await Deno.readLink("/symlink"); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.PermissionDenied); diff --git a/cli/js/tests/real_path_test.ts b/cli/js/tests/real_path_test.ts new file mode 100644 index 000000000..c88955270 --- /dev/null +++ b/cli/js/tests/real_path_test.ts @@ -0,0 +1,108 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { unitTest, assert } from "./test_util.ts"; + +unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void { + const incompletePath = "cli/tests/fixture.json"; + const realPath = Deno.realPathSync(incompletePath); + if (Deno.build.os !== "windows") { + assert(realPath.startsWith("/")); + } else { + assert(/^[A-Z]/.test(realPath)); + } + assert(realPath.endsWith(incompletePath)); +}); + +unitTest( + { + ignore: Deno.build.os === "windows", + perms: { read: true, write: true }, + }, + function realPathSyncSymlink(): void { + const testDir = Deno.makeTempDirSync(); + const target = testDir + "/target"; + const symlink = testDir + "/symln"; + Deno.mkdirSync(target); + Deno.symlinkSync(target, symlink); + const targetPath = Deno.realPathSync(symlink); + assert(targetPath.startsWith("/")); + assert(targetPath.endsWith("/target")); + } +); + +unitTest({ perms: { read: false } }, function realPathSyncPerm(): void { + let caughtError = false; + try { + Deno.realPathSync("some_file"); + } catch (e) { + caughtError = true; + assert(e instanceof Deno.errors.PermissionDenied); + } + assert(caughtError); +}); + +unitTest({ perms: { read: true } }, function realPathSyncNotFound(): void { + let caughtError = false; + try { + Deno.realPathSync("bad_filename"); + } catch (e) { + caughtError = true; + assert(e instanceof Deno.errors.NotFound); + } + assert(caughtError); +}); + +unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise< + void +> { + const incompletePath = "cli/tests/fixture.json"; + const realPath = await Deno.realPath(incompletePath); + if (Deno.build.os !== "windows") { + assert(realPath.startsWith("/")); + } else { + assert(/^[A-Z]/.test(realPath)); + } + assert(realPath.endsWith(incompletePath)); +}); + +unitTest( + { + ignore: Deno.build.os === "windows", + perms: { read: true, write: true }, + }, + async function realPathSymlink(): Promise { + const testDir = Deno.makeTempDirSync(); + const target = testDir + "/target"; + const symlink = testDir + "/symln"; + Deno.mkdirSync(target); + Deno.symlinkSync(target, symlink); + const targetPath = await Deno.realPath(symlink); + assert(targetPath.startsWith("/")); + assert(targetPath.endsWith("/target")); + } +); + +unitTest({ perms: { read: false } }, async function realPathPerm(): Promise< + void +> { + let caughtError = false; + try { + await Deno.realPath("some_file"); + } catch (e) { + caughtError = true; + assert(e instanceof Deno.errors.PermissionDenied); + } + assert(caughtError); +}); + +unitTest({ perms: { read: true } }, async function realPathNotFound(): Promise< + void +> { + let caughtError = false; + try { + await Deno.realPath("bad_filename"); + } catch (e) { + caughtError = true; + assert(e instanceof Deno.errors.NotFound); + } + assert(caughtError); +}); diff --git a/cli/js/tests/realpath_test.ts b/cli/js/tests/realpath_test.ts deleted file mode 100644 index d76094366..000000000 --- a/cli/js/tests/realpath_test.ts +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { unitTest, assert } from "./test_util.ts"; - -unitTest({ perms: { read: true } }, function realpathSyncSuccess(): void { - const incompletePath = "cli/tests/fixture.json"; - const realPath = Deno.realpathSync(incompletePath); - if (Deno.build.os !== "windows") { - assert(realPath.startsWith("/")); - } else { - assert(/^[A-Z]/.test(realPath)); - } - assert(realPath.endsWith(incompletePath)); -}); - -unitTest( - { - ignore: Deno.build.os === "windows", - perms: { read: true, write: true }, - }, - function realpathSyncSymlink(): void { - const testDir = Deno.makeTempDirSync(); - const target = testDir + "/target"; - const symlink = testDir + "/symln"; - Deno.mkdirSync(target); - Deno.symlinkSync(target, symlink); - const targetPath = Deno.realpathSync(symlink); - assert(targetPath.startsWith("/")); - assert(targetPath.endsWith("/target")); - } -); - -unitTest({ perms: { read: false } }, function realpathSyncPerm(): void { - let caughtError = false; - try { - Deno.realpathSync("some_file"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); -}); - -unitTest({ perms: { read: true } }, function realpathSyncNotFound(): void { - let caughtError = false; - try { - Deno.realpathSync("bad_filename"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.NotFound); - } - assert(caughtError); -}); - -unitTest({ perms: { read: true } }, async function realpathSuccess(): Promise< - void -> { - const incompletePath = "cli/tests/fixture.json"; - const realPath = await Deno.realpath(incompletePath); - if (Deno.build.os !== "windows") { - assert(realPath.startsWith("/")); - } else { - assert(/^[A-Z]/.test(realPath)); - } - assert(realPath.endsWith(incompletePath)); -}); - -unitTest( - { - ignore: Deno.build.os === "windows", - perms: { read: true, write: true }, - }, - async function realpathSymlink(): Promise { - const testDir = Deno.makeTempDirSync(); - const target = testDir + "/target"; - const symlink = testDir + "/symln"; - Deno.mkdirSync(target); - Deno.symlinkSync(target, symlink); - const targetPath = await Deno.realpath(symlink); - assert(targetPath.startsWith("/")); - assert(targetPath.endsWith("/target")); - } -); - -unitTest({ perms: { read: false } }, async function realpathPerm(): Promise< - void -> { - let caughtError = false; - try { - await Deno.realpath("some_file"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); -}); - -unitTest({ perms: { read: true } }, async function realpathNotFound(): Promise< - void -> { - let caughtError = false; - try { - await Deno.realpath("bad_filename"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.NotFound); - } - assert(caughtError); -}); diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts index 516834454..24186db71 100644 --- a/cli/js/tests/test_util.ts +++ b/cli/js/tests/test_util.ts @@ -332,7 +332,7 @@ unitTest(function permissionsMatches(): void { unitTest( { perms: { read: true } }, function assertAllUnitTestFilesImported(): void { - const directoryTestFiles = [...Deno.readdirSync("./cli/js/tests/")] + const directoryTestFiles = [...Deno.readDirSync("./cli/js/tests/")] .map((k) => k.name) .filter( (file) => diff --git a/cli/js/tests/unit_tests.ts b/cli/js/tests/unit_tests.ts index dd4abf116..fa168e6dd 100644 --- a/cli/js/tests/unit_tests.ts +++ b/cli/js/tests/unit_tests.ts @@ -42,7 +42,7 @@ import "./net_test.ts"; import "./os_test.ts"; import "./permissions_test.ts"; import "./process_test.ts"; -import "./realpath_test.ts"; +import "./real_path_test.ts"; import "./read_dir_test.ts"; import "./read_text_file_test.ts"; import "./read_file_test.ts"; -- cgit v1.2.3