summaryrefslogtreecommitdiff
path: root/cli/js/utime_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-03-04 17:31:14 +0100
committerGitHub <noreply@github.com>2020-03-04 17:31:14 +0100
commit8d96dffa410a149d0fff6115bd97f41fc1fe7459 (patch)
treeb00dc7a78e5030b68741de8bf9dde83b9fa07364 /cli/js/utime_test.ts
parent30682cf74fa039d3493c74101dca2dbb3a8d49b6 (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/utime_test.ts')
-rw-r--r--cli/js/utime_test.ts186
1 files changed, 100 insertions, 86 deletions
diff --git a/cli/js/utime_test.ts b/cli/js/utime_test.ts
index 7d6a72f47..89b60f870 100644
--- a/cli/js/utime_test.ts
+++ b/cli/js/utime_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { testPerm, assert } from "./test_util.ts";
+import { unitTest, assert } from "./test_util.ts";
// Allow 10 second difference.
// Note this might not be enough for FAT (but we are not testing on such fs).
@@ -9,24 +9,27 @@ function assertFuzzyTimestampEquals(t1: any, t2: number): void {
assert(Math.abs(t1 - t2) < 10);
}
-testPerm({ read: true, write: true }, function utimeSyncFileSuccess(): void {
- const testDir = Deno.makeTempDirSync();
- const filename = testDir + "/file.txt";
- Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
- perm: 0o666
- });
+unitTest(
+ { perms: { read: true, write: true } },
+ function utimeSyncFileSuccess(): void {
+ const testDir = Deno.makeTempDirSync();
+ const filename = testDir + "/file.txt";
+ Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
+ perm: 0o666
+ });
- const atime = 1000;
- const mtime = 50000;
- Deno.utimeSync(filename, atime, mtime);
+ const atime = 1000;
+ const mtime = 50000;
+ Deno.utimeSync(filename, atime, mtime);
- const fileInfo = Deno.statSync(filename);
- assertFuzzyTimestampEquals(fileInfo.accessed, atime);
- assertFuzzyTimestampEquals(fileInfo.modified, mtime);
-});
+ const fileInfo = Deno.statSync(filename);
+ assertFuzzyTimestampEquals(fileInfo.accessed, atime);
+ assertFuzzyTimestampEquals(fileInfo.modified, mtime);
+ }
+);
-testPerm(
- { read: true, write: true },
+unitTest(
+ { perms: { read: true, write: true } },
function utimeSyncDirectorySuccess(): void {
const testDir = Deno.makeTempDirSync();
@@ -40,20 +43,23 @@ testPerm(
}
);
-testPerm({ read: true, write: true }, function utimeSyncDateSuccess(): void {
- const testDir = Deno.makeTempDirSync();
+unitTest(
+ { perms: { read: true, write: true } },
+ function utimeSyncDateSuccess(): void {
+ const testDir = Deno.makeTempDirSync();
- const atime = 1000;
- const mtime = 50000;
- Deno.utimeSync(testDir, new Date(atime * 1000), new Date(mtime * 1000));
+ const atime = 1000;
+ const mtime = 50000;
+ Deno.utimeSync(testDir, new Date(atime * 1000), new Date(mtime * 1000));
- const dirInfo = Deno.statSync(testDir);
- assertFuzzyTimestampEquals(dirInfo.accessed, atime);
- assertFuzzyTimestampEquals(dirInfo.modified, mtime);
-});
+ const dirInfo = Deno.statSync(testDir);
+ assertFuzzyTimestampEquals(dirInfo.accessed, atime);
+ assertFuzzyTimestampEquals(dirInfo.modified, mtime);
+ }
+);
-testPerm(
- { read: true, write: true },
+unitTest(
+ { perms: { read: true, write: true } },
function utimeSyncLargeNumberSuccess(): void {
const testDir = Deno.makeTempDirSync();
@@ -69,36 +75,42 @@ testPerm(
}
);
-testPerm({ read: true, write: true }, function utimeSyncNotFound(): void {
- const atime = 1000;
- const mtime = 50000;
+unitTest(
+ { perms: { read: true, write: true } },
+ function utimeSyncNotFound(): void {
+ const atime = 1000;
+ const mtime = 50000;
- let caughtError = false;
- try {
- Deno.utimeSync("/baddir", atime, mtime);
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.NotFound);
+ let caughtError = false;
+ try {
+ Deno.utimeSync("/baddir", atime, mtime);
+ } catch (e) {
+ caughtError = true;
+ assert(e instanceof Deno.errors.NotFound);
+ }
+ assert(caughtError);
}
- assert(caughtError);
-});
-
-testPerm({ read: true, write: false }, function utimeSyncPerm(): void {
- const atime = 1000;
- const mtime = 50000;
-
- let caughtError = false;
- try {
- Deno.utimeSync("/some_dir", atime, mtime);
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.PermissionDenied);
+);
+
+unitTest(
+ { perms: { read: true, write: false } },
+ function utimeSyncPerm(): void {
+ const atime = 1000;
+ const mtime = 50000;
+
+ let caughtError = false;
+ try {
+ Deno.utimeSync("/some_dir", atime, mtime);
+ } catch (e) {
+ caughtError = true;
+ assert(e instanceof Deno.errors.PermissionDenied);
+ }
+ assert(caughtError);
}
- assert(caughtError);
-});
+);
-testPerm(
- { read: true, write: true },
+unitTest(
+ { perms: { read: true, write: true } },
async function utimeFileSuccess(): Promise<void> {
const testDir = Deno.makeTempDirSync();
const filename = testDir + "/file.txt";
@@ -116,8 +128,8 @@ testPerm(
}
);
-testPerm(
- { read: true, write: true },
+unitTest(
+ { perms: { read: true, write: true } },
async function utimeDirectorySuccess(): Promise<void> {
const testDir = Deno.makeTempDirSync();
@@ -131,8 +143,8 @@ testPerm(
}
);
-testPerm(
- { read: true, write: true },
+unitTest(
+ { perms: { read: true, write: true } },
async function utimeDateSuccess(): Promise<void> {
const testDir = Deno.makeTempDirSync();
@@ -146,34 +158,36 @@ testPerm(
}
);
-testPerm({ read: true, write: true }, async function utimeNotFound(): Promise<
- void
-> {
- const atime = 1000;
- const mtime = 50000;
-
- let caughtError = false;
- try {
- await Deno.utime("/baddir", atime, mtime);
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.NotFound);
+unitTest(
+ { perms: { read: true, write: true } },
+ async function utimeNotFound(): Promise<void> {
+ const atime = 1000;
+ const mtime = 50000;
+
+ let caughtError = false;
+ try {
+ await Deno.utime("/baddir", atime, mtime);
+ } catch (e) {
+ caughtError = true;
+ assert(e instanceof Deno.errors.NotFound);
+ }
+ assert(caughtError);
}
- assert(caughtError);
-});
-
-testPerm({ read: true, write: false }, async function utimeSyncPerm(): Promise<
- void
-> {
- const atime = 1000;
- const mtime = 50000;
-
- let caughtError = false;
- try {
- await Deno.utime("/some_dir", atime, mtime);
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.PermissionDenied);
+);
+
+unitTest(
+ { perms: { read: true, write: false } },
+ async function utimeSyncPerm(): Promise<void> {
+ const atime = 1000;
+ const mtime = 50000;
+
+ let caughtError = false;
+ try {
+ await Deno.utime("/some_dir", atime, mtime);
+ } catch (e) {
+ caughtError = true;
+ assert(e instanceof Deno.errors.PermissionDenied);
+ }
+ assert(caughtError);
}
- assert(caughtError);
-});
+);