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
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
testPerm({ env: true }, function envSuccess(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
const env = Deno.env();
|
2018-08-31 07:51:12 -04:00
|
|
|
assert(env !== null);
|
2019-03-09 12:30:38 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
2018-08-31 07:51:12 -04:00
|
|
|
env.test_var = "Hello World";
|
2019-02-12 10:08:56 -05:00
|
|
|
const newEnv = Deno.env();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(env.test_var, newEnv.test_var);
|
2018-08-31 07:51:12 -04:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function envFailure(): void {
|
2018-08-31 07:51:12 -04:00
|
|
|
let caughtError = false;
|
|
|
|
try {
|
2019-03-09 12:30:38 -05:00
|
|
|
Deno.env();
|
2018-08-31 07:51:12 -04:00
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(err.name, "PermissionDenied");
|
2018-08-31 07:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(caughtError);
|
|
|
|
});
|
2019-01-06 14:16:42 -05:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function osPid(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
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
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function osIsTTYSmoke(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
console.log(Deno.isTTY());
|
2019-02-02 22:05:30 -05:00
|
|
|
});
|
2019-06-25 12:05:41 -04:00
|
|
|
|
2019-08-03 21:34:13 -04:00
|
|
|
testPerm({ env: true }, function homeDir(): void {
|
2019-06-25 12:05:41 -04:00
|
|
|
assertNotEquals(Deno.homeDir(), "");
|
|
|
|
});
|
2019-08-03 21:34:13 -04:00
|
|
|
|
|
|
|
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 {
|
2019-08-06 17:05:47 -04:00
|
|
|
assertNotEquals(Deno.execPath(), "");
|
2019-08-03 21:34:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
testPerm({ env: false }, function execPathPerm(): void {
|
2019-08-06 17:05:47 -04:00
|
|
|
let caughtError = false;
|
|
|
|
try {
|
|
|
|
Deno.execPath();
|
|
|
|
} catch (err) {
|
|
|
|
caughtError = true;
|
|
|
|
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(err.name, "PermissionDenied");
|
|
|
|
}
|
|
|
|
assert(caughtError);
|
2019-08-03 21:34:13 -04:00
|
|
|
});
|