MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 104 lines 5.3 kB view raw
1import { test, summary } from './helpers.js'; 2import os from 'ant:os'; 3 4console.log('OS Module Tests\n'); 5 6test('os.EOL exists', typeof os.EOL, 'string'); 7test('os.EOL is newline', os.EOL === '\n' || os.EOL === '\r\n', true); 8 9test('os.devNull exists', typeof os.devNull, 'string'); 10test('os.devNull value', os.devNull === '/dev/null' || os.devNull === '\\\\.\\nul', true); 11 12test('os.arch returns string', typeof os.arch(), 'string'); 13test('os.arch valid value', ['x64', 'arm64', 'arm', 'ia32', 'ppc64', 's390x', 'mips64', 'mipsel', 'loong64', 'riscv64'].includes(os.arch()), true); 14 15test('os.platform returns string', typeof os.platform(), 'string'); 16test('os.platform valid value', ['darwin', 'linux', 'win32', 'freebsd', 'openbsd', 'sunos', 'aix'].includes(os.platform()), true); 17 18test('os.type returns string', typeof os.type(), 'string'); 19test('os.type valid value', ['Darwin', 'Linux', 'Windows_NT', 'FreeBSD', 'OpenBSD'].includes(os.type()), true); 20 21test('os.release returns string', typeof os.release(), 'string'); 22test('os.release not empty', os.release().length > 0, true); 23 24test('os.version returns string', typeof os.version(), 'string'); 25 26test('os.machine returns string', typeof os.machine(), 'string'); 27test('os.machine not empty', os.machine().length > 0, true); 28 29test('os.hostname returns string', typeof os.hostname(), 'string'); 30test('os.hostname not empty', os.hostname().length > 0, true); 31 32test('os.homedir returns string', typeof os.homedir(), 'string'); 33test('os.homedir not empty', os.homedir().length > 0, true); 34 35test('os.tmpdir returns string', typeof os.tmpdir(), 'string'); 36test('os.tmpdir not empty', os.tmpdir().length > 0, true); 37 38test('os.endianness returns string', typeof os.endianness(), 'string'); 39test('os.endianness valid value', os.endianness() === 'LE' || os.endianness() === 'BE', true); 40 41test('os.uptime returns number', typeof os.uptime(), 'number'); 42test('os.uptime is non-negative', os.uptime() >= 0, true); 43 44test('os.totalmem returns number', typeof os.totalmem(), 'number'); 45test('os.totalmem is positive', os.totalmem() > 0, true); 46 47test('os.freemem returns number', typeof os.freemem(), 'number'); 48test('os.freemem is positive', os.freemem() > 0, true); 49test('os.freemem <= totalmem', os.freemem() <= os.totalmem(), true); 50 51test('os.availableParallelism returns number', typeof os.availableParallelism(), 'number'); 52test('os.availableParallelism >= 1', os.availableParallelism() >= 1, true); 53 54const cpus = os.cpus(); 55test('os.cpus returns array', Array.isArray(cpus), true); 56test('os.cpus has entries', cpus.length > 0, true); 57if (cpus.length > 0) { 58 test('os.cpus[0] has model', typeof cpus[0].model, 'string'); 59 test('os.cpus[0] has speed', typeof cpus[0].speed, 'number'); 60 test('os.cpus[0] has times', typeof cpus[0].times, 'object'); 61 test('os.cpus[0].times has user', typeof cpus[0].times.user, 'number'); 62 test('os.cpus[0].times has sys', typeof cpus[0].times.sys, 'number'); 63 test('os.cpus[0].times has idle', typeof cpus[0].times.idle, 'number'); 64} 65 66const loadavg = os.loadavg(); 67test('os.loadavg returns array', Array.isArray(loadavg), true); 68test('os.loadavg has 3 entries', loadavg.length, 3); 69test('os.loadavg[0] is number', typeof loadavg[0], 'number'); 70test('os.loadavg[1] is number', typeof loadavg[1], 'number'); 71test('os.loadavg[2] is number', typeof loadavg[2], 'number'); 72 73const netInterfaces = os.networkInterfaces(); 74test('os.networkInterfaces returns object', typeof netInterfaces, 'object'); 75 76const userInfo = os.userInfo(); 77test('os.userInfo returns object', typeof userInfo, 'object'); 78test('os.userInfo has uid', typeof userInfo.uid, 'number'); 79test('os.userInfo has gid', typeof userInfo.gid, 'number'); 80test('os.userInfo has username', typeof userInfo.username, 'string'); 81test('os.userInfo has homedir', typeof userInfo.homedir, 'string'); 82 83test('os.getPriority returns number', typeof os.getPriority(), 'number'); 84test('os.getPriority(0) returns number', typeof os.getPriority(0), 'number'); 85 86test('os.constants exists', typeof os.constants, 'object'); 87test('os.constants.signals exists', typeof os.constants.signals, 'object'); 88test('os.constants.signals.SIGINT exists', typeof os.constants.signals.SIGINT, 'number'); 89test('os.constants.signals.SIGTERM exists', typeof os.constants.signals.SIGTERM, 'number'); 90test('os.constants.errno exists', typeof os.constants.errno, 'object'); 91test('os.constants.errno.ENOENT exists', typeof os.constants.errno.ENOENT, 'number'); 92test('os.constants.priority exists', typeof os.constants.priority, 'object'); 93test('os.constants.priority.PRIORITY_NORMAL', os.constants.priority.PRIORITY_NORMAL, 0); 94 95test('os.constants.dlopen exists', typeof os.constants.dlopen, 'object'); 96test('os.constants.dlopen.RTLD_LAZY exists', typeof os.constants.dlopen.RTLD_LAZY, 'number'); 97test('os.constants.dlopen.RTLD_NOW exists', typeof os.constants.dlopen.RTLD_NOW, 'number'); 98test('os.constants.dlopen.RTLD_GLOBAL exists', typeof os.constants.dlopen.RTLD_GLOBAL, 'number'); 99test('os.constants.dlopen.RTLD_LOCAL exists', typeof os.constants.dlopen.RTLD_LOCAL, 'number'); 100 101test('os.constants.UV_UDP_REUSEADDR exists', typeof os.constants.UV_UDP_REUSEADDR, 'number'); 102test('os.constants.UV_UDP_REUSEADDR value', os.constants.UV_UDP_REUSEADDR, 4); 103 104summary();