Browse Source

More changes to tests so they really work under context module loader.

Plus, getting rid of test/common.js defining things in global.
v0.7.4-release
Herbert Vojčík 15 years ago
committed by Ryan Dahl
parent
commit
cf2b206a8e
  1. 15
      test/common.js
  2. 4
      test/disabled/test-http-big-proxy-responses.js
  3. 4
      test/disabled/test-http-stress.js
  4. 2
      test/fixtures/b/c.js
  5. 2
      test/fixtures/b/d.js
  6. 2
      test/fixtures/b/package/index.js
  7. 2
      test/fixtures/echo.js
  8. 2
      test/fixtures/net-fd-passing-receiver.js
  9. 6
      test/pummel/test-net-many-clients.js
  10. 2
      test/pummel/test-net-pause.js
  11. 4
      test/pummel/test-net-timeout.js
  12. 2
      test/simple/test-assert.js
  13. 2
      test/simple/test-buffer.js
  14. 6
      test/simple/test-c-ares.js
  15. 2
      test/simple/test-child-process-buffering.js
  16. 3
      test/simple/test-child-process-exec-env.js
  17. 4
      test/simple/test-exec.js
  18. 3
      test/simple/test-fs-realpath.js
  19. 10
      test/simple/test-fs-stat.js
  20. 2
      test/simple/test-http.js
  21. 18
      test/simple/test-module-loading.js
  22. 2
      test/simple/test-net-binary.js
  23. 4
      test/simple/test-readdir.js
  24. 2
      test/simple/test-stdout-to-file.js
  25. 4
      test/simple/test-string-decoder.js

15
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;
};

4
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<len; i++) {
if (i % 1000 == 0) print(',');
if (i % 1000 == 0) common.print(',');
res.write(chunk);
}
res.end();
@ -42,7 +42,7 @@ var proxy = http.createServer(function (req, res) {
var count = 0;
proxy_res.addListener('data', function(d) {
if (count++ % 1000 == 0) print('.');
if (count++ % 1000 == 0) common.print('.');
res.write(d);
sent += d.length;
assert.ok(sent <= (len*chunk.length));

4
test/disabled/test-http-stress.js

@ -21,10 +21,10 @@ server.addListener('listening', function () {
http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
requests_complete++;
if (err) {
print("-");
common.print("-");
} else {
assert.equal(body, content)
print(".");
common.print(".");
requests_ok++;
}
if (requests_complete == request_count) {

2
test/fixtures/b/c.js

@ -6,7 +6,7 @@ var package = require("./package");
assert.equal("world", package.hello);
debug("load fixtures/b/c.js");
common.debug("load fixtures/b/c.js");
var string = "C";

2
test/fixtures/b/d.js

@ -1,4 +1,4 @@
debug("load fixtures/b/d.js");
common.debug("load fixtures/b/d.js");
var string = "D";

2
test/fixtures/b/package/index.js

@ -1,2 +1,2 @@
exports.hello = "world";
debug("load package/index.js");
common.debug("load package/index.js");

2
test/fixtures/echo.js

@ -1,7 +1,7 @@
common = require("../common");
assert = common.assert
print("hello world\r\n");
common.print("hello world\r\n");
var stdin = process.openStdin();

2
test/fixtures/net-fd-passing-receiver.js

@ -26,7 +26,7 @@ receiver = net.createServer(function(socket) {
/* To signal the test runne we're up and listening */
receiver.addListener("listening", function() {
print("ready");
common.print("ready");
});
receiver.listen(path);

6
test/pummel/test-net-many-clients.js

@ -17,7 +17,7 @@ for (var i = 0; i < bytes; i++) {
var server = net.createServer(function (c) {
c.addListener("connect", function () {
total_connections++;
print("#");
common.print("#");
c.write(body);
c.end();
});
@ -31,7 +31,7 @@ function runClient (callback) {
client.setEncoding("utf8");
client.addListener("connect", function () {
print("c");
common.print("c");
client.recved = "";
client.connections += 1;
});
@ -50,7 +50,7 @@ function runClient (callback) {
});
client.addListener("close", function (had_error) {
print(".");
common.print(".");
assert.equal(false, had_error);
assert.equal(bytes, client.recved.length);

2
test/pummel/test-net-pause.js

@ -21,7 +21,7 @@ server.on('listening', function(){
client = net.createConnection(common.PORT);
client.setEncoding("ascii");
client.addListener("data", function (d) {
print(d);
common.print(d);
recv += d;
});

4
test/pummel/test-net-timeout.js

@ -12,7 +12,7 @@ var echo_server = net.createServer(function (socket) {
socket.addListener("timeout", function () {
console.log("server timeout");
timeouttime = new Date;
p(timeouttime);
common.p(timeouttime);
socket.destroy();
});
@ -53,7 +53,7 @@ client.addListener("data", function (chunk) {
if (exchanges == 5) {
console.log("wait for timeout - should come in " + timeout + " ms");
starttime = new Date;
p(starttime);
common.p(starttime);
}
}
});

2
test/simple/test-assert.js

@ -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");
assert.throws(makeBlock(a.ok, false),

2
test/simple/test-buffer.js

@ -25,7 +25,7 @@ var copied = b.copy(c, 0, 0, 512);
console.log("copied " + copied + " bytes from b into c");
assert.strictEqual(512, copied);
for (var i = 0; i < c.length; i++) {
print('.');
common.print('.');
assert.equal(i % 256, c[i]);
}
console.log("");

6
test/simple/test-c-ares.js

@ -7,12 +7,12 @@ var dns = require("dns");
// Try resolution without callback
dns.getHostByName('localhost', function (error, result) {
p(result);
common.p(result);
assert.deepEqual(['127.0.0.1'], result);
});
dns.getHostByName('127.0.0.1', function (error, result) {
p(result);
common.p(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) {
if (error) throw error;
p(arguments);
common.p(arguments);
//assert.equal('string', typeof result);
assert.equal(6, addressType);
});

2
test/simple/test-child-process-buffering.js

@ -25,7 +25,7 @@ function pwd (callback) {
pwd(function (result) {
p(result);
common.p(result);
assert.equal(true, result.length > 1);
assert.equal("\n", result[result.length-1]);
});

3
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;

4
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 != "");
}
});

3
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());
});
}

10
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() ) );

2
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"]);

18
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);

2
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();
});
});

4
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());
}
});

2
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;

4
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!");

Loading…
Cancel
Save