0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/dir_test.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-01-21 14:03:30 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2018-10-13 16:03:27 -04:00
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
test(function dirCwdNotNull() {
assert(Deno.cwd() != null);
2018-10-13 16:03:27 -04:00
});
testPerm({ write: true }, function dirCwdChdirSuccess() {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
const current = Deno.cwd();
if (Deno.platform.os === "mac") {
2018-10-13 16:03:27 -04:00
assertEqual(current, "/private" + path);
} else {
assertEqual(current, path);
}
Deno.chdir(initialdir);
2018-10-13 16:03:27 -04:00
});
testPerm({ write: true }, function dirCwdError() {
// excluding windows since it throws resource busy, while removeSync
if (["linux", "mac"].includes(Deno.platform.os)) {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
Deno.removeSync(path);
2018-10-13 16:03:27 -04:00
try {
Deno.cwd();
2018-10-13 16:03:27 -04:00
throw Error("current directory removed, should throw error");
} catch (err) {
if (err instanceof Deno.DenoError) {
2018-10-13 16:03:27 -04:00
console.log(err.name === "NotFound");
} else {
throw Error("raised different exception");
}
}
Deno.chdir(initialdir);
2018-10-13 16:03:27 -04:00
}
});
testPerm({ write: true }, function dirChdirError() {
const path = Deno.makeTempDirSync() + "test";
2018-10-13 16:03:27 -04:00
try {
Deno.chdir(path);
2018-10-13 16:03:27 -04:00
throw Error("directory not available, should throw error");
} catch (err) {
if (err instanceof Deno.DenoError) {
2018-10-13 16:03:27 -04:00
console.log(err.name === "NotFound");
} else {
throw Error("raised different exception");
}
}
});