[Pkg-javascript-commits] [node-string-decoder] 03/11: and correct node version, again
Bastien Roucariès
rouca at moszumanska.debian.org
Sun Aug 13 10:27:58 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to annotated tag v1.0.3
in repository node-string-decoder.
commit bee3d7bddd179cc3fcd9fb8ca25a47b6ee12d517
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Mon May 1 10:40:38 2017 -0400
and correct node version, again
---
README.md | 2 +-
test/common.js | 175 +++++++++++++++++++++++--------
test/parallel/test-string-decoder-end.js | 10 +-
test/parallel/test-string-decoder.js | 14 ++-
4 files changed, 151 insertions(+), 50 deletions(-)
diff --git a/README.md b/README.md
index 1ff6b9b..dc3a2d2 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ npm install --save string_decoder
This package is a mirror of the string_decoder implementation in Node-core.
-Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.0.0/docs/api/).
+Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.8.0/docs/api/).
As of version 1.0.0 **string_decoder** uses semantic versioning.
diff --git a/test/common.js b/test/common.js
index 125c5fd..e879f8e 100644
--- a/test/common.js
+++ b/test/common.js
@@ -8,11 +8,11 @@ var child_process = require('child_process');
var stream = require('stream');
var util = require('util');
var Timer = process.binding('timer_wrap').Timer;
+var execSync = require('child_process').execSync;
-var testRoot = process.env.NODE_TEST_DIR ? path.resolve(process.env.NODE_TEST_DIR) : __dirname;
+var testRoot = process.env.NODE_TEST_DIR ? fs.realpathSync(process.env.NODE_TEST_DIR) : __dirname;
-exports.testDir = __dirname;
-exports.fixturesDir = path.join(exports.testDir, 'fixtures');
+exports.fixturesDir = path.join(__dirname, 'fixtures');
exports.tmpDirName = 'tmp';
// PORT should match the definition in test/testpy/__init__.py.
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
@@ -28,14 +28,15 @@ exports.isOSX = process.platform === 'darwin';
exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */
var cpus = os.cpus();
-exports.enoughTestCpu = cpus.length > 1 || cpus[0].speed > 999;
+exports.enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999);
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
exports.buildType = process.config.target_defaults.default_configuration;
function rimrafSync(p) {
+ var st = void 0;
try {
- var st = fs.lstatSync(p);
+ st = fs.lstatSync(p);
} catch (e) {
if (e.code === 'ENOENT') return;
}
@@ -146,8 +147,8 @@ Object.defineProperty(exports, 'opensslCli', { get: function () {
if (exports.isWindows) opensslCli += '.exe';
- var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
- if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
+ var opensslCmd = child_process.spawnSync(opensslCli, ['version']);
+ if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) {
// openssl command cannot be executed
opensslCli = false;
}
@@ -175,12 +176,6 @@ if (exports.isWindows) {
exports.PIPE = exports.tmpDir + '/test.sock';
}
-if (exports.isWindows) {
- exports.faketimeCli = false;
-} else {
- exports.faketimeCli = path.join(__dirname, '..', 'tools', 'faketime', 'src', 'faketime');
-}
-
var ifaces = os.networkInterfaces();
exports.hasIPv6 = Object.keys(ifaces).some(function (name) {
return (/lo/.test(name) && ifaces[name].some(function (info) {
@@ -189,6 +184,27 @@ exports.hasIPv6 = Object.keys(ifaces).some(function (name) {
);
});
+/*
+ * Check that when running a test with
+ * `$node --abort-on-uncaught-exception $file child`
+ * the process aborts.
+ */
+exports.childShouldThrowAndAbort = function () {
+ var testCmd = '';
+ if (!exports.isWindows) {
+ // Do not create core files, as it can take a lot of disk space on
+ // continuous testing and developers' machines
+ testCmd += 'ulimit -c 0 && ';
+ }
+ testCmd += process.argv[0] + ' --abort-on-uncaught-exception ';
+ testCmd += process.argv[1] + ' child';
+ var child = child_process.exec(testCmd);
+ child.on('exit', function onExit(exitCode, signal) {
+ var errMsg = 'Test should have aborted ' + ('but instead exited with exit code ' + exitCode) + (' and signal ' + signal);
+ assert(exports.nodeProcessAborted(exitCode, signal), errMsg);
+ });
+};
+
exports.ddCommand = function (filename, kilobytes) {
if (exports.isWindows) {
var p = path.resolve(exports.fixturesDir, 'create-file.js');
@@ -198,26 +214,6 @@ exports.ddCommand = function (filename, kilobytes) {
}
};
-exports.spawnCat = function (options) {
- var spawn = require('child_process').spawn;
-
- if (exports.isWindows) {
- return spawn('more', [], options);
- } else {
- return spawn('cat', [], options);
- }
-};
-
-exports.spawnSyncCat = function (options) {
- var spawnSync = require('child_process').spawnSync;
-
- if (exports.isWindows) {
- return spawnSync('more', [], options);
- } else {
- return spawnSync('cat', [], options);
- }
-};
-
exports.spawnPwd = function (options) {
var spawn = require('child_process').spawn;
@@ -241,6 +237,8 @@ exports.spawnSyncPwd = function (options) {
exports.platformTimeout = function (ms) {
if (process.config.target_defaults.default_configuration === 'Debug') ms = 2 * ms;
+ if (global.__coverage__) ms = 4 * ms;
+
if (exports.isAix) return 2 * ms; // default localhost speed is slower on AIX
if (process.arch !== 'arm') return ms;
@@ -254,8 +252,8 @@ exports.platformTimeout = function (ms) {
return ms; // ARMv8+
};
-var knownGlobals = [setTimeout, setInterval, setImmediate, clearTimeout, clearInterval, clearImmediate, console, constructor, // Enumerable in V8 3.21.
-Buffer, process, global];
+var knownGlobals = [Buffer, clearImmediate, clearInterval, clearTimeout, console, constructor, // Enumerable in V8 3.21.
+global, process, setImmediate, setInterval, setTimeout];
if (global.gc) {
knownGlobals.push(global.gc);
@@ -335,8 +333,14 @@ function leakedGlobals() {
var leaked = [];
for (var val in global) {
- if (-1 === knownGlobals.indexOf(global[val])) leaked.push(val);
- }return leaked;
+ if (!knownGlobals.includes(global[val])) leaked.push(val);
+ }if (global.__coverage__) {
+ return leaked.filter(function (varname) {
+ return !/^(cov_|__cov)/.test(varname);
+ });
+ } else {
+ return leaked;
+ }
}
exports.leakedGlobals = leakedGlobals;
@@ -347,8 +351,7 @@ process.on('exit', function () {
if (!exports.globalCheck) return;
var leaked = leakedGlobals();
if (leaked.length > 0) {
- console.error('Unknown globals: %s', leaked);
- assert.ok(false, 'Unknown global found');
+ fail('Unexpected global(s) found: ' + leaked.join(', '));
}
});
@@ -370,7 +373,7 @@ function runCallChecks(exitCode) {
}
exports.mustCall = function (fn, expected) {
- if (typeof expected !== 'number') expected = 1;
+ if (expected === undefined) expected = 1;else if (typeof expected !== 'number') throw new TypeError('Invalid expected value: ' + expected);
var context = {
expected: expected,
@@ -407,8 +410,42 @@ exports.fileExists = function (pathname) {
}
};
-exports.fail = function (msg) {
+exports.canCreateSymLink = function () {
+ // On Windows, creating symlinks requires admin privileges.
+ // We'll only try to run symlink test if we have enough privileges.
+ // On other platforms, creating symlinks shouldn't need admin privileges
+ if (exports.isWindows) {
+ // whoami.exe needs to be the one from System32
+ // If unix tools are in the path, they can shadow the one we want,
+ // so use the full path while executing whoami
+ var whoamiPath = path.join(process.env['SystemRoot'], 'System32', 'whoami.exe');
+
+ var err = false;
+ var output = '';
+
+ try {
+ output = execSync(whoamiPath + ' /priv', { timout: 1000 });
+ } catch (e) {
+ err = true;
+ } finally {
+ if (err || !output.includes('SeCreateSymbolicLinkPrivilege')) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+};
+
+function fail(msg) {
assert.fail(null, null, msg);
+}
+exports.fail = fail;
+
+exports.mustNotCall = function (msg) {
+ return function mustNotCall() {
+ fail(msg || 'function should not have been called');
+ };
};
exports.skip = function (msg) {
@@ -461,9 +498,9 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
// one of them (exit code or signal) needs to be set to one of
// the expected exit codes or signals.
if (signal !== null) {
- return expectedSignals.indexOf(signal) > -1;
+ return expectedSignals.includes(signal);
} else {
- return expectedExitCodes.indexOf(exitCode) > -1;
+ return expectedExitCodes.includes(exitCode);
}
};
@@ -491,4 +528,56 @@ exports.expectWarning = function (name, expected) {
// get each message only once.
expected.splice(expected.indexOf(warning.message), 1);
}, expected.length));
+};
+
+Object.defineProperty(exports, 'hasIntl', {
+ get: function () {
+ return process.binding('config').hasIntl;
+ }
+});
+
+// https://github.com/w3c/testharness.js/blob/master/testharness.js
+exports.WPT = {
+ test: function (fn, desc) {
+ try {
+ fn();
+ } catch (err) {
+ if (err instanceof Error) err.message = 'In ' + desc + ':\n ' + err.message;
+ throw err;
+ }
+ },
+ assert_equals: assert.strictEqual,
+ assert_true: function (value, message) {
+ return assert.strictEqual(value, true, message);
+ },
+ assert_false: function (value, message) {
+ return assert.strictEqual(value, false, message);
+ },
+ assert_throws: function (code, func, desc) {
+ assert.throws(func, function (err) {
+ return typeof err === 'object' && 'name' in err && err.name === code.name;
+ }, desc);
+ },
+ assert_array_equals: assert.deepStrictEqual,
+ assert_unreached: function (desc) {
+ assert.fail(undefined, undefined, 'Reached unreachable code: ' + desc);
+ }
+};
+
+// Useful for testing expected internal/error objects
+exports.expectsError = function expectsError(_ref) {
+ var code = _ref.code,
+ type = _ref.type,
+ message = _ref.message;
+
+ return function (error) {
+ assert.strictEqual(error.code, code);
+ if (type !== undefined) assert(error instanceof type, error + ' is not the expected type ' + type);
+ if (message instanceof RegExp) {
+ assert(message.test(error.message), error.message + ' does not match ' + message);
+ } else if (typeof message === 'string') {
+ assert.strictEqual(error.message, message);
+ }
+ return true;
+ };
};
\ No newline at end of file
diff --git a/test/parallel/test-string-decoder-end.js b/test/parallel/test-string-decoder-end.js
index ab855e5..2c9b5ac 100644
--- a/test/parallel/test-string-decoder-end.js
+++ b/test/parallel/test-string-decoder-end.js
@@ -16,7 +16,7 @@ var bufs = ['☃💩', 'asdf'].map(function (b) {
// also test just arbitrary bytes from 0-15.
for (var i = 1; i <= 16; i++) {
- var bytes = new Array(i).join('.').split('.').map(function (_, j) {
+ var bytes = '.'.repeat(i - 1).split('.').map(function (_, j) {
return j + 0x78;
});
bufs.push(bufferShim.from(bytes));
@@ -38,8 +38,8 @@ function testBuf(encoding, buf) {
// write one byte at a time.
var s = new SD(encoding);
var res1 = '';
- for (var i = 0; i < buf.length; i++) {
- res1 += s.write(buf.slice(i, i + 1));
+ for (var _i = 0; _i < buf.length; _i++) {
+ res1 += s.write(buf.slice(_i, _i + 1));
}
res1 += s.end();
@@ -55,6 +55,6 @@ function testBuf(encoding, buf) {
console.log('expect=%j', res3);
console.log('res1=%j', res1);
console.log('res2=%j', res2);
- assert.equal(res1, res3, 'one byte at a time should match toString');
- assert.equal(res2, res3, 'all bytes at once should match toString');
+ assert.strictEqual(res1, res3, 'one byte at a time should match toString');
+ assert.strictEqual(res2, res3, 'all bytes at once should match toString');
}
\ No newline at end of file
diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js
index 6944773..61d6534 100644
--- a/test/parallel/test-string-decoder.js
+++ b/test/parallel/test-string-decoder.js
@@ -82,6 +82,10 @@ assert.strictEqual(decoder.write(bufferShim.from('F1', 'hex')), '');
assert.strictEqual(decoder.write(bufferShim.from('41F2', 'hex')), '\ufffdA');
assert.strictEqual(decoder.end(), '\ufffd');
+// Additional utf8Text test
+decoder = new StringDecoder('utf8');
+assert.strictEqual(decoder.text(bufferShim.from([0x41]), 2), '');
+
// Additional UTF-16LE surrogate pair tests
decoder = new StringDecoder('utf16le');
assert.strictEqual(decoder.write(bufferShim.from('3DD8', 'hex')), '');
@@ -98,13 +102,21 @@ assert.strictEqual(decoder.write(bufferShim.from('3DD8', 'hex')), '');
assert.strictEqual(decoder.write(bufferShim.from('4D', 'hex')), '');
assert.strictEqual(decoder.end(), '\ud83d');
+assert.throws(function () {
+ new StringDecoder(1);
+}, /^Error: Unknown encoding: 1$/);
+
+assert.throws(function () {
+ new StringDecoder('test');
+}, /^Error: Unknown encoding: test$/);
+
// test verifies that StringDecoder will correctly decode the given input
// buffer with the given encoding to the expected output. It will attempt all
// possible ways to write() the input buffer, see writeSequences(). The
// singleSequence allows for easy debugging of a specific sequence which is
// useful in case of test failures.
function test(encoding, input, expected, singleSequence) {
- var sequences;
+ var sequences = void 0;
if (!singleSequence) {
sequences = writeSequences(input.length);
} else {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-string-decoder.git
More information about the Pkg-javascript-commits
mailing list