@ -1,74 +1,91 @@
'use strict' ;
var common = require ( '../common' ) ;
var assert = require ( 'assert' ) ;
var os = require ( 'os' ) ;
var path = require ( 'path' ) ;
const common = require ( '../common' ) ;
const assert = require ( 'assert' ) ;
const os = require ( 'os' ) ;
const path = require ( 'path' ) ;
const is = {
string : ( value ) => { assert . strictEqual ( typeof value , 'string' ) ; } ,
number : ( value ) => { assert . strictEqual ( typeof value , 'number' ) ; } ,
array : ( value ) => { assert . ok ( Array . isArray ( value ) ) ; } ,
object : ( value ) => {
assert . strictEqual ( typeof value , 'object' ) ;
assert . notStrictEqual ( value , null ) ;
}
} ;
process . env . TMPDIR = '/tmpdir' ;
process . env . TMP = '/tmp' ;
process . env . TEMP = '/temp' ;
if ( common . isWindows ) {
assert . equal ( os . tmpdir ( ) , '/temp' ) ;
assert . strictE qual( os . tmpdir ( ) , '/temp' ) ;
process . env . TEMP = '' ;
assert . equal ( os . tmpdir ( ) , '/tmp' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmp' ) ;
process . env . TMP = '' ;
const expected = ( process . env . SystemRoot || process . env . windir ) + '\\temp' ;
assert . e qual( os . tmpdir ( ) , expected ) ;
assert . strictE qual( os . tmpdir ( ) , expected ) ;
process . env . TEMP = '\\temp\\' ;
assert . e qual( os . tmpdir ( ) , '\\temp' ) ;
assert . strictE qual( os . tmpdir ( ) , '\\temp' ) ;
process . env . TEMP = '\\tmpdir/' ;
assert . e qual( os . tmpdir ( ) , '\\tmpdir/' ) ;
assert . strictE qual( os . tmpdir ( ) , '\\tmpdir/' ) ;
process . env . TEMP = '\\' ;
assert . e qual( os . tmpdir ( ) , '\\' ) ;
assert . strictE qual( os . tmpdir ( ) , '\\' ) ;
process . env . TEMP = 'C:\\' ;
assert . e qual( os . tmpdir ( ) , 'C:\\' ) ;
assert . strictE qual( os . tmpdir ( ) , 'C:\\' ) ;
} else {
assert . e qual( os . tmpdir ( ) , '/tmpdir' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmpdir' ) ;
process . env . TMPDIR = '' ;
assert . e qual( os . tmpdir ( ) , '/tmp' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmp' ) ;
process . env . TMP = '' ;
assert . e qual( os . tmpdir ( ) , '/temp' ) ;
assert . strictE qual( os . tmpdir ( ) , '/temp' ) ;
process . env . TEMP = '' ;
assert . e qual( os . tmpdir ( ) , '/tmp' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmp' ) ;
process . env . TMPDIR = '/tmpdir/' ;
assert . e qual( os . tmpdir ( ) , '/tmpdir' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmpdir' ) ;
process . env . TMPDIR = '/tmpdir\\' ;
assert . e qual( os . tmpdir ( ) , '/tmpdir\\' ) ;
assert . strictE qual( os . tmpdir ( ) , '/tmpdir\\' ) ;
process . env . TMPDIR = '/' ;
assert . e qual( os . tmpdir ( ) , '/' ) ;
assert . strictE qual( os . tmpdir ( ) , '/' ) ;
}
var endianness = os . endianness ( ) ;
const endianness = os . endianness ( ) ;
console . log ( 'endianness = %s' , endianness ) ;
is . string ( endianness ) ;
assert . ok ( /[BL]E/ . test ( endianness ) ) ;
var hostname = os . hostname ( ) ;
const hostname = os . hostname ( ) ;
console . log ( 'hostname = %s' , hostname ) ;
is . string ( hostname ) ;
assert . ok ( hostname . length > 0 ) ;
var uptime = os . uptime ( ) ;
const uptime = os . uptime ( ) ;
console . log ( 'uptime = %d' , uptime ) ;
is . number ( uptime ) ;
assert . ok ( uptime > 0 ) ;
var cpus = os . cpus ( ) ;
const cpus = os . cpus ( ) ;
console . log ( 'cpus = ' , cpus ) ;
is . array ( cpus ) ;
assert . ok ( cpus . length > 0 ) ;
var type = os . type ( ) ;
const type = os . type ( ) ;
console . log ( 'type = ' , type ) ;
is . string ( type ) ;
assert . ok ( type . length > 0 ) ;
var release = os . release ( ) ;
const release = os . release ( ) ;
console . log ( 'release = ' , release ) ;
is . string ( release ) ;
assert . ok ( release . length > 0 ) ;
var platform = os . platform ( ) ;
const platform = os . platform ( ) ;
console . log ( 'platform = ' , platform ) ;
is . string ( platform ) ;
assert . ok ( platform . length > 0 ) ;
var arch = os . arch ( ) ;
const arch = os . arch ( ) ;
console . log ( 'arch = ' , arch ) ;
is . string ( arch ) ;
assert . ok ( arch . length > 0 ) ;
if ( ! common . isSunOS ) {
@ -79,7 +96,7 @@ if (!common.isSunOS) {
}
var interfaces = os . networkInterfaces ( ) ;
const interfaces = os . networkInterfaces ( ) ;
console . error ( interfaces ) ;
switch ( platform ) {
case 'linux' :
@ -104,29 +121,30 @@ switch (platform) {
}
}
var EOL = os . EOL ;
const EOL = os . EOL ;
assert . ok ( EOL . length > 0 ) ;
var home = os . homedir ( ) ;
const home = os . homedir ( ) ;
console . log ( 'homedir = ' + home ) ;
assert . ok ( typeof home === 'string' ) ;
is . string ( home ) ;
assert . ok ( home . indexOf ( path . sep ) !== - 1 ) ;
if ( common . isWindows && process . env . USERPROFILE ) {
assert . e qual( home , process . env . USERPROFILE ) ;
assert . strictE qual( home , process . env . USERPROFILE ) ;
delete process . env . USERPROFILE ;
assert . ok ( os . homedir ( ) . indexOf ( path . sep ) !== - 1 ) ;
process . env . USERPROFILE = home ;
} else if ( ! common . isWindows && process . env . HOME ) {
assert . e qual( home , process . env . HOME ) ;
assert . strictE qual( home , process . env . HOME ) ;
delete process . env . HOME ;
assert . ok ( os . homedir ( ) . indexOf ( path . sep ) !== - 1 ) ;
process . env . HOME = home ;
}
const pwd = os . userInfo ( ) ;
is . object ( pwd ) ;
const pwdBuf = os . userInfo ( { encoding : 'buffer' } ) ;
if ( common . isWindows ) {
@ -137,15 +155,15 @@ if (common.isWindows) {
assert . strictEqual ( pwdBuf . gid , - 1 ) ;
assert . strictEqual ( pwdBuf . shell , null ) ;
} else {
assert . strictEqual ( typeof pwd . uid , 'number' ) ;
assert . strictEqual ( typeof pwd . gid , 'number' ) ;
is . number ( pwd . uid ) ;
is . number ( pwd . gid ) ;
assert . notStrictEqual ( pwd . shell . indexOf ( path . sep ) , - 1 ) ;
assert . strictEqual ( pwd . uid , pwdBuf . uid ) ;
assert . strictEqual ( pwd . gid , pwdBuf . gid ) ;
assert . strictEqual ( pwd . shell , pwdBuf . shell . toString ( 'utf8' ) ) ;
}
assert . strictEqual ( typeof pwd . username , 'string' ) ;
is . string ( pwd . username ) ;
assert . notStrictEqual ( pwd . homedir . indexOf ( path . sep ) , - 1 ) ;
assert . strictEqual ( pwd . username , pwdBuf . username . toString ( 'utf8' ) ) ;
assert . strictEqual ( pwd . homedir , pwdBuf . homedir . toString ( 'utf8' ) ) ;