summaryrefslogtreecommitdiff
path: root/tools/util_test.ts
diff options
context:
space:
mode:
authorDmitry Sharshakov <sh7dm@outlook.com>2019-02-08 23:59:38 +0300
committerRyan Dahl <ry@tinyclouds.org>2019-02-08 15:59:38 -0500
commit9ab03389f047e5520c184b9fce4cd5fb2e4804bd (patch)
treec1b3295aa6788595e4b73d28aeba0b8fdc8f3205 /tools/util_test.ts
parent3abaf9edb6877c328402b94fa0bcb6a9e0bbe86d (diff)
Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
Diffstat (limited to 'tools/util_test.ts')
-rw-r--r--tools/util_test.ts21
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/util_test.ts b/tools/util_test.ts
index 79868b440..5a1d33617 100644
--- a/tools/util_test.ts
+++ b/tools/util_test.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { test, assertEqual } from "../js/test_util.ts";
+import * as deno from "deno";
+import { assert, testPerm, assertEqual } from "../js/test_util.ts";
import { findFiles } from "./util.ts";
const testDir = "tools/testdata/find_files_testdata";
@@ -7,7 +8,7 @@ const testDir = "tools/testdata/find_files_testdata";
// Sorts and replace backslashes with slashes.
const normalize = files => files.map(f => f.replace(/\\/g, "/")).sort();
-test(function testFindFiles() {
+testPerm({ read: true }, function testFindFiles() {
const files = findFiles([testDir], [".ts", ".md"]);
assertEqual(normalize(files), [
`${testDir}/bar.md`,
@@ -23,7 +24,7 @@ test(function testFindFiles() {
]);
});
-test(function testFindFilesDepth() {
+testPerm({ read: true }, function testFindFilesDepth() {
const files = findFiles([testDir], [".ts", ".md"], { depth: 1 });
assertEqual(normalize(files), [
`${testDir}/bar.md`,
@@ -33,7 +34,7 @@ test(function testFindFilesDepth() {
]);
});
-test(function testFindFilesSkip() {
+testPerm({ read: true }, function testFindFilesSkip() {
const files = findFiles([testDir], [".ts", ".md"], {
skip: ["foo.md", "subdir1"]
});
@@ -47,3 +48,15 @@ test(function testFindFilesSkip() {
`${testDir}/subdir0/subdir0/foo.ts`
]);
});
+
+testPerm({ read: false }, function testFindFilesPerm() {
+ let caughtError = false;
+ try {
+ const files = findFiles([testDir], [".ts", ".md"]);
+ } catch (e) {
+ caughtError = true;
+ assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
+ assertEqual(e.name, "PermissionDenied");
+ }
+ assert(caughtError);
+});