More changes to tests so they really work under context module loader.
Plus, getting rid of test/common.js defining things in global.
This commit is contained in:
parent
1872719b8c
commit
cf2b206a8e
@ -9,4 +9,17 @@ exports.assert = require('assert');
|
|||||||
|
|
||||||
var sys = require("sys");
|
var sys = require("sys");
|
||||||
for (var i in sys) exports[i] = sys[i];
|
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;
|
||||||
|
};
|
||||||
|
@ -13,7 +13,7 @@ var chargen = http.createServer(function (req, res) {
|
|||||||
assert.ok(len > 0);
|
assert.ok(len > 0);
|
||||||
res.writeHead(200, {"transfer-encoding":"chunked"});
|
res.writeHead(200, {"transfer-encoding":"chunked"});
|
||||||
for (var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
if (i % 1000 == 0) print(',');
|
if (i % 1000 == 0) common.print(',');
|
||||||
res.write(chunk);
|
res.write(chunk);
|
||||||
}
|
}
|
||||||
res.end();
|
res.end();
|
||||||
@ -42,7 +42,7 @@ var proxy = http.createServer(function (req, res) {
|
|||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
proxy_res.addListener('data', function(d) {
|
proxy_res.addListener('data', function(d) {
|
||||||
if (count++ % 1000 == 0) print('.');
|
if (count++ % 1000 == 0) common.print('.');
|
||||||
res.write(d);
|
res.write(d);
|
||||||
sent += d.length;
|
sent += d.length;
|
||||||
assert.ok(sent <= (len*chunk.length));
|
assert.ok(sent <= (len*chunk.length));
|
||||||
|
@ -21,10 +21,10 @@ server.addListener('listening', function () {
|
|||||||
http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
|
http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
|
||||||
requests_complete++;
|
requests_complete++;
|
||||||
if (err) {
|
if (err) {
|
||||||
print("-");
|
common.print("-");
|
||||||
} else {
|
} else {
|
||||||
assert.equal(body, content)
|
assert.equal(body, content)
|
||||||
print(".");
|
common.print(".");
|
||||||
requests_ok++;
|
requests_ok++;
|
||||||
}
|
}
|
||||||
if (requests_complete == request_count) {
|
if (requests_complete == request_count) {
|
||||||
|
2
test/fixtures/b/c.js
vendored
2
test/fixtures/b/c.js
vendored
@ -6,7 +6,7 @@ var package = require("./package");
|
|||||||
|
|
||||||
assert.equal("world", package.hello);
|
assert.equal("world", package.hello);
|
||||||
|
|
||||||
debug("load fixtures/b/c.js");
|
common.debug("load fixtures/b/c.js");
|
||||||
|
|
||||||
var string = "C";
|
var string = "C";
|
||||||
|
|
||||||
|
2
test/fixtures/b/d.js
vendored
2
test/fixtures/b/d.js
vendored
@ -1,4 +1,4 @@
|
|||||||
debug("load fixtures/b/d.js");
|
common.debug("load fixtures/b/d.js");
|
||||||
|
|
||||||
var string = "D";
|
var string = "D";
|
||||||
|
|
||||||
|
2
test/fixtures/b/package/index.js
vendored
2
test/fixtures/b/package/index.js
vendored
@ -1,2 +1,2 @@
|
|||||||
exports.hello = "world";
|
exports.hello = "world";
|
||||||
debug("load package/index.js");
|
common.debug("load package/index.js");
|
||||||
|
2
test/fixtures/echo.js
vendored
2
test/fixtures/echo.js
vendored
@ -1,7 +1,7 @@
|
|||||||
common = require("../common");
|
common = require("../common");
|
||||||
assert = common.assert
|
assert = common.assert
|
||||||
|
|
||||||
print("hello world\r\n");
|
common.print("hello world\r\n");
|
||||||
|
|
||||||
var stdin = process.openStdin();
|
var stdin = process.openStdin();
|
||||||
|
|
||||||
|
2
test/fixtures/net-fd-passing-receiver.js
vendored
2
test/fixtures/net-fd-passing-receiver.js
vendored
@ -26,7 +26,7 @@ receiver = net.createServer(function(socket) {
|
|||||||
|
|
||||||
/* To signal the test runne we're up and listening */
|
/* To signal the test runne we're up and listening */
|
||||||
receiver.addListener("listening", function() {
|
receiver.addListener("listening", function() {
|
||||||
print("ready");
|
common.print("ready");
|
||||||
});
|
});
|
||||||
|
|
||||||
receiver.listen(path);
|
receiver.listen(path);
|
||||||
|
@ -17,7 +17,7 @@ for (var i = 0; i < bytes; i++) {
|
|||||||
var server = net.createServer(function (c) {
|
var server = net.createServer(function (c) {
|
||||||
c.addListener("connect", function () {
|
c.addListener("connect", function () {
|
||||||
total_connections++;
|
total_connections++;
|
||||||
print("#");
|
common.print("#");
|
||||||
c.write(body);
|
c.write(body);
|
||||||
c.end();
|
c.end();
|
||||||
});
|
});
|
||||||
@ -31,7 +31,7 @@ function runClient (callback) {
|
|||||||
client.setEncoding("utf8");
|
client.setEncoding("utf8");
|
||||||
|
|
||||||
client.addListener("connect", function () {
|
client.addListener("connect", function () {
|
||||||
print("c");
|
common.print("c");
|
||||||
client.recved = "";
|
client.recved = "";
|
||||||
client.connections += 1;
|
client.connections += 1;
|
||||||
});
|
});
|
||||||
@ -50,7 +50,7 @@ function runClient (callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("close", function (had_error) {
|
client.addListener("close", function (had_error) {
|
||||||
print(".");
|
common.print(".");
|
||||||
assert.equal(false, had_error);
|
assert.equal(false, had_error);
|
||||||
assert.equal(bytes, client.recved.length);
|
assert.equal(bytes, client.recved.length);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ server.on('listening', function(){
|
|||||||
client = net.createConnection(common.PORT);
|
client = net.createConnection(common.PORT);
|
||||||
client.setEncoding("ascii");
|
client.setEncoding("ascii");
|
||||||
client.addListener("data", function (d) {
|
client.addListener("data", function (d) {
|
||||||
print(d);
|
common.print(d);
|
||||||
recv += d;
|
recv += d;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ var echo_server = net.createServer(function (socket) {
|
|||||||
socket.addListener("timeout", function () {
|
socket.addListener("timeout", function () {
|
||||||
console.log("server timeout");
|
console.log("server timeout");
|
||||||
timeouttime = new Date;
|
timeouttime = new Date;
|
||||||
p(timeouttime);
|
common.p(timeouttime);
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ client.addListener("data", function (chunk) {
|
|||||||
if (exchanges == 5) {
|
if (exchanges == 5) {
|
||||||
console.log("wait for timeout - should come in " + timeout + " ms");
|
console.log("wait for timeout - should come in " + timeout + " ms");
|
||||||
starttime = new Date;
|
starttime = new Date;
|
||||||
p(starttime);
|
common.p(starttime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,7 @@ function makeBlock (f) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.ok(a.AssertionError instanceof Error,
|
assert.ok(common.indirectInstanceOf(a.AssertionError.prototype, Error),
|
||||||
"a.AssertionError instanceof Error");
|
"a.AssertionError instanceof Error");
|
||||||
|
|
||||||
assert.throws(makeBlock(a.ok, false),
|
assert.throws(makeBlock(a.ok, false),
|
||||||
|
@ -25,7 +25,7 @@ var copied = b.copy(c, 0, 0, 512);
|
|||||||
console.log("copied " + copied + " bytes from b into c");
|
console.log("copied " + copied + " bytes from b into c");
|
||||||
assert.strictEqual(512, copied);
|
assert.strictEqual(512, copied);
|
||||||
for (var i = 0; i < c.length; i++) {
|
for (var i = 0; i < c.length; i++) {
|
||||||
print('.');
|
common.print('.');
|
||||||
assert.equal(i % 256, c[i]);
|
assert.equal(i % 256, c[i]);
|
||||||
}
|
}
|
||||||
console.log("");
|
console.log("");
|
||||||
|
@ -7,12 +7,12 @@ var dns = require("dns");
|
|||||||
// Try resolution without callback
|
// Try resolution without callback
|
||||||
|
|
||||||
dns.getHostByName('localhost', function (error, result) {
|
dns.getHostByName('localhost', function (error, result) {
|
||||||
p(result);
|
common.p(result);
|
||||||
assert.deepEqual(['127.0.0.1'], result);
|
assert.deepEqual(['127.0.0.1'], result);
|
||||||
});
|
});
|
||||||
|
|
||||||
dns.getHostByName('127.0.0.1', function (error, result) {
|
dns.getHostByName('127.0.0.1', function (error, result) {
|
||||||
p(result);
|
common.p(result);
|
||||||
assert.deepEqual(['127.0.0.1'], result);
|
assert.deepEqual(['127.0.0.1'], result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ dns.lookup('::1', function (error, result, addressType) {
|
|||||||
|
|
||||||
dns.lookup('ipv6.google.com', function (error, result, addressType) {
|
dns.lookup('ipv6.google.com', function (error, result, addressType) {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
p(arguments);
|
common.p(arguments);
|
||||||
//assert.equal('string', typeof result);
|
//assert.equal('string', typeof result);
|
||||||
assert.equal(6, addressType);
|
assert.equal(6, addressType);
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@ function pwd (callback) {
|
|||||||
|
|
||||||
|
|
||||||
pwd(function (result) {
|
pwd(function (result) {
|
||||||
p(result);
|
common.p(result);
|
||||||
assert.equal(true, result.length > 1);
|
assert.equal(true, result.length > 1);
|
||||||
assert.equal("\n", result[result.length-1]);
|
assert.equal("\n", result[result.length-1]);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require('../common');
|
common = require('../common');
|
||||||
|
assert = common.assert;
|
||||||
var exec = require('child_process').exec,
|
var exec = require('child_process').exec,
|
||||||
sys = require('sys');
|
sys = require('sys');
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
|
@ -13,7 +13,7 @@ exec("ls /", function (err, stdout, stderr) {
|
|||||||
assert.equal(false, err.killed);
|
assert.equal(false, err.killed);
|
||||||
} else {
|
} else {
|
||||||
success_count++;
|
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));
|
console.log("stderr: " + JSON.stringify(stderr));
|
||||||
} else {
|
} else {
|
||||||
success_count++;
|
success_count++;
|
||||||
p(stdout);
|
common.p(stdout);
|
||||||
assert.equal(true, stdout != "");
|
assert.equal(true, stdout != "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,8 @@ function asynctest(testBlock, args, callback, assertBlock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bashRealpath(path, callback) {
|
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());
|
callback(err, o.trim());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ fs.stat(".", function (err, stats) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
got_error = true;
|
got_error = true;
|
||||||
} else {
|
} else {
|
||||||
p(stats);
|
common.p(stats);
|
||||||
assert.ok(stats.mtime instanceof Date);
|
assert.ok(stats.mtime instanceof Date);
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ fs.lstat(".", function (err, stats) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
got_error = true;
|
got_error = true;
|
||||||
} else {
|
} else {
|
||||||
p(stats);
|
common.p(stats);
|
||||||
assert.ok(stats.mtime instanceof Date);
|
assert.ok(stats.mtime instanceof Date);
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ fs.open(".", "r", undefined, function(err, fd) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
got_error = true;
|
got_error = true;
|
||||||
} else {
|
} else {
|
||||||
p(stats);
|
common.p(stats);
|
||||||
assert.ok(stats.mtime instanceof Date);
|
assert.ok(stats.mtime instanceof Date);
|
||||||
success_count++;
|
success_count++;
|
||||||
fs.close(fd);
|
fs.close(fd);
|
||||||
@ -50,7 +50,7 @@ fs.open(".", "r", undefined, function(err, fd) {
|
|||||||
got_error = true;
|
got_error = true;
|
||||||
}
|
}
|
||||||
if (stats) {
|
if (stats) {
|
||||||
p(stats);
|
common.p(stats);
|
||||||
assert.ok(stats.mtime instanceof Date);
|
assert.ok(stats.mtime instanceof Date);
|
||||||
success_count++;
|
success_count++;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ fs.stat(__filename, function (err, s) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
got_error = true;
|
got_error = true;
|
||||||
} else {
|
} else {
|
||||||
p(s);
|
common.p(s);
|
||||||
success_count++;
|
success_count++;
|
||||||
|
|
||||||
console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) );
|
console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) );
|
||||||
|
@ -17,7 +17,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
assert.equal("GET", req.method);
|
assert.equal("GET", req.method);
|
||||||
assert.equal("/hello", url.parse(req.url).pathname);
|
assert.equal("/hello", url.parse(req.url).pathname);
|
||||||
|
|
||||||
p(req.headers);
|
common.p(req.headers);
|
||||||
assert.equal(true, "accept" in req.headers);
|
assert.equal(true, "accept" in req.headers);
|
||||||
assert.equal("*/*", req.headers["accept"]);
|
assert.equal("*/*", req.headers["accept"]);
|
||||||
|
|
||||||
|
@ -15,25 +15,25 @@ var d4 = require("../fixtures/b/d");
|
|||||||
|
|
||||||
assert.equal(false, false, "testing the test program.");
|
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("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("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("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("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("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("D", d3.D());
|
||||||
|
|
||||||
assert.equal(true, d4.D instanceof Function);
|
assert.equal(true, common.indirectInstanceOf(d4.D, Function));
|
||||||
assert.equal("D", d4.D());
|
assert.equal("D", d4.D());
|
||||||
|
|
||||||
assert.ok((new a.SomeClass) instanceof c.SomeClass);
|
assert.ok((new a.SomeClass) instanceof c.SomeClass);
|
||||||
@ -52,7 +52,7 @@ assert.equal(root.sayHello(), root.hello);
|
|||||||
common.debug("test name clashes");
|
common.debug("test name clashes");
|
||||||
// this one exists and should import the local module
|
// this one exists and should import the local module
|
||||||
var my_path = require("./path");
|
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
|
// this one does not exist and should throw
|
||||||
assert.throws(function() { require("./utils")});
|
assert.throws(function() { require("./utils")});
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ require.registerExtension('.test', function(content) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(require('../fixtures/registerExt2').custom, 'passed');
|
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.
|
// this will throw if it fails.
|
||||||
var foo = require("../fixtures/require-path/p1/foo");
|
var foo = require("../fixtures/require-path/p1/foo");
|
||||||
process.assert(foo.bar.expect === foo.bar.actual);
|
process.assert(foo.bar.expect === foo.bar.actual);
|
||||||
|
@ -54,7 +54,7 @@ echoServer.addListener("listening", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
c.addListener("close", function () {
|
c.addListener("close", function () {
|
||||||
p(recv);
|
common.p(recv);
|
||||||
echoServer.close();
|
echoServer.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ var files = ['are'
|
|||||||
|
|
||||||
console.log('readdirSync ' + readdirDir);
|
console.log('readdirSync ' + readdirDir);
|
||||||
var f = fs.readdirSync(readdirDir);
|
var f = fs.readdirSync(readdirDir);
|
||||||
p(f);
|
common.p(f);
|
||||||
assert.deepEqual(files, f.sort());
|
assert.deepEqual(files, f.sort());
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ fs.readdir(readdirDir, function (err, f) {
|
|||||||
console.log("error");
|
console.log("error");
|
||||||
got_error = true;
|
got_error = true;
|
||||||
} else {
|
} else {
|
||||||
p(f);
|
common.p(f);
|
||||||
assert.deepEqual(files, f.sort());
|
assert.deepEqual(files, f.sort());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@ function test (size, useBuffer, cb) {
|
|||||||
fs.unlinkSync(tmpFile);
|
fs.unlinkSync(tmpFile);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
print(size + ' chars to ' + tmpFile + '...');
|
common.print(size + ' chars to ' + tmpFile + '...');
|
||||||
|
|
||||||
childProccess.exec(cmd, function(err) {
|
childProccess.exec(cmd, function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
@ -43,7 +43,7 @@ charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5];
|
|||||||
// 0 i j buffer.length
|
// 0 i j buffer.length
|
||||||
// Scan through every possible 3 segment combination
|
// Scan through every possible 3 segment combination
|
||||||
// and make sure that the string is always parsed.
|
// and make sure that the string is always parsed.
|
||||||
print('scanning ');
|
common.print('scanning ');
|
||||||
for (var j = 2; j < buffer.length; j++) {
|
for (var j = 2; j < buffer.length; j++) {
|
||||||
for (var i = 1; i < j; i++) {
|
for (var i = 1; i < j; i++) {
|
||||||
var decoder = new StringDecoder('utf8');
|
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(i, j));
|
||||||
sum += decoder.write(buffer.slice(j, buffer.length));
|
sum += decoder.write(buffer.slice(j, buffer.length));
|
||||||
assert.equal(expected, sum);
|
assert.equal(expected, sum);
|
||||||
print(".");
|
common.print(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(" crayon!");
|
console.log(" crayon!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user