summaryrefslogtreecommitdiff
path: root/cli/tests/unit/stat_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/stat_test.ts')
-rw-r--r--cli/tests/unit/stat_test.ts111
1 files changed, 108 insertions, 3 deletions
diff --git a/cli/tests/unit/stat_test.ts b/cli/tests/unit/stat_test.ts
index 7eaf73d58..67598a2d7 100644
--- a/cli/tests/unit/stat_test.ts
+++ b/cli/tests/unit/stat_test.ts
@@ -1,5 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { unitTest, assert, assertEquals } from "./test_util.ts";
+import {
+ unitTest,
+ assert,
+ assertEquals,
+ pathToAbsoluteFileUrl,
+} from "./test_util.ts";
unitTest(
{ perms: { read: true, write: true } },
@@ -18,12 +23,47 @@ unitTest(
const tempFile = Deno.makeTempFileSync();
const tempInfo = Deno.statSync(tempFile);
- const now = Date.now();
+ let now = Date.now();
assert(tempInfo.atime !== null && now - tempInfo.atime.valueOf() < 1000);
assert(tempInfo.mtime !== null && now - tempInfo.mtime.valueOf() < 1000);
assert(
tempInfo.birthtime === null || now - tempInfo.birthtime.valueOf() < 1000
);
+
+ const packageInfoByUrl = Deno.statSync(pathToAbsoluteFileUrl("README.md"));
+ assert(packageInfoByUrl.isFile);
+ assert(!packageInfoByUrl.isSymlink);
+
+ const modulesInfoByUrl = Deno.statSync(
+ pathToAbsoluteFileUrl("cli/tests/symlink_to_subdir")
+ );
+ assert(modulesInfoByUrl.isDirectory);
+ assert(!modulesInfoByUrl.isSymlink);
+
+ const testsInfoByUrl = Deno.statSync(pathToAbsoluteFileUrl("cli/tests"));
+ assert(testsInfoByUrl.isDirectory);
+ assert(!testsInfoByUrl.isSymlink);
+
+ const tempFileForUrl = Deno.makeTempFileSync();
+ const tempInfoByUrl = Deno.statSync(
+ new URL(
+ `file://${Deno.build.os === "windows" ? "/" : ""}${tempFileForUrl}`
+ )
+ );
+ now = Date.now();
+ assert(
+ tempInfoByUrl.atime !== null && now - tempInfoByUrl.atime.valueOf() < 1000
+ );
+ assert(
+ tempInfoByUrl.mtime !== null && now - tempInfoByUrl.mtime.valueOf() < 1000
+ );
+ assert(
+ tempInfoByUrl.birthtime === null ||
+ now - tempInfoByUrl.birthtime.valueOf() < 1000
+ );
+
+ Deno.removeSync(tempFile, { recursive: true });
+ Deno.removeSync(tempFileForUrl, { recursive: true });
}
);
@@ -58,13 +98,27 @@ unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void {
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
+ const packageInfoByUrl = Deno.lstatSync(pathToAbsoluteFileUrl("README.md"));
+ assert(packageInfoByUrl.isFile);
+ assert(!packageInfoByUrl.isSymlink);
+
const modulesInfo = Deno.lstatSync("cli/tests/symlink_to_subdir");
assert(!modulesInfo.isDirectory);
assert(modulesInfo.isSymlink);
+ const modulesInfoByUrl = Deno.lstatSync(
+ pathToAbsoluteFileUrl("cli/tests/symlink_to_subdir")
+ );
+ assert(!modulesInfoByUrl.isDirectory);
+ assert(modulesInfoByUrl.isSymlink);
+
const coreInfo = Deno.lstatSync("core");
assert(coreInfo.isDirectory);
assert(!coreInfo.isSymlink);
+
+ const coreInfoByUrl = Deno.lstatSync(pathToAbsoluteFileUrl("core"));
+ assert(coreInfoByUrl.isDirectory);
+ assert(!coreInfoByUrl.isSymlink);
});
unitTest({ perms: { read: false } }, function lstatSyncPerm(): void {
@@ -100,23 +154,60 @@ unitTest(
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
+ const packageInfoByUrl = await Deno.stat(
+ pathToAbsoluteFileUrl("README.md")
+ );
+ assert(packageInfoByUrl.isFile);
+ assert(!packageInfoByUrl.isSymlink);
+
const modulesInfo = await Deno.stat("cli/tests/symlink_to_subdir");
assert(modulesInfo.isDirectory);
assert(!modulesInfo.isSymlink);
+ const modulesInfoByUrl = await Deno.stat(
+ pathToAbsoluteFileUrl("cli/tests/symlink_to_subdir")
+ );
+ assert(modulesInfoByUrl.isDirectory);
+ assert(!modulesInfoByUrl.isSymlink);
+
const testsInfo = await Deno.stat("cli/tests");
assert(testsInfo.isDirectory);
assert(!testsInfo.isSymlink);
+ const testsInfoByUrl = await Deno.stat(pathToAbsoluteFileUrl("cli/tests"));
+ assert(testsInfoByUrl.isDirectory);
+ assert(!testsInfoByUrl.isSymlink);
+
const tempFile = await Deno.makeTempFile();
const tempInfo = await Deno.stat(tempFile);
- const now = Date.now();
+ let now = Date.now();
assert(tempInfo.atime !== null && now - tempInfo.atime.valueOf() < 1000);
assert(tempInfo.mtime !== null && now - tempInfo.mtime.valueOf() < 1000);
assert(
tempInfo.birthtime === null || now - tempInfo.birthtime.valueOf() < 1000
);
+
+ const tempFileForUrl = await Deno.makeTempFile();
+ const tempInfoByUrl = await Deno.stat(
+ new URL(
+ `file://${Deno.build.os === "windows" ? "/" : ""}${tempFileForUrl}`
+ )
+ );
+ now = Date.now();
+ assert(
+ tempInfoByUrl.atime !== null && now - tempInfoByUrl.atime.valueOf() < 1000
+ );
+ assert(
+ tempInfoByUrl.mtime !== null && now - tempInfoByUrl.mtime.valueOf() < 1000
+ );
+ assert(
+ tempInfoByUrl.birthtime === null ||
+ now - tempInfoByUrl.birthtime.valueOf() < 1000
+ );
+
+ Deno.removeSync(tempFile, { recursive: true });
+ Deno.removeSync(tempFileForUrl, { recursive: true });
}
);
@@ -155,13 +246,27 @@ unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise<
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
+ const packageInfoByUrl = await Deno.lstat(pathToAbsoluteFileUrl("README.md"));
+ assert(packageInfoByUrl.isFile);
+ assert(!packageInfoByUrl.isSymlink);
+
const modulesInfo = await Deno.lstat("cli/tests/symlink_to_subdir");
assert(!modulesInfo.isDirectory);
assert(modulesInfo.isSymlink);
+ const modulesInfoByUrl = await Deno.lstat(
+ pathToAbsoluteFileUrl("cli/tests/symlink_to_subdir")
+ );
+ assert(!modulesInfoByUrl.isDirectory);
+ assert(modulesInfoByUrl.isSymlink);
+
const coreInfo = await Deno.lstat("core");
assert(coreInfo.isDirectory);
assert(!coreInfo.isSymlink);
+
+ const coreInfoByUrl = await Deno.lstat(pathToAbsoluteFileUrl("core"));
+ assert(coreInfoByUrl.isDirectory);
+ assert(!coreInfoByUrl.isSymlink);
});
unitTest({ perms: { read: false } }, async function lstatPerm(): Promise<void> {