addon-sdk/source/test/test-node-os.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-node-os.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,33 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +"use strict";
     1.8 +
     1.9 +let os = require("node/os");
    1.10 +let system = require("sdk/system");
    1.11 +
    1.12 +exports["test os"] = function (assert) {
    1.13 +  assert.equal(os.tmpdir(), system.pathFor("TmpD"), "os.tmpdir() matches temp dir");
    1.14 +  assert.ok(os.endianness() === "BE" || os.endianness() === "LE", "os.endianness is BE or LE");
    1.15 +
    1.16 +  assert.ok(os.arch().length > 0, "os.arch() returns a value");
    1.17 +  assert.equal(typeof os.arch(), "string", "os.arch() returns a string");
    1.18 +  assert.ok(os.type().length > 0, "os.type() returns a value");
    1.19 +  assert.equal(typeof os.type(), "string", "os.type() returns a string");
    1.20 +  assert.ok(os.platform().length > 0, "os.platform() returns a value");
    1.21 +  assert.equal(typeof os.platform(), "string", "os.platform() returns a string");
    1.22 +
    1.23 +  assert.ok(os.release().length > 0, "os.release() returns a value");
    1.24 +  assert.equal(typeof os.release(), "string", "os.release() returns a string");
    1.25 +  assert.ok(os.hostname().length > 0, "os.hostname() returns a value");
    1.26 +  assert.equal(typeof os.hostname(), "string", "os.hostname() returns a string");
    1.27 +  assert.ok(os.EOL === "\n" || os.EOL === "\r\n", "os.EOL returns a correct EOL char");
    1.28 +
    1.29 +  assert.deepEqual(os.loadavg(), [0, 0, 0], "os.loadavg() returns an array of 0s");
    1.30 +
    1.31 +  ["uptime", "totalmem", "freemem", "cpus"].forEach(method => {
    1.32 +    assert.throws(() => os[method](), "os." + method + " throws");
    1.33 +  });
    1.34 +};
    1.35 +
    1.36 +require("test").run(exports);

mercurial