Skip to content

Commit

Permalink
[test] Upgrade common.js from node core
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Oct 28, 2012
1 parent 3d61877 commit fefbf04
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions test/core/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.tmpDir = path.join(exports.testDir, 'tmp');
exports.PORT = 12346;
exports.PROXY_PORT = 1234567;

if (process.platform == 'win32') {
if (process.platform === 'win32') {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
Expand All @@ -54,9 +54,10 @@ exports.indirectInstanceOf = function(obj, cls) {


exports.ddCommand = function(filename, kilobytes) {
if (process.platform == 'win32') {
return '"' + process.argv[0] + '" "' + path.resolve(exports.fixturesDir,
'create-file.js') + '" "' + filename + '" ' + (kilobytes * 1024);
if (process.platform === 'win32') {
var p = path.resolve(exports.fixturesDir, 'create-file.js');
return '"' + process.argv[0] + '" "' + p + '" "' +
filename + '" ' + (kilobytes * 1024);
} else {
return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
}
Expand All @@ -66,7 +67,7 @@ exports.ddCommand = function(filename, kilobytes) {
exports.spawnPwd = function(options) {
var spawn = require('child_process').spawn;

if (process.platform == 'win32') {
if (process.platform === 'win32') {
return spawn('cmd.exe', ['/c', 'cd'], options);
} else {
return spawn('pwd', [], options);
Expand All @@ -81,8 +82,10 @@ process.on('exit', function() {
if (!exports.globalCheck) return;
var knownGlobals = [setTimeout,
setInterval,
setImmediate,
clearTimeout,
clearInterval,
clearImmediate,
console,
Buffer,
process,
Expand Down Expand Up @@ -111,6 +114,7 @@ process.on('exit', function() {
knownGlobals.push(ArrayBuffer);
knownGlobals.push(Int8Array);
knownGlobals.push(Uint8Array);
knownGlobals.push(Uint8ClampedArray);
knownGlobals.push(Int16Array);
knownGlobals.push(Uint16Array);
knownGlobals.push(Int32Array);
Expand Down Expand Up @@ -138,8 +142,43 @@ process.on('exit', function() {
});


// This function allows one two run an HTTP test agaist both HTTPS and
// normal HTTP modules. This ensures they fit the same API.
exports.httpTest = function httpTest(cb) {
};
var mustCallChecks = [];


function runCallChecks() {
var failed = mustCallChecks.filter(function(context) {
return context.actual !== context.expected;
});

failed.forEach(function(context) {
console.log('Mismatched %s function calls. Expected %d, actual %d.',
context.name,
context.expected,
context.actual);
console.log(context.stack.split('\n').slice(2).join('\n'));
});

if (failed.length) process.exit(1);
}


exports.mustCall = function(fn, expected) {
if (typeof expected !== 'number') expected = 1;

var context = {
expected: expected,
actual: 0,
stack: (new Error).stack,
name: fn.name || '<anonymous>'
};

// add the exit listener only once to avoid listener leak warnings
if (mustCallChecks.length === 0) process.on('exit', runCallChecks);

mustCallChecks.push(context);

return function() {
context.actual++;
return fn.apply(this, arguments);
};
};

0 comments on commit fefbf04

Please sign in to comment.