2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-06 20:48:46 -05:00
|
|
|
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
2018-09-11 15:38:53 -04:00
|
|
|
|
|
|
|
// TODO Add tests for modified, accessed, and created fields once there is a way
|
|
|
|
// to create temp files.
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true }, async function statSyncSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const packageInfo = Deno.statSync("package.json");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(packageInfo.isFile());
|
|
|
|
assert(!packageInfo.isSymlink());
|
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const testingInfo = Deno.statSync("testing");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(testingInfo.isDirectory());
|
|
|
|
assert(!testingInfo.isSymlink());
|
|
|
|
|
2019-03-19 12:18:05 -04:00
|
|
|
const testsInfo = Deno.statSync("tests");
|
|
|
|
assert(testsInfo.isDirectory());
|
|
|
|
assert(!testsInfo.isSymlink());
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: false }, async function statSyncPerm() {
|
|
|
|
let caughtError = false;
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.statSync("package.json");
|
2019-02-08 15:59:38 -05:00
|
|
|
} catch (e) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(e.name, "PermissionDenied");
|
2019-02-08 15:59:38 -05:00
|
|
|
}
|
|
|
|
assert(caughtError);
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ read: true }, async function statSyncNotFound() {
|
2018-09-11 15:38:53 -04:00
|
|
|
let caughtError = false;
|
|
|
|
let badInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
badInfo = Deno.statSync("bad_file_name");
|
2018-09-11 15:38:53 -04:00
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
|
|
|
assertEquals(err.name, "NotFound");
|
2018-09-11 15:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(caughtError);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(badInfo, undefined);
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true }, async function lstatSyncSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const packageInfo = Deno.lstatSync("package.json");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(packageInfo.isFile());
|
|
|
|
assert(!packageInfo.isSymlink());
|
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const testingInfo = Deno.lstatSync("testing");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(!testingInfo.isDirectory());
|
|
|
|
assert(testingInfo.isSymlink());
|
|
|
|
|
2019-03-19 12:18:05 -04:00
|
|
|
const testsInfo = Deno.lstatSync("tests");
|
|
|
|
assert(testsInfo.isDirectory());
|
|
|
|
assert(!testsInfo.isSymlink());
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: false }, async function lstatSyncPerm() {
|
|
|
|
let caughtError = false;
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.lstatSync("package.json");
|
2019-02-08 15:59:38 -05:00
|
|
|
} catch (e) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(e.name, "PermissionDenied");
|
2019-02-08 15:59:38 -05:00
|
|
|
}
|
|
|
|
assert(caughtError);
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ read: true }, async function lstatSyncNotFound() {
|
2018-09-11 15:38:53 -04:00
|
|
|
let caughtError = false;
|
|
|
|
let badInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
badInfo = Deno.lstatSync("bad_file_name");
|
2018-09-11 15:38:53 -04:00
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
|
|
|
assertEquals(err.name, "NotFound");
|
2018-09-11 15:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(caughtError);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(badInfo, undefined);
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true }, async function statSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const packageInfo = await Deno.stat("package.json");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(packageInfo.isFile());
|
|
|
|
assert(!packageInfo.isSymlink());
|
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const testingInfo = await Deno.stat("testing");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(testingInfo.isDirectory());
|
|
|
|
assert(!testingInfo.isSymlink());
|
|
|
|
|
2019-03-19 12:18:05 -04:00
|
|
|
const testsInfo = await Deno.stat("tests");
|
|
|
|
assert(testsInfo.isDirectory());
|
|
|
|
assert(!testsInfo.isSymlink());
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: false }, async function statPerm() {
|
|
|
|
let caughtError = false;
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
await Deno.stat("package.json");
|
2019-02-08 15:59:38 -05:00
|
|
|
} catch (e) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(e.name, "PermissionDenied");
|
2019-02-08 15:59:38 -05:00
|
|
|
}
|
|
|
|
assert(caughtError);
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ read: true }, async function statNotFound() {
|
2018-09-11 15:38:53 -04:00
|
|
|
let caughtError = false;
|
|
|
|
let badInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
badInfo = await Deno.stat("bad_file_name");
|
2018-09-11 15:38:53 -04:00
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
|
|
|
assertEquals(err.name, "NotFound");
|
2018-09-11 15:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(caughtError);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(badInfo, undefined);
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true }, async function lstatSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const packageInfo = await Deno.lstat("package.json");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(packageInfo.isFile());
|
|
|
|
assert(!packageInfo.isSymlink());
|
|
|
|
|
2019-02-12 10:08:56 -05:00
|
|
|
const testingInfo = await Deno.lstat("testing");
|
2018-09-11 15:38:53 -04:00
|
|
|
assert(!testingInfo.isDirectory());
|
|
|
|
assert(testingInfo.isSymlink());
|
|
|
|
|
2019-03-19 12:18:05 -04:00
|
|
|
const testsInfo = await Deno.lstat("tests");
|
|
|
|
assert(testsInfo.isDirectory());
|
|
|
|
assert(!testsInfo.isSymlink());
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: false }, async function lstatPerm() {
|
|
|
|
let caughtError = false;
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
await Deno.lstat("package.json");
|
2019-02-08 15:59:38 -05:00
|
|
|
} catch (e) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(e.name, "PermissionDenied");
|
2019-02-08 15:59:38 -05:00
|
|
|
}
|
|
|
|
assert(caughtError);
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ read: true }, async function lstatNotFound() {
|
2018-09-11 15:38:53 -04:00
|
|
|
let caughtError = false;
|
|
|
|
let badInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
badInfo = await Deno.lstat("bad_file_name");
|
2018-09-11 15:38:53 -04:00
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
|
|
|
assertEquals(err.name, "NotFound");
|
2018-09-11 15:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(caughtError);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(badInfo, undefined);
|
2018-09-11 15:38:53 -04:00
|
|
|
});
|