1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/js/os_test.ts

73 lines
1.7 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.
2019-06-25 12:05:41 -04:00
import {
test,
testPerm,
assert,
assertEquals,
assertNotEquals
} from "./test_util.ts";
2018-08-30 13:49:24 -04:00
testPerm({ env: true }, function envSuccess(): void {
const env = Deno.env();
assert(env !== null);
// eslint-disable-next-line @typescript-eslint/camelcase
env.test_var = "Hello World";
const newEnv = Deno.env();
assertEquals(env.test_var, newEnv.test_var);
});
test(function envFailure(): void {
let caughtError = false;
try {
Deno.env();
} catch (err) {
caughtError = true;
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
assertEquals(err.name, "PermissionDenied");
}
assert(caughtError);
});
2019-01-06 14:16:42 -05:00
test(function osPid(): void {
console.log("pid", Deno.pid);
assert(Deno.pid > 0);
2019-01-06 14:16:42 -05:00
});
2019-02-02 22:05:30 -05:00
// See complete tests in tools/is_tty_test.py
test(function osIsTTYSmoke(): void {
console.log(Deno.isTTY());
2019-02-02 22:05:30 -05:00
});
2019-06-25 12:05:41 -04:00
testPerm({ env: true }, function homeDir(): void {
2019-06-25 12:05:41 -04:00
assertNotEquals(Deno.homeDir(), "");
});
testPerm({ env: false }, function homeDirPerm(): void {
let caughtError = false;
try {
Deno.homeDir();
} catch (err) {
caughtError = true;
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
assertEquals(err.name, "PermissionDenied");
}
assert(caughtError);
});
testPerm({ env: true }, function execPath(): void {
assertNotEquals(Deno.execPath(), "");
});
testPerm({ env: false }, function execPathPerm(): void {
let caughtError = false;
try {
Deno.execPath();
} catch (err) {
caughtError = true;
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
assertEquals(err.name, "PermissionDenied");
}
assert(caughtError);
});