diff --git a/test/common.js b/test/common.js index 03d4cbccc9..bce2f45315 100644 --- a/test/common.js +++ b/test/common.js @@ -9,4 +9,17 @@ exports.assert = require('assert'); var sys = require("sys"); for (var i in sys) exports[i] = sys[i]; -for (var i in exports) global[i] = exports[i]; +//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; +}; diff --git a/test/disabled/test-http-big-proxy-responses.js b/test/disabled/test-http-big-proxy-responses.js index d569b76d40..7026d56db5 100644 --- a/test/disabled/test-http-big-proxy-responses.js +++ b/test/disabled/test-http-big-proxy-responses.js @@ -13,7 +13,7 @@ var chargen = http.createServer(function (req, res) { assert.ok(len > 0); res.writeHead(200, {"transfer-encoding":"chunked"}); for (var i=0; i 1); assert.equal("\n", result[result.length-1]); }); diff --git a/test/simple/test-child-process-exec-env.js b/test/simple/test-child-process-exec-env.js index d4cd989a31..cc8d2f9873 100644 --- a/test/simple/test-child-process-exec-env.js +++ b/test/simple/test-child-process-exec-env.js @@ -1,4 +1,5 @@ -require('../common'); +common = require('../common'); +assert = common.assert; var exec = require('child_process').exec, sys = require('sys'); success_count = 0; diff --git a/test/simple/test-exec.js b/test/simple/test-exec.js index 727fd1fae6..c37d0ddcd9 100644 --- a/test/simple/test-exec.js +++ b/test/simple/test-exec.js @@ -13,7 +13,7 @@ exec("ls /", function (err, stdout, stderr) { assert.equal(false, err.killed); } else { success_count++; - p(stdout); + common.p(stdout); } }); @@ -30,7 +30,7 @@ exec("ls /DOES_NOT_EXIST", function (err, stdout, stderr) { console.log("stderr: " + JSON.stringify(stderr)); } else { success_count++; - p(stdout); + common.p(stdout); assert.equal(true, stdout != ""); } }); diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js index e97e553f8a..7ff4ea5300 100644 --- a/test/simple/test-fs-realpath.js +++ b/test/simple/test-fs-realpath.js @@ -23,7 +23,8 @@ function asynctest(testBlock, args, callback, assertBlock) { } function bashRealpath(path, callback) { - exec("cd '"+path.replace("'","\\'")+"' && pwd -P",function (err, o) { + common.exec("cd '"+path.replace("'","\\'")+"' && pwd -P",function + (err, o) { callback(err, o.trim()); }); } diff --git a/test/simple/test-fs-stat.js b/test/simple/test-fs-stat.js index e626a973ec..7623a95f46 100644 --- a/test/simple/test-fs-stat.js +++ b/test/simple/test-fs-stat.js @@ -8,7 +8,7 @@ fs.stat(".", function (err, stats) { if (err) { got_error = true; } else { - p(stats); + common.p(stats); assert.ok(stats.mtime instanceof Date); success_count++; } @@ -18,7 +18,7 @@ fs.lstat(".", function (err, stats) { if (err) { got_error = true; } else { - p(stats); + common.p(stats); assert.ok(stats.mtime instanceof Date); success_count++; } @@ -33,7 +33,7 @@ fs.open(".", "r", undefined, function(err, fd) { if (err) { got_error = true; } else { - p(stats); + common.p(stats); assert.ok(stats.mtime instanceof Date); success_count++; fs.close(fd); @@ -50,7 +50,7 @@ fs.open(".", "r", undefined, function(err, fd) { got_error = true; } if (stats) { - p(stats); + common.p(stats); assert.ok(stats.mtime instanceof Date); success_count++; } @@ -62,7 +62,7 @@ fs.stat(__filename, function (err, s) { if (err) { got_error = true; } else { - p(s); + common.p(s); success_count++; console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) ); diff --git a/test/simple/test-http.js b/test/simple/test-http.js index 96a452ef29..05e6c7e8d2 100644 --- a/test/simple/test-http.js +++ b/test/simple/test-http.js @@ -17,7 +17,7 @@ var server = http.createServer(function (req, res) { assert.equal("GET", req.method); assert.equal("/hello", url.parse(req.url).pathname); - p(req.headers); + common.p(req.headers); assert.equal(true, "accept" in req.headers); assert.equal("*/*", req.headers["accept"]); diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 9a53a2d3d7..e66a0d8412 100644 --- a/test/simple/test-module-loading.js +++ b/test/simple/test-module-loading.js @@ -15,25 +15,25 @@ var d4 = require("../fixtures/b/d"); assert.equal(false, false, "testing the test program."); -assert.equal(true, a.A instanceof Function); +assert.equal(true, common.indirectInstanceOf(a.A, Function)); assert.equal("A", a.A()); -assert.equal(true, a.C instanceof Function); +assert.equal(true, common.indirectInstanceOf(a.C, Function)); assert.equal("C", a.C()); -assert.equal(true, a.D instanceof Function); +assert.equal(true, common.indirectInstanceOf(a.D, Function)); assert.equal("D", a.D()); -assert.equal(true, d.D instanceof Function); +assert.equal(true, common.indirectInstanceOf(d.D, Function)); assert.equal("D", d.D()); -assert.equal(true, d2.D instanceof Function); +assert.equal(true, common.indirectInstanceOf(d2.D, Function)); assert.equal("D", d2.D()); -assert.equal(true, d3.D instanceof Function); +assert.equal(true, common.indirectInstanceOf(d3.D, Function)); assert.equal("D", d3.D()); -assert.equal(true, d4.D instanceof Function); +assert.equal(true, common.indirectInstanceOf(d4.D, Function)); assert.equal("D", d4.D()); assert.ok((new a.SomeClass) instanceof c.SomeClass); @@ -52,7 +52,7 @@ assert.equal(root.sayHello(), root.hello); common.debug("test name clashes"); // this one exists and should import the local module var my_path = require("./path"); -assert.equal(true, my_path.path_func instanceof Function); +assert.ok(common.indirectInstanceOf(my_path.path_func, Function)); // this one does not exist and should throw assert.throws(function() { require("./utils")}); @@ -98,7 +98,7 @@ require.registerExtension('.test', function(content) { }); assert.equal(require('../fixtures/registerExt2').custom, 'passed'); -debug("load modules by absolute id, then change require.paths, and load another module with the same absolute id."); +common.debug("load modules by absolute id, then change require.paths, and load another module with the same absolute id."); // this will throw if it fails. var foo = require("../fixtures/require-path/p1/foo"); process.assert(foo.bar.expect === foo.bar.actual); diff --git a/test/simple/test-net-binary.js b/test/simple/test-net-binary.js index 572e6f77e7..233118c5c3 100644 --- a/test/simple/test-net-binary.js +++ b/test/simple/test-net-binary.js @@ -54,7 +54,7 @@ echoServer.addListener("listening", function() { }); c.addListener("close", function () { - p(recv); + common.p(recv); echoServer.close(); }); }); diff --git a/test/simple/test-readdir.js b/test/simple/test-readdir.js index 8d3f6fd508..e89f42a55b 100644 --- a/test/simple/test-readdir.js +++ b/test/simple/test-readdir.js @@ -19,7 +19,7 @@ var files = ['are' console.log('readdirSync ' + readdirDir); var f = fs.readdirSync(readdirDir); -p(f); +common.p(f); assert.deepEqual(files, f.sort()); @@ -29,7 +29,7 @@ fs.readdir(readdirDir, function (err, f) { console.log("error"); got_error = true; } else { - p(f); + common.p(f); assert.deepEqual(files, f.sort()); } }); diff --git a/test/simple/test-stdout-to-file.js b/test/simple/test-stdout-to-file.js index 3db8183ecf..0cf7cb2650 100644 --- a/test/simple/test-stdout-to-file.js +++ b/test/simple/test-stdout-to-file.js @@ -21,7 +21,7 @@ function test (size, useBuffer, cb) { fs.unlinkSync(tmpFile); } catch (e) {} - print(size + ' chars to ' + tmpFile + '...'); + common.print(size + ' chars to ' + tmpFile + '...'); childProccess.exec(cmd, function(err) { if (err) throw err; diff --git a/test/simple/test-string-decoder.js b/test/simple/test-string-decoder.js index d9b689cd85..cc59b070c3 100644 --- a/test/simple/test-string-decoder.js +++ b/test/simple/test-string-decoder.js @@ -43,7 +43,7 @@ charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5]; // 0 i j buffer.length // Scan through every possible 3 segment combination // and make sure that the string is always parsed. -print('scanning '); +common.print('scanning '); for (var j = 2; j < buffer.length; j++) { for (var i = 1; i < j; i++) { var decoder = new StringDecoder('utf8'); @@ -57,7 +57,7 @@ for (var j = 2; j < buffer.length; j++) { sum += decoder.write(buffer.slice(i, j)); sum += decoder.write(buffer.slice(j, buffer.length)); assert.equal(expected, sum); - print("."); + common.print("."); } } console.log(" crayon!");