node/test/parallel/test-process-getgroups.js
Jeremiah Senkpiel 52bae222a3 test: abstract skip functionality to common
The tap skipping output is so prevalent yet obscure in nature that we
ought to move it into it's own function in test/common.js

PR-URL: https://github.com/nodejs/node/pull/6697
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2016-05-12 16:43:35 -04:00

27 lines
722 B
JavaScript

'use strict';
const common = require('../common');
var assert = require('assert');
var exec = require('child_process').exec;
if (process.platform === 'darwin') {
common.skip('Output of `id -G` is unreliable on Darwin.');
return;
}
if (typeof process.getgroups === 'function') {
var groups = process.getgroups();
assert(Array.isArray(groups));
assert(groups.length > 0);
exec('id -G', function(err, stdout) {
if (err) throw err;
var real_groups = stdout.match(/\d+/g).map(Number);
assert.equal(groups.length, real_groups.length);
check(groups, real_groups);
check(real_groups, groups);
});
}
function check(a, b) {
for (var i = 0; i < a.length; ++i) assert(b.indexOf(a[i]) !== -1);
}