2009-11-01 02:02:30 +08:00
|
|
|
var path = require("path");
|
|
|
|
|
|
|
|
exports.testDir = path.dirname(__filename);
|
|
|
|
exports.fixturesDir = path.join(exports.testDir, "fixtures");
|
2010-02-26 04:01:23 +08:00
|
|
|
exports.libDir = path.join(exports.testDir, "../lib");
|
2010-09-09 09:42:32 +08:00
|
|
|
exports.tmpDir = path.join(exports.testDir, "tmp");
|
2010-02-27 04:06:32 +08:00
|
|
|
exports.PORT = 12346;
|
2009-09-21 00:19:33 +08:00
|
|
|
|
2010-07-14 07:40:54 +08:00
|
|
|
exports.assert = require('assert');
|
|
|
|
|
2010-10-12 05:04:09 +08:00
|
|
|
var util = require("util");
|
|
|
|
for (var i in util) exports[i] = util[i];
|
2010-08-17 23:21:43 +08:00
|
|
|
//for (var i in exports) global[i] = exports[i];
|
|
|
|
|
|
|
|
function protoCtrChain (o) {
|
|
|
|
var result = [];
|
|
|
|
for (; o; o = o.__proto__) { result.push(o.constructor); }
|
|
|
|
return result.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.indirectInstanceOf = function (obj, cls) {
|
|
|
|
if (obj instanceof cls) { return true; }
|
|
|
|
var clsChain = protoCtrChain(cls.prototype);
|
|
|
|
var objChain = protoCtrChain(obj);
|
|
|
|
return objChain.slice(-clsChain.length) === clsChain;
|
|
|
|
};
|
2010-12-05 05:40:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Turn this off if the test should not check for global leaks.
|
|
|
|
exports.globalCheck = true;
|
|
|
|
|
|
|
|
process.on('exit', function () {
|
|
|
|
if (!exports.globalCheck) return;
|
|
|
|
var knownGlobals = [ setTimeout,
|
|
|
|
setInterval,
|
|
|
|
clearTimeout,
|
|
|
|
clearInterval,
|
|
|
|
console,
|
|
|
|
Buffer,
|
|
|
|
process,
|
|
|
|
global ];
|
|
|
|
|
|
|
|
for (var x in global) {
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
for (var y in knownGlobals) {
|
|
|
|
if (global[x] === knownGlobals[y]) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
console.error("Unknown global: %s", x);
|
|
|
|
exports.assert.ok(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|