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 { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
2018-10-13 16:03:27 -04:00
|
|
|
|
|
|
|
test(function dirCwdNotNull() {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno.cwd() != null);
|
2018-10-13 16:03:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ write: true }, function dirCwdChdirSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const initialdir = Deno.cwd();
|
|
|
|
const path = Deno.makeTempDirSync();
|
|
|
|
Deno.chdir(path);
|
|
|
|
const current = Deno.cwd();
|
2019-03-06 16:54:58 -05:00
|
|
|
if (Deno.build.os === "mac") {
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(current, "/private" + path);
|
2018-10-13 16:03:27 -04:00
|
|
|
} else {
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(current, path);
|
2018-10-13 16:03:27 -04:00
|
|
|
}
|
2019-02-12 10:08:56 -05:00
|
|
|
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
|
2019-03-06 16:54:58 -05:00
|
|
|
if (["linux", "mac"].includes(Deno.build.os)) {
|
2019-02-12 10:08:56 -05:00
|
|
|
const initialdir = Deno.cwd();
|
|
|
|
const path = Deno.makeTempDirSync();
|
|
|
|
Deno.chdir(path);
|
|
|
|
Deno.removeSync(path);
|
2018-10-13 16:03:27 -04:00
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.cwd();
|
2018-10-13 16:03:27 -04:00
|
|
|
throw Error("current directory removed, should throw error");
|
|
|
|
} catch (err) {
|
2019-02-12 10:08:56 -05:00
|
|
|
if (err instanceof Deno.DenoError) {
|
2018-10-13 16:03:27 -04:00
|
|
|
console.log(err.name === "NotFound");
|
|
|
|
} else {
|
|
|
|
throw Error("raised different exception");
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.chdir(initialdir);
|
2018-10-13 16:03:27 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ write: true }, function dirChdirError() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const path = Deno.makeTempDirSync() + "test";
|
2018-10-13 16:03:27 -04:00
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.chdir(path);
|
2018-10-13 16:03:27 -04:00
|
|
|
throw Error("directory not available, should throw error");
|
|
|
|
} catch (err) {
|
2019-02-12 10:08:56 -05:00
|
|
|
if (err instanceof Deno.DenoError) {
|
2018-10-13 16:03:27 -04:00
|
|
|
console.log(err.name === "NotFound");
|
|
|
|
} else {
|
|
|
|
throw Error("raised different exception");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|