mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(cli/tests/unit) to use assertThrows (#6459)
This commit is contained in:
parent
6bbe52fba3
commit
87f8f99c49
28 changed files with 404 additions and 913 deletions
|
@ -1,4 +1,9 @@
|
|||
import { unitTest, assert, assertEquals } from "./test_util.ts";
|
||||
import {
|
||||
unitTest,
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
} from "./test_util.ts";
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
|
@ -28,27 +33,17 @@ unitTest(
|
|||
unitTest({ perms: { write: true } }, function writeTextFileSyncFail(): void {
|
||||
const filename = "/baddir/test.txt";
|
||||
// The following should fail because /baddir doesn't exist (hopefully).
|
||||
let caughtError = false;
|
||||
try {
|
||||
assertThrows(() => {
|
||||
Deno.writeTextFileSync(filename, "hello");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.NotFound);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.NotFound);
|
||||
});
|
||||
|
||||
unitTest({ perms: { write: false } }, function writeTextFileSyncPerm(): void {
|
||||
const filename = "/baddir/test.txt";
|
||||
// The following should fail due to no write permission
|
||||
let caughtError = false;
|
||||
try {
|
||||
assertThrows(() => {
|
||||
Deno.writeTextFileSync(filename, "Hello");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.PermissionDenied);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.PermissionDenied);
|
||||
});
|
||||
|
||||
unitTest(
|
||||
|
@ -81,14 +76,9 @@ unitTest(
|
|||
async function writeTextFileNotFound(): Promise<void> {
|
||||
const filename = "/baddir/test.txt";
|
||||
// The following should fail because /baddir doesn't exist (hopefully).
|
||||
let caughtError = false;
|
||||
try {
|
||||
await assertThrowsAsync(async () => {
|
||||
await Deno.writeTextFile(filename, "Hello");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.NotFound);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.NotFound);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -97,13 +87,8 @@ unitTest(
|
|||
async function writeTextFilePerm(): Promise<void> {
|
||||
const filename = "/baddir/test.txt";
|
||||
// The following should fail due to no write permission
|
||||
let caughtError = false;
|
||||
try {
|
||||
await assertThrowsAsync(async () => {
|
||||
await Deno.writeTextFile(filename, "Hello");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.PermissionDenied);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.PermissionDenied);
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue