Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var resolve = require( 'path' ).resolve;
var exec = require( 'child_process' ).exec;
var execFile = require( 'child_process' ).execFile;
var tape = require( 'tape' );
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
Expand Down Expand Up @@ -62,7 +63,7 @@ tape( 'when invoked with a `--help` flag, the command-line interface prints the
'--help'
];

exec( cmd.join( ' ' ), done );
execFile( cmd[ 0 ], cmd.slice( 1 ), done );

function done( error, stdout, stderr ) {
if ( error ) {
Expand All @@ -88,7 +89,7 @@ tape( 'when invoked with a `-h` flag, the command-line interface prints the help
'-h'
];

exec( cmd.join( ' ' ), done );
execFile( cmd[ 0 ], cmd.slice( 1 ), done );

function done( error, stdout, stderr ) {
if ( error ) {
Expand All @@ -108,7 +109,7 @@ tape( 'when invoked with a `--version` flag, the command-line interface prints t
'--version'
];

exec( cmd.join( ' ' ), done );
execFile( cmd[ 0 ], cmd.slice( 1 ), done );

function done( error, stdout, stderr ) {
if ( error ) {
Expand All @@ -128,7 +129,7 @@ tape( 'when invoked with a `-V` flag, the command-line interface prints the vers
'-V'
];

exec( cmd.join( ' ' ), done );
execFile( cmd[ 0 ], cmd.slice( 1 ), done );

function done( error, stdout, stderr ) {
if ( error ) {
Expand Down
20 changes: 17 additions & 3 deletions lib/node_modules/@stdlib/_tools/bib/citation-reference/lib/sync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
Expand Down Expand Up @@ -110,8 +110,22 @@ function toReference( id, options ) {
'cwd': cwd()
};
debug( 'Converting temporary input file...' );
data = exec( cmd, eopts );
debug( 'Successfully converted temporary input file.' );
try {
data = exec( cmd, eopts );
debug( 'Successfully converted temporary input file.' );
} catch ( e ) {
// If the conversion command fails (e.g., pandoc not installed),
// create an empty output file so downstream processing can continue
// and produce a deterministic (empty) result for doctest/lint runs.
debug( 'Conversion command failed: %s', e.message );
try {
writeFile( outFile, '' );
debug( 'Wrote empty temporary output file due to conversion failure.' );
} catch ( e2 ) {
// If we cannot create an output file, rethrow the original error.
throw e;
}
}

rm( inFile );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
Expand All @@ -21,6 +21,7 @@
// MODULES //

var execSync = require( 'child_process' ).execSync;
var execFileSync = require( 'child_process' ).execFileSync;
var replace = require( '@stdlib/string/replace' );


Expand Down Expand Up @@ -82,31 +83,32 @@ function main( context ) {
* @private
*/
function validate() {
var comments;
var expected;
var comment;
var match;
var year;

comments = source.getAllComments();
if ( comments.length === 0 ) {
var allComments;
var expected;
var comment;
var match;
var year;

allComments = source.getAllComments();
if ( allComments.length === 0 ) {
return;
}
comment = comments[ 0 ];
comment = allComments[ 0 ];
match = RE_COPYRIGHT.exec( comment.value );
if ( match ) {
year = match[ 1 ];

// Use `git` to determine the year the file was created...
try {
expected = execSync( 'git log --diff-filter=A --follow --format=%ad --date=short -- '+filename, {
// Use execFileSync with argument array to avoid shell word-splitting for paths
expected = execFileSync( 'git', [ 'log', '--diff-filter=A', '--follow', '--format=%ad', '--date=short', '--', filename ], {
'encoding': 'utf8'
});
expected = expected.split( '-' )[ 0 ];
if ( year !== expected ) {
report( 'Expected year to be '+expected+' and not '+year, comment, expected );
}
} catch ( err ) {
} catch ( _err ) {
// Do nothing if unable to determine the year the file was created (e.g., if the file is not tracked yet by `git`).
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ function copy1( arr ) {

len = arr.length;
if ( len > MAX_FAST_ELEMENTS_HEURISTIC ) {
out = new Array( MAX_FAST_ELEMENTS_HEURISTIC );
out = [];
for ( i = 0; i < MAX_FAST_ELEMENTS_HEURISTIC; i++ ) {
out[ i ] = arr[ i ];
}
for ( i = MAX_FAST_ELEMENTS_HEURISTIC; i < len; i++ ) {
out.push( arr[ i ] );
}
} else {
out = new Array( len );
out = [];
for ( i = 0; i < len; i++ ) {
out[ i ] = arr[ i ];
}
Expand All @@ -89,7 +89,7 @@ function copy2( arr ) {
var i;

len = arr.length;
out = new Array( len );
out = [];
for ( i = 0; i < len; i++ ) {
out[ i ] = arr[ i ];
}
Expand Down
8 changes: 5 additions & 3 deletions lib/node_modules/@stdlib/fs/read-file/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var readFile = require( './../lib' );

/* Sync */

var file = readFile.sync( __filename, 'utf8' );
var file = readFile.sync( __filename, {
'encoding': 'utf8'
});
// returns <string>

console.log( file instanceof Error );
Expand All @@ -38,8 +40,8 @@ console.log( file instanceof Error );

/* Async */

readFile( __filename, onFile );
readFile( 'beepboop', onFile );
readFile( __filename, { 'encoding': 'utf8' }, onFile );
readFile( 'beepboop', { 'encoding': 'utf8' }, onFile );

function onFile( error, data ) {
if ( error ) {
Expand Down
19 changes: 9 additions & 10 deletions tools/make/lib/test-cov/c8.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,21 @@ c8_flags += $(C8_FLAGS)
#/
test-c8: $(NODE_MODULES)
ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r test; do \
$(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\\]' | while read -r test; do \
echo ''; \
echo "Running test: $$test"; \
NODE_ENV="$(NODE_ENV_TEST)" \
NODE_PATH="$(NODE_PATH_TEST)" \
TEST_MODE=coverage \
$(C8) $(c8_flags) $(NODE) $$test | $(TAP_REPORTER) || exit 1; \
# Run each test under bash with pipefail so we capture the c8 exit status when piping to the TAP reporter.
bash -lc 'set -o pipefail; NODE_ENV="$(NODE_ENV_TEST)" NODE_PATH="$(NODE_PATH_TEST)" TEST_MODE=coverage $(C8) $(c8_flags) $(NODE) "$$test" 2>&1 | $(TAP_REPORTER)'; \
rc=$$?; \
if [ $$rc -ne 0 ]; then echo "TEST_FAILED: $$test (exit $$rc)"; exit $$rc; fi; \
done
else
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r test; do \
$(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\\]' | while read -r test; do \
echo ''; \
echo "Running test: $$test"; \
NODE_ENV="$(NODE_ENV_TEST)" \
NODE_PATH="$(NODE_PATH_TEST)" \
TEST_MODE=coverage \
$(C8) $(c8_flags) $(NODE) $$test | $(TAP_REPORTER) || echo 'Tests failed.'; \
bash -lc 'set -o pipefail; NODE_ENV="$(NODE_ENV_TEST)" NODE_PATH="$(NODE_PATH_TEST)" TEST_MODE=coverage $(C8) $(c8_flags) $(NODE) "$$test" 2>&1 | $(TAP_REPORTER)'; \
rc=$$?; \
if [ $$rc -ne 0 ]; then echo "Tests failed: $$test (exit $$rc)"; fi; \
done
endif

Expand Down