Skip to content

Commit 2745530

Browse files
committed
Sniff umask behavior
This commit attempts to detect "anomalous" process.umask behavior. In certain environments on Windows, process.umask does not exhibit expected behavior; e.g., failing to set a new mask. Here, we add a script to try and detect deviant behavior and skip tests if this behavior is detected. This allows us to avoid failing builds on, e.g., AppVeyor. - https://ci.appveyor.com/project/kgryte/stdlib/build/job/7o6qgf25sovv9bea
1 parent 35c7a6b commit 2745530

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Checks whether the built-in `process.umask` exhibits expected behavior.
25+
*
26+
* ## Notes
27+
*
28+
* - In certain environments on Windows, `process.umask` does not seem to behave as expected (e.g., a mask cannot be set). This function is indicated to "sniff" this behavior.
29+
*
30+
* @private
31+
* @returns {boolean} boolean indicating whether `process.umask` exhibits expected behavior
32+
*/
33+
function check() {
34+
var MASK;
35+
var mask;
36+
var bool;
37+
var old;
38+
var i;
39+
40+
MASK = process.umask();
41+
bool = true;
42+
43+
for ( i = 100; i < 200; i++ ) {
44+
old = process.umask();
45+
46+
// Should return an integer-valued number:
47+
if ( typeof old !== 'number' ) {
48+
bool = false;
49+
break;
50+
}
51+
52+
// Attempt to update the mask:
53+
mask = process.umask( i );
54+
55+
// Should have returned the previous mask:
56+
if ( mask !== old ) {
57+
bool = false;
58+
break;
59+
}
60+
// Should return the current mask:
61+
if ( process.umask() !== i ) {
62+
bool = false;
63+
break;
64+
}
65+
}
66+
process.umask( MASK ); // restore
67+
return bool;
68+
}
69+
70+
71+
// EXPORTS //
72+
73+
module.exports = check;

lib/node_modules/@stdlib/process/umask/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
25+
var check = require( './fixtures/check_umask.js' );
2526
var umask = require( './../lib' );
2627

2728

@@ -36,7 +37,7 @@ var INT_TO_SYMBOLIC = int2symbolic();
3637
var SYMBOLIC_TO_INT = symbolic2int();
3738
var MASK = umask();
3839
var opts = {
39-
'skip': IS_BROWSER
40+
'skip': IS_BROWSER || check()
4041
};
4142

4243

0 commit comments

Comments
 (0)