2020-09-21 08:26:41 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-02-22 18:46:52 -05:00
|
|
|
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
|
2020-01-29 20:57:29 -05:00
|
|
|
import * as os from "./os.ts";
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "build architecture is a string",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.arch(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "home directory is a string",
|
2020-06-20 23:49:27 -04:00
|
|
|
ignore: true,
|
2020-01-29 20:57:29 -05:00
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.homedir(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-01 19:05:04 -05:00
|
|
|
name: "tmp directory is a string",
|
2020-06-20 23:49:27 -04:00
|
|
|
ignore: true,
|
2020-03-01 19:05:04 -05:00
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.tmpdir(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-01 19:05:04 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "hostname is a string",
|
2020-06-20 23:49:27 -04:00
|
|
|
ignore: true,
|
2020-01-29 20:57:29 -05:00
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.hostname(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-02-21 12:01:01 -05:00
|
|
|
name: "platform is a string",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.platform(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-02-21 12:01:01 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-02-24 08:35:45 -05:00
|
|
|
name: "release is a string",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof os.release(), "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-02-24 08:35:45 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "getPriority(): PID must be a 32 bit integer",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.getPriority(3.15);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"pid must be 'an integer'",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.getPriority(9999999999);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"must be >= -2147483648 && <= 2147483647",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "setPriority(): PID must be a 32 bit integer",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(3.15, 0);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"pid must be 'an integer'",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(9999999999, 0);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"pid must be >= -2147483648 && <= 2147483647",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "setPriority(): priority must be an integer between -20 and 19",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(0, 3.15);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be 'an integer'",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(0, -21);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(0, 20);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(0, 9999999999);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name:
|
|
|
|
"setPriority(): if only one argument specified, then this is the priority, NOT the pid",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(3.15);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be 'an integer'",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(-21);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(20);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(9999999999);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"priority must be >= -20 && <= 19",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "Signals are as expected",
|
|
|
|
fn() {
|
|
|
|
// Test a few random signals for equality
|
|
|
|
assertEquals(os.constants.signals.SIGKILL, Deno.Signal.SIGKILL);
|
|
|
|
assertEquals(os.constants.signals.SIGCONT, Deno.Signal.SIGCONT);
|
|
|
|
assertEquals(os.constants.signals.SIGXFSZ, Deno.Signal.SIGXFSZ);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "EOL is as expected",
|
|
|
|
fn() {
|
|
|
|
assert(os.EOL == "\r\n" || os.EOL == "\n");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-30 18:57:29 -05:00
|
|
|
name: "Endianness is determined",
|
|
|
|
fn() {
|
|
|
|
assert(["LE", "BE"].includes(os.endianness()));
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-30 18:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "Load average is an array of 3 numbers",
|
|
|
|
fn() {
|
2020-02-22 18:46:52 -05:00
|
|
|
const result = os.loadavg();
|
|
|
|
assert(result.length == 3);
|
|
|
|
assertEquals(typeof result[0], "number");
|
|
|
|
assertEquals(typeof result[1], "number");
|
|
|
|
assertEquals(typeof result[2], "number");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-02-23 14:40:44 -05:00
|
|
|
name: "Primitive coercion works as expected",
|
|
|
|
fn() {
|
|
|
|
assertEquals(`${os.arch}`, os.arch());
|
|
|
|
assertEquals(`${os.endianness}`, os.endianness());
|
|
|
|
assertEquals(`${os.platform}`, os.platform());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-02-23 14:40:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-01-29 20:57:29 -05:00
|
|
|
name: "APIs not yet implemented",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.cpus();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.freemem();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.getPriority();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.networkInterfaces();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.setPriority(0);
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.totalmem();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-06-12 09:53:53 -04:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.type();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-06-12 09:53:53 -04:00
|
|
|
);
|
2020-01-29 20:57:29 -05:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.uptime();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
os.userInfo();
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Not implemented",
|
2020-01-29 20:57:29 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-01-29 20:57:29 -05:00
|
|
|
});
|