summaryrefslogtreecommitdiff
path: root/cli/js/truncate_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/truncate_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/truncate_test.ts')
-rw-r--r--cli/js/truncate_test.ts80
1 files changed, 43 insertions, 37 deletions
diff --git a/cli/js/truncate_test.ts b/cli/js/truncate_test.ts
index bec51b04d..3fd85c990 100644
--- a/cli/js/truncate_test.ts
+++ b/cli/js/truncate_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { testPerm, assertEquals, assert } from "./test_util.ts";
+import { unitTest, assertEquals, assert } from "./test_util.ts";
function readDataSync(name: string): string {
const data = Deno.readFileSync(name);
@@ -15,43 +15,47 @@ async function readData(name: string): Promise<string> {
return text;
}
-testPerm({ read: true, write: true }, function truncateSyncSuccess(): void {
- const enc = new TextEncoder();
- const d = enc.encode("Hello");
- const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt";
- Deno.writeFileSync(filename, d);
- Deno.truncateSync(filename, 20);
- let data = readDataSync(filename);
- assertEquals(data.length, 20);
- Deno.truncateSync(filename, 5);
- data = readDataSync(filename);
- assertEquals(data.length, 5);
- Deno.truncateSync(filename, -5);
- data = readDataSync(filename);
- assertEquals(data.length, 0);
- Deno.removeSync(filename);
-});
+unitTest(
+ { perms: { read: true, write: true } },
+ function truncateSyncSuccess(): void {
+ const enc = new TextEncoder();
+ const d = enc.encode("Hello");
+ const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt";
+ Deno.writeFileSync(filename, d);
+ Deno.truncateSync(filename, 20);
+ let data = readDataSync(filename);
+ assertEquals(data.length, 20);
+ Deno.truncateSync(filename, 5);
+ data = readDataSync(filename);
+ assertEquals(data.length, 5);
+ Deno.truncateSync(filename, -5);
+ data = readDataSync(filename);
+ assertEquals(data.length, 0);
+ Deno.removeSync(filename);
+ }
+);
-testPerm({ read: true, write: true }, async function truncateSuccess(): Promise<
- void
-> {
- const enc = new TextEncoder();
- const d = enc.encode("Hello");
- const filename = Deno.makeTempDirSync() + "/test_truncate.txt";
- await Deno.writeFile(filename, d);
- await Deno.truncate(filename, 20);
- let data = await readData(filename);
- assertEquals(data.length, 20);
- await Deno.truncate(filename, 5);
- data = await readData(filename);
- assertEquals(data.length, 5);
- await Deno.truncate(filename, -5);
- data = await readData(filename);
- assertEquals(data.length, 0);
- await Deno.remove(filename);
-});
+unitTest(
+ { perms: { read: true, write: true } },
+ async function truncateSuccess(): Promise<void> {
+ const enc = new TextEncoder();
+ const d = enc.encode("Hello");
+ const filename = Deno.makeTempDirSync() + "/test_truncate.txt";
+ await Deno.writeFile(filename, d);
+ await Deno.truncate(filename, 20);
+ let data = await readData(filename);
+ assertEquals(data.length, 20);
+ await Deno.truncate(filename, 5);
+ data = await readData(filename);
+ assertEquals(data.length, 5);
+ await Deno.truncate(filename, -5);
+ data = await readData(filename);
+ assertEquals(data.length, 0);
+ await Deno.remove(filename);
+ }
+);
-testPerm({ write: false }, function truncateSyncPerm(): void {
+unitTest({ perms: { write: false } }, function truncateSyncPerm(): void {
let err;
try {
Deno.mkdirSync("/test_truncateSyncPermission.txt");
@@ -62,7 +66,9 @@ testPerm({ write: false }, function truncateSyncPerm(): void {
assertEquals(err.name, "PermissionDenied");
});
-testPerm({ write: false }, async function truncatePerm(): Promise<void> {
+unitTest({ perms: { write: false } }, async function truncatePerm(): Promise<
+ void
+> {
let err;
try {
await Deno.mkdir("/test_truncatePermission.txt");