mirror of
https://github.com/denoland/deno
synced 2024-11-05 18:45:24 +00:00
c42a9d7370
A major API change was that asserts are imported from testing/asserts.ts now rather than testing/mod.ts and assertEqual as renamed to assertEquals to conform to what is most common in JavaScript.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
|
|
|
test(function dirCwdNotNull() {
|
|
assert(Deno.cwd() != null);
|
|
});
|
|
|
|
testPerm({ write: true }, function dirCwdChdirSuccess() {
|
|
const initialdir = Deno.cwd();
|
|
const path = Deno.makeTempDirSync();
|
|
Deno.chdir(path);
|
|
const current = Deno.cwd();
|
|
if (Deno.build.os === "mac") {
|
|
assertEquals(current, "/private" + path);
|
|
} else {
|
|
assertEquals(current, path);
|
|
}
|
|
Deno.chdir(initialdir);
|
|
});
|
|
|
|
testPerm({ write: true }, function dirCwdError() {
|
|
// excluding windows since it throws resource busy, while removeSync
|
|
if (["linux", "mac"].includes(Deno.build.os)) {
|
|
const initialdir = Deno.cwd();
|
|
const path = Deno.makeTempDirSync();
|
|
Deno.chdir(path);
|
|
Deno.removeSync(path);
|
|
try {
|
|
Deno.cwd();
|
|
throw Error("current directory removed, should throw error");
|
|
} catch (err) {
|
|
if (err instanceof Deno.DenoError) {
|
|
console.log(err.name === "NotFound");
|
|
} else {
|
|
throw Error("raised different exception");
|
|
}
|
|
}
|
|
Deno.chdir(initialdir);
|
|
}
|
|
});
|
|
|
|
testPerm({ write: true }, function dirChdirError() {
|
|
const path = Deno.makeTempDirSync() + "test";
|
|
try {
|
|
Deno.chdir(path);
|
|
throw Error("directory not available, should throw error");
|
|
} catch (err) {
|
|
if (err instanceof Deno.DenoError) {
|
|
console.log(err.name === "NotFound");
|
|
} else {
|
|
throw Error("raised different exception");
|
|
}
|
|
}
|
|
});
|