Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
test: Fixed unittest for Chakra engine
Browse files Browse the repository at this point in the history
There were certain unittest that depends specifically on v8 internals and/or
engine specific error message. This change adds if-else to expect different
error message for Chakra engine or skip running test case if it test v8
internals not present in Chakra or if it test features unimplemented by
chakrashim.

Modified test python script to take engine name depending on which it
will match the baselines for v8 vs. chakracore engine.
  • Loading branch information
kunalspathak committed Feb 11, 2016
1 parent 73d9093 commit 42bc284
Show file tree
Hide file tree
Showing 51 changed files with 282 additions and 68 deletions.
6 changes: 6 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports.libDir = path.join(exports.testDir, '../lib');
exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
exports.isWindows = process.platform === 'win32';
exports.isChakraEngine = process.jsEngine === 'chakracore';
exports.isAix = process.platform === 'aix';
exports.isLinuxPPCBE = (process.platform === 'linux') &&
(process.arch === 'ppc64') &&
Expand Down Expand Up @@ -517,3 +518,8 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
return expectedExitCodes.indexOf(exitCode) > -1;
}
};

exports.engineSpecificMessage = function(messageObject) {
var jsEngine = process.jsEngine || 'v8'; //default is 'v8'
return messageObject[jsEngine];
};
11 changes: 11 additions & 0 deletions test/message/core_line_numbers.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RangeError: Invalid input
at error (punycode.js:67:*)
at decode (punycode.js:*:*)
at Anonymous function (*test*message*core_line_numbers.js:*:*)
at Module.prototype._compile (module.js:*:*)
at Module._extensions[.js] (module.js:*:*)
at Module.prototype.load (module.js:*:*)
at Module._load (module.js:*:*)
at Module.runMain (module.js:*:*)
at startup (node.js:*:*)
at Anonymous function (node.js:*:*)
File renamed without changes.
8 changes: 8 additions & 0 deletions test/message/error_exit.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Exiting with code=1
AssertionError: 1 == 2
at Anonymous function (*test*message*error_exit.js:*:*)
at Module.prototype._compile (module.js:*:*)
at Module._extensions[.js] (module.js:*:*)
at Module.prototype.load (module.js:*:*)
at Module._load (module.js:*:*)
at Module.runMain (module.js:*:*)
File renamed without changes.
7 changes: 7 additions & 0 deletions test/message/nexttick_throw.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ReferenceError: 'undefined_reference_error_maker' is undefined
at Anonymous function (*test*message*nexttick_throw.js:*:*)
at nextTickCallbackWith0Args (node.js:*:*)
at _tickCallback (node.js:*:*)
at Module.runMain (module.js:*:*)
at startup (node.js:*:*)
at Anonymous function (node.js:*:*)
File renamed without changes.
2 changes: 2 additions & 0 deletions test/message/stack_overflow.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
before
Error: Out of stack space
File renamed without changes.
13 changes: 9 additions & 4 deletions test/message/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class MessageTestConfiguration(test.TestConfiguration):

def __init__(self, context, root):
super(MessageTestConfiguration, self).__init__(context, root)
self.engine = context.engine

def Ls(self, path):
if isdir(path):
Expand All @@ -125,11 +126,15 @@ def ListTests(self, current_path, path, arch, mode):
if self.Contains(path, test):
file_prefix = join(self.root, reduce(join, test[1:], ""))
file_path = file_prefix + ".js"
engine_output_path = file_prefix + (".%s.out" % self.engine)
output_path = file_prefix + ".out"
if not exists(output_path):
print "Could not find %s" % output_path
continue
result.append(MessageTestCase(test, file_path, output_path,
if exists(engine_output_path):
output_path = engine_output_path
else:
if not exists(output_path):
print "Could not find %s or %s" % (output_path, engine_output_path)
continue
result.append(MessageTestCase(test, file_path, output_path,
arch, mode, self.context, self))
return result

Expand Down
1 change: 1 addition & 0 deletions test/message/throw_custom_error.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MyCustomError: This is a custom message
2 changes: 2 additions & 0 deletions test/message/throw_in_line_with_tabs.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
before
[object Object]
1 change: 1 addition & 0 deletions test/message/throw_non_error.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[object Object]
File renamed without changes.
1 change: 1 addition & 0 deletions test/message/throw_null.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
File renamed without changes.
1 change: 1 addition & 0 deletions test/message/throw_undefined.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
undefined
File renamed without changes.
3 changes: 3 additions & 0 deletions test/message/timeout_throw.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ReferenceError: 'undefined_reference_error_maker' is undefined
at Anonymous function (*test*message*timeout_throw.js:*:*)
at listOnTimeout (timers.js:*:*)
File renamed without changes.
12 changes: 12 additions & 0 deletions test/message/undefined_reference_in_new_context.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
before
TypeError: Unable to set property 'bar' of undefined or null reference
at Global code (evalmachine.<anonymous>:1:1)
at Script.prototype.runInNewContext (vm.js:*)
at exports.runInNewContext (vm.js:*)
at Anonymous function (*test*message*undefined_reference_in_new_context.js:*)
at Module.prototype._compile (module.js:*:*)
at Module._extensions[.js] (module.js:*:*)
at Module.prototype.load (module.js:*:*)
at Module._load (module.js:*:*)
at Module.runMain (module.js:*:*)
at startup (node.js:*:*)
11 changes: 11 additions & 0 deletions test/message/vm_display_syntax_error.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
beginning
SyntaxError: Expected identifier
at exports.runInThisContext (vm.js:*)
at Anonymous function (*test*message*vm_display_syntax_error.js:*)
at Module.prototype._compile (module.js:*)
at Module._extensions[.js] (module.js:*)
at Module.prototype.load (module.js:*)
at Module._load (module.js:*)
at Module.runMain (module.js:*)
at startup (node.js:*)
at Anonymous function (node.js:*)
12 changes: 12 additions & 0 deletions test/message/vm_dont_display_syntax_error.chakracore.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
beginning
middle
SyntaxError: Expected identifier
at exports.runInThisContext (vm.js:*)
at Anonymous function (*test*message*vm_dont_display_syntax_error.js:*)
at Module.prototype._compile (module.js:*)
at Module._extensions[.js] (module.js:*)
at Module.prototype.load (module.js:*)
at Module._load (module.js:*)
at Module.runMain (module.js:*)
at startup (node.js:*)
at Anonymous function (node.js:*)
17 changes: 12 additions & 5 deletions test/parallel/test-buffer-slow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const buffer = require('buffer');
const Buffer = buffer.Buffer;
Expand Down Expand Up @@ -30,7 +30,10 @@ assert.strictEqual(SlowBuffer(0).length, 0);
try {
assert.strictEqual(SlowBuffer(buffer.kMaxLength).length, buffer.kMaxLength);
} catch (e) {
assert.equal(e.message, 'Invalid array buffer length');
assert.equal(e.message, common.engineSpecificMessage({
v8 : 'Invalid array buffer length',
chakracore : 'Invalid offset/length when creating typed array'
}));
}

// should work with number-coercible values
Expand All @@ -44,12 +47,16 @@ assert.strictEqual(SlowBuffer({}).length, 0);
assert.strictEqual(SlowBuffer('string').length, 0);

// should throw with invalid length
var expectedError = common.engineSpecificMessage({
v8 : 'invalid Buffer length',
chakracore : 'Invalid offset/length when creating typed array'
});
assert.throws(function() {
new SlowBuffer(Infinity);
}, 'invalid Buffer length');
}, expectedError);
assert.throws(function() {
new SlowBuffer(-1);
}, 'invalid Buffer length');
}, expectedError);
assert.throws(function() {
new SlowBuffer(buffer.kMaxLength + 1);
}, 'invalid Buffer length');
}, expectedError);
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-double-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var assert = require('assert'),
spawn = require('child_process').spawn;

// We're trying to reproduce:
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/O/

var grep, sed, echo;

Expand Down
32 changes: 24 additions & 8 deletions test/parallel/test-child-process-fork-exec-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,54 @@ var fs = require('fs');
var path = require('path');
var common = require('../common');
var msg = {test: 'this'};
var nodePath = process.execPath;
var copyPath = path.join(common.tmpDir, 'node-copy.exe');
var nodeCopyPath = path.join(common.tmpDir, 'node-copy.exe');
var chakracoreCopyPath = path.join(common.tmpDir, 'chakracore.dll');
var exePaths = [
{srcPath : process.execPath,
destPath : nodeCopyPath}];
if (common.isChakraEngine) {
// chakra needs chakracore.dll as well
exePaths.push(
{srcPath : process.execPath.replace('node.exe', 'chakracore.dll'),
destPath : chakracoreCopyPath});
}

if (process.env.FORK) {
assert(process.send);
assert.equal(process.argv[0], copyPath);
assert.equal(process.argv[0], nodeCopyPath);
process.send(msg);
process.exit();
}
else {
common.refreshTmpDir();
try {
fs.unlinkSync(copyPath);
exePaths.forEach(function(value) {
fs.unlinkSync(value.destPath);
});
}
catch (e) {
if (e.code !== 'ENOENT') throw e;
}
fs.writeFileSync(copyPath, fs.readFileSync(nodePath));
fs.chmodSync(copyPath, '0755');

exePaths.forEach(function(value) {
fs.writeFileSync(value.destPath, fs.readFileSync(value.srcPath));
fs.chmodSync(value.destPath, '0755');
});

// slow but simple
var envCopy = JSON.parse(JSON.stringify(process.env));
envCopy.FORK = 'true';
var child = require('child_process').fork(__filename, {
execPath: copyPath,
execPath: nodeCopyPath,
env: envCopy
});
child.on('message', common.mustCall(function(recv) {
assert.deepEqual(msg, recv);
}));
child.on('exit', common.mustCall(function(code) {
fs.unlinkSync(copyPath);
exePaths.forEach(function(value) {
fs.unlinkSync(value.destPath);
});
assert.equal(code, 0);
}));
}
5 changes: 4 additions & 1 deletion test/parallel/test-cli-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ var syntaxArgs = [
assert.equal(c.stdout, '', 'stdout produced');

// stderr should have a syntax error message
var match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m);
var match = c.stderr.match(common.engineSpecificMessage({
v8: /^SyntaxError: Unexpected identifier$/m,
chakracore: /^SyntaxError: Expected ';'$/m})
);
assert(match, 'stderr incorrect');

assert.equal(c.status, 1, 'code == ' + c.status);
Expand Down
12 changes: 9 additions & 3 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
var common = require('../common');
var assert = require('assert');

assert.ok(process.stdout.writable);
Expand All @@ -25,6 +25,12 @@ var strings = [];
global.process.stdout.write = function(string) {
strings.push(string);
};

var expectedFuncToString = common.engineSpecificMessage({
v8 : "{ foo: 'bar', inspect: [Function] }\n",
chakracore : "{ foo: 'bar', inspect: [Function: inspect] }\n"
});

console._stderr = process.stdout;

// test console.log()
Expand Down Expand Up @@ -72,8 +78,8 @@ assert.equal('foo bar\n', strings.shift());
assert.equal('foo bar hop\n', strings.shift());
assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift());
assert.equal('inspect\n', strings.shift());
assert.equal("{ foo: 'bar', inspect: [Function] }\n", strings.shift());
assert.equal("{ foo: 'bar', inspect: [Function] }\n", strings.shift());
assert.equal(expectedFuncToString, strings.shift());
assert.equal(expectedFuncToString, strings.shift());
assert.notEqual(-1, strings.shift().indexOf('foo: [Object]'));
assert.equal(-1, strings.shift().indexOf('baz'));
assert.equal('Trace: This is a {"formatted":"trace"} 10 foo',
Expand Down
10 changes: 8 additions & 2 deletions test/parallel/test-domain.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
// Simple tests of most basic domain functionality.

require('../common');
var common = require('../common');
var assert = require('assert');
var domain = require('domain');
var events = require('events');
Expand Down Expand Up @@ -29,6 +29,12 @@ d.on('error', function(er) {
}
}

const typeErrMsg = common.engineSpecificMessage({
v8 : "Cannot read property 'isDirectory' of undefined",
chakracore : "Unable to get property 'isDirectory' of undefined or\
null reference"
});

switch (er_message) {
case 'emitted':
assert.equal(er.domain, d);
Expand Down Expand Up @@ -84,7 +90,7 @@ d.on('error', function(er) {
assert.ok(!er.domainBound);
break;

case 'Cannot read property \'isDirectory\' of undefined':
case typeErrMsg:
assert.equal(er.domain, d);
assert.ok(!er.domainEmitter);
assert.ok(!er.domainBound);
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ function errExec(script, callback) {
// There was some error
assert.ok(err);

// More than one line of error output.
assert.ok(stderr.split('\n').length > 2);
if (!common.isChakraEngine) {
// More than one line of error output. (not necessarily for chakra engine)
assert.ok(stderr.split('\n').length > 2);
}

// Assert the script is mentioned in error output.
assert.ok(stderr.indexOf(script) >= 0);
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-fs-read-buffer-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const stream = fs.createWriteStream(file, {
});

const size = kStringMaxLength / 200;
const a = new Buffer(size).fill('a');

const a = new Buffer(common.isChakraEngine ? Math.round(size) : size).fill('a');

for (var i = 0; i < 201; i++) {
stream.write(a);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const stream = fs.createWriteStream(file, {
});

const size = kStringMaxLength / 200;
const a = new Buffer(size).fill('a');
const a = new Buffer(common.isChakraEngine ? Math.round(size) : size).fill('a');

for (var i = 0; i < 201; i++) {
stream.write(a);
Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-intl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';
require('../common');
var common = require('../common');
var assert = require('assert');

// does node think that i18n was enabled?
var enablei18n = process.config.variables.v8_enable_i18n_support;
// for chakra i18n is enabled
var enablei18n = common.engineSpecificMessage({
v8 : process.config.variables.v8_enable_i18n_support,
chakracore : true
});

if (enablei18n === undefined) {
enablei18n = false;
}
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var common = require('../common');
var assert = require('assert');

var expected_keys = ['ares', 'http_parser', 'modules', 'node',
'uv', 'v8', 'zlib'];
'uv', 'zlib'];
expected_keys.push(process.jsEngine);

if (common.hasCrypto) {
expected_keys.push('openssl');
}

if (typeof Intl !== 'undefined') {
if (!common.isChakraEngine && typeof Intl !== 'undefined') {
expected_keys.push('icu');
}

Expand Down

0 comments on commit 42bc284

Please sign in to comment.