| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6618df commit 825842c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,23 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | - const assert = require('assert'); | ||
| 4 | - const exec = require('child_process').exec; | ||
| 3 | + | ||
| 4 | + // Check `id -G` and `process.getgroups()` return same groups. | ||
| 5 | 5 | ||
| 6 | 6 | if (common.isOSX) { | |
| 7 | 7 | common.skip('Output of `id -G` is unreliable on Darwin.'); | |
| 8 | 8 | return; | |
| 9 | 9 | } | |
| 10 | + const assert = require('assert'); | ||
| 11 | + const exec = require('child_process').exec; | ||
| 10 | 12 | ||
| 11 | 13 | if (typeof process.getgroups === 'function') { | |
| 12 | - const groups = process.getgroups(); | ||
| 14 | + const groups = unique(process.getgroups()); | ||
| 13 | 15 | assert(Array.isArray(groups)); | |
| 14 | 16 | assert(groups.length > 0); | |
| 15 | 17 | exec('id -G', function(err, stdout) { | |
| 16 | 18 | assert.ifError(err); | |
| 17 | - const real_groups = stdout.match(/\d+/g).map(Number); | ||
| 18 | - assert.strictEqual(groups.length, real_groups.length); | ||
| 19 | + const real_groups = unique(stdout.match(/\d+/g).map(Number)); | ||
| 20 | + assert.deepStrictEqual(groups, real_groups); | ||
| 19 | 21 | check(groups, real_groups); | |
| 20 | 22 | check(real_groups, groups); | |
| 21 | 23 | }); | |
@@ -24,3 +26,7 @@ if (typeof process.getgroups === 'function') { | |||
| 24 | 26 | function check(a, b) { | |
| 25 | 27 | for (let i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1); | |
| 26 | 28 | } | |
| 29 | + | ||
| 30 | + function unique(groups) { | ||
| 31 | + return [...new Set(groups)].sort(); | ||
| 32 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments