Browse Source

Update tests to work with module contexts

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
9fd5e3c89c
  1. 2
      test/common.js
  2. 4
      test/disabled/test-cat.js
  3. 3
      test/disabled/test-dns.js
  4. 3
      test/disabled/test-eio-race3.js
  5. 9
      test/disabled/test-fs-sendfile.js
  6. 7
      test/disabled/test-http-big-proxy-responses.js
  7. 7
      test/disabled/test-http-head-request.js
  8. 7
      test/disabled/test-http-stress.js
  9. 3
      test/disabled/test-idle-watcher.js
  10. 2
      test/disabled/test-net-fd-passing.js
  11. 9
      test/disabled/test-remote-module-loading.js
  12. 3
      test/disabled/test-setuidgid.js
  13. 7
      test/disabled/tls_client.js
  14. 7
      test/disabled/tls_server.js
  15. 2
      test/fixtures/a.js
  16. 3
      test/fixtures/echo.js
  17. 3
      test/fixtures/print-chars-from-buffer.js
  18. 3
      test/fixtures/print-chars.js
  19. 3
      test/message/2100bytes.js
  20. 3
      test/message/hello_world.js
  21. 7
      test/message/undefined_reference_in_new_context.js
  22. 4
      test/message/undefined_reference_in_new_context.out
  23. 3
      test/pummel/test-child-process-spawn-loop.js
  24. 7
      test/pummel/test-http-client-reconnect-bug.js
  25. 7
      test/pummel/test-keep-alive.js
  26. 9
      test/pummel/test-net-many-clients.js
  27. 9
      test/pummel/test-net-pause.js
  28. 9
      test/pummel/test-net-pingpong-delay.js
  29. 9
      test/pummel/test-net-pingpong.js
  30. 9
      test/pummel/test-net-throttle.js
  31. 9
      test/pummel/test-net-timeout.js
  32. 13
      test/pummel/test-net-tls.js
  33. 3
      test/pummel/test-timers.js
  34. 7
      test/pummel/test-watch-file.js
  35. 3
      test/simple/test-assert.js
  36. 3
      test/simple/test-buffer.js
  37. 3
      test/simple/test-byte-length.js
  38. 3
      test/simple/test-c-ares.js
  39. 3
      test/simple/test-chdir.js
  40. 3
      test/simple/test-child-process-buffering.js
  41. 5
      test/simple/test-child-process-custom-fds.js
  42. 3
      test/simple/test-child-process-env.js
  43. 7
      test/simple/test-child-process-exit-code.js
  44. 5
      test/simple/test-child-process-ipc.js
  45. 3
      test/simple/test-child-process-kill.js
  46. 3
      test/simple/test-child-process-stdin.js
  47. 5
      test/simple/test-child-process-stdout-flush.js
  48. 9
      test/simple/test-crypto.js
  49. 3
      test/simple/test-delayed-require.js
  50. 3
      test/simple/test-dgram-pingpong.js
  51. 3
      test/simple/test-dgram-udp4.js
  52. 3
      test/simple/test-dgram-unix-anon.js
  53. 3
      test/simple/test-dgram-unix.js
  54. 3
      test/simple/test-eio-race.js
  55. 5
      test/simple/test-eio-race2.js
  56. 3
      test/simple/test-eio-race4.js
  57. 5
      test/simple/test-error-reporting.js
  58. 13
      test/simple/test-eval-cx.js
  59. 3
      test/simple/test-event-emitter-add-listeners.js
  60. 3
      test/simple/test-event-emitter-modify-in-emit.js
  61. 3
      test/simple/test-event-emitter-remove-listeners.js
  62. 3
      test/simple/test-exception-handler.js
  63. 3
      test/simple/test-exec.js
  64. 3
      test/simple/test-executable-path.js
  65. 9
      test/simple/test-file-read-noexist.js
  66. 5
      test/simple/test-file-write-stream.js
  67. 5
      test/simple/test-fs-chmod.js
  68. 7
      test/simple/test-fs-error-messages.js
  69. 17
      test/simple/test-fs-fsync.js
  70. 5
      test/simple/test-fs-read-buffer.js
  71. 5
      test/simple/test-fs-read-file-sync.js
  72. 5
      test/simple/test-fs-read-stream.js
  73. 5
      test/simple/test-fs-read.js
  74. 5
      test/simple/test-fs-readfile-empty.js
  75. 65
      test/simple/test-fs-realpath.js
  76. 3
      test/simple/test-fs-stat.js
  77. 9
      test/simple/test-fs-symlink.js
  78. 5
      test/simple/test-fs-write-buffer.js
  79. 21
      test/simple/test-fs-write-file.js
  80. 5
      test/simple/test-fs-write-sync.js
  81. 5
      test/simple/test-fs-write.js
  82. 7
      test/simple/test-http-1.0.js
  83. 16
      test/simple/test-http-304.js
  84. 13
      test/simple/test-http-blank-header.js
  85. 7
      test/simple/test-http-cat.js
  86. 7
      test/simple/test-http-chunked.js
  87. 9
      test/simple/test-http-client-race-2.js
  88. 7
      test/simple/test-http-client-race.js
  89. 9
      test/simple/test-http-client-upload.js
  90. 7
      test/simple/test-http-eof-on-connect.js
  91. 7
      test/simple/test-http-exceptions.js
  92. 7
      test/simple/test-http-full-response.js
  93. 13
      test/simple/test-http-head-request.js
  94. 13
      test/simple/test-http-head-response-has-no-body.js
  95. 7
      test/simple/test-http-malformed-request.js
  96. 3
      test/simple/test-http-parser.js
  97. 23
      test/simple/test-http-proxy.js
  98. 7
      test/simple/test-http-server-multiheaders.js
  99. 15
      test/simple/test-http-server.js
  100. 12
      test/simple/test-http-set-timeout.js

2
test/common.js

@ -1,7 +1,5 @@
var path = require("path"); var path = require("path");
exports = module.exports = global;
exports.testDir = path.dirname(__filename); exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, "fixtures"); exports.fixturesDir = path.join(exports.testDir, "fixtures");
exports.libDir = path.join(exports.testDir, "../lib"); exports.libDir = path.join(exports.testDir, "../lib");

4
test/disabled/test-cat.js

@ -13,12 +13,12 @@ var server = http.createServer(function (req, res) {
res.sendBody(body); res.sendBody(body);
res.finish(); res.finish();
}); });
server.listen(PORT); server.listen(common.PORT);
var errors = 0; var errors = 0;
var successes = 0; var successes = 0;
var promise = process.cat("http://localhost:"+PORT, "utf8"); var promise = process.cat("http://localhost:"+common.PORT, "utf8");
promise.addCallback(function (content) { promise.addCallback(function (content) {
assert.equal(body, content); assert.equal(body, content);

3
test/disabled/test-dns.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var dns = require("dns"), var dns = require("dns"),
child_process = require("child_process"), child_process = require("child_process"),

3
test/disabled/test-eio-race3.js

@ -1,6 +1,7 @@
/* XXX Can this test be modified to not call the now-removed wait()? */ /* XXX Can this test be modified to not call the now-removed wait()? */
require("../common"); common = require("../common");
assert = common.assert
console.log('first stat ...'); console.log('first stat ...');

9
test/disabled/test-fs-sendfile.js

@ -1,8 +1,9 @@
require("../common"); common = require("../common");
assert = common.assert
tcp = require("tcp"); tcp = require("tcp");
sys = require("sys"); sys = require("sys");
var x = path.join(fixturesDir, "x.txt"); var x = path.join(common.fixturesDir, "x.txt");
var expected = "xyz"; var expected = "xyz";
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
@ -14,9 +15,9 @@ var server = tcp.createServer(function (socket) {
assert.equal(expected, found); assert.equal(expected, found);
}); });
}); });
server.listen(PORT); server.listen(common.PORT);
var client = tcp.createConnection(PORT); var client = tcp.createConnection(common.PORT);
client.addListener("connect", function () { client.addListener("connect", function () {
fs.open(x, 'r').addCallback(function (fd) { fs.open(x, 'r').addCallback(function (fd) {
fs.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) { fs.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) {

7
test/disabled/test-http-big-proxy-responses.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
var sys = require("sys"), var sys = require("sys"),
fs = require("fs"), fs = require("fs"),
http = require("http"), http = require("http"),
@ -63,7 +64,7 @@ function call_chargen(list) {
if (list.length > 0) { if (list.length > 0) {
var len = list.shift(); var len = list.shift();
sys.debug("calling chargen for " + len + " chunks."); sys.common.debug("calling chargen for " + len + " chunks.");
var recved = 0; var recved = 0;
@ -78,7 +79,7 @@ function call_chargen(list) {
res.addListener('end', function() { res.addListener('end', function() {
assert.ok(recved <= (len*chunk.length)); assert.ok(recved <= (len*chunk.length));
sys.debug("end for " + len + " chunks."); sys.common.debug("end for " + len + " chunks.");
call_chargen(list); call_chargen(list);
}); });

7
test/disabled/test-http-head-request.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
var assert = require("assert"); var assert = require("assert");
var http = require("http"); var http = require("http");
@ -14,12 +15,12 @@ server = http.createServer(function (req, res) {
if (req.method != 'HEAD') res.write(body); if (req.method != 'HEAD') res.write(body);
res.end(); res.end();
}); });
server.listen(PORT); server.listen(common.PORT);
var gotEnd = false; var gotEnd = false;
server.addListener('listening', function() { server.addListener('listening', function() {
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
var request = client.request("HEAD", "/"); var request = client.request("HEAD", "/");
request.addListener('response', function (response) { request.addListener('response', function (response) {
console.log('got response'); console.log('got response');

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

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
@ -10,14 +11,14 @@ var server = http.createServer(function(req, res) {
res.write(body); res.write(body);
res.end(); res.end();
}); });
server.listen(PORT); server.listen(common.PORT);
var requests_ok = 0; var requests_ok = 0;
var requests_complete = 0; var requests_complete = 0;
server.addListener('listening', function () { server.addListener('listening', function () {
for (var i = 0; i < request_count; i++) { for (var i = 0; i < request_count; i++) {
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) { http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
requests_complete++; requests_complete++;
if (err) { if (err) {
print("-"); print("-");

3
test/disabled/test-idle-watcher.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var complete = false; var complete = false;
var idle = new process.IdleWatcher(); var idle = new process.IdleWatcher();

2
test/disabled/test-net-fd-passing.js

@ -8,7 +8,7 @@ function fdPassingTest(path, port) {
var message = "beep toot"; var message = "beep toot";
var expectedData = ["[greeting] " + greeting, "[echo] " + message]; var expectedData = ["[greeting] " + greeting, "[echo] " + message];
var receiverArgs = [fixturesDir + "/net-fd-passing-receiver.js", path, greeting]; var receiverArgs = [common.fixturesDir + "/net-fd-passing-receiver.js", path, greeting];
var receiver = process.createChildProcess(process.ARGV[0], receiverArgs); var receiver = process.createChildProcess(process.ARGV[0], receiverArgs);
var initializeSender = function() { var initializeSender = function() {

9
test/disabled/test-remote-module-loading.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var http = require('http'); var http = require('http');
var sys = require('sys'); var sys = require('sys');
@ -14,16 +15,16 @@ var server = http.createServer(function(req, res) {
res.write(body); res.write(body);
res.end(); res.end();
}); });
server.listen(PORT); server.listen(common.PORT);
assert.throws(function () { assert.throws(function () {
var httpModule = require('http://localhost:'+PORT+'/moduleA.js'); var httpModule = require('http://localhost:'+common.PORT+'/moduleA.js');
assert.equal('/moduleA.js', httpModule.httpPath()); assert.equal('/moduleA.js', httpModule.httpPath());
modulesLoaded++; modulesLoaded++;
}); });
var nodeBinary = process.ARGV[0]; var nodeBinary = process.ARGV[0];
var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+PORT+'/moduleB.js'; var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+common.PORT+'/moduleB.js';
sys.exec(cmd, function (err, stdout, stderr) { sys.exec(cmd, function (err, stdout, stderr) {
if (err) throw err; if (err) throw err;

3
test/disabled/test-setuidgid.js

@ -1,5 +1,6 @@
// Requires special privlages // Requires special privlages
require('../common'); common = require("../common");
assert = common.assert
var assert = require('assert'); var assert = require('assert');
var oldgid = process.getgid(); var oldgid = process.getgid();

7
test/disabled/tls_client.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
var sys=require('sys'); var sys=require('sys');
var net=require('net'); var net=require('net');
var fs=require('fs'); var fs=require('fs');
@ -8,7 +9,7 @@ var crypto=require('crypto');
var client = net.createConnection(443, "www.microsoft.com"); var client = net.createConnection(443, "www.microsoft.com");
//var client = net.createConnection(443, "www.google.com"); //var client = net.createConnection(443, "www.google.com");
var caPem = fs.readFileSync(fixturesDir+"/msca.pem"); var caPem = fs.readFileSync(common.fixturesDir+"/msca.pem");
//var caPem = fs.readFileSync("ca.pem"); //var caPem = fs.readFileSync("ca.pem");
var credentials = crypto.createCredentials({ca:caPem}); var credentials = crypto.createCredentials({ca:caPem});
@ -27,7 +28,7 @@ client.addListener("secure", function () {
}); });
client.addListener("data", function (chunk) { client.addListener("data", function (chunk) {
sys.error(chunk); sys.common.error(chunk);
}); });
client.addListener("end", function () { client.addListener("end", function () {

7
test/disabled/tls_server.js

@ -1,12 +1,13 @@
require('../common'); common = require("../common");
assert = common.assert
var sys=require('sys'); var sys=require('sys');
var net=require('net'); var net=require('net');
var fs=require('fs'); var fs=require('fs');
var crypto=require('crypto'); var crypto=require('crypto');
var keyPem = fs.readFileSync(fixturesDir + "/cert.pem"); var keyPem = fs.readFileSync(common.fixturesDir + "/cert.pem");
var certPem = fs.readFileSync(fixturesDir + "/cert.pem"); var certPem = fs.readFileSync(common.fixturesDir + "/cert.pem");
var credentials = crypto.createCredentials({key:keyPem, cert:certPem}); var credentials = crypto.createCredentials({key:keyPem, cert:certPem});
var i = 0; var i = 0;

2
test/fixtures/a.js

@ -1,6 +1,6 @@
var c = require("./b/c"); var c = require("./b/c");
debug("load fixtures/a.js"); common.debug("load fixtures/a.js");
var string = "A"; var string = "A";

3
test/fixtures/echo.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
print("hello world\r\n"); print("hello world\r\n");

3
test/fixtures/print-chars-from-buffer.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
Buffer = require("buffer").Buffer; Buffer = require("buffer").Buffer;
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);

3
test/fixtures/print-chars.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);

3
test/message/2100bytes.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
sys = require('sys'); sys = require('sys');
console.log([ console.log([

3
test/message/hello_world.js

@ -1,3 +1,4 @@
require('../common'); common = require("../common");
assert = common.assert
console.log('hello world'); console.log('hello world');

7
test/message/undefined_reference_in_new_context.js

@ -1,6 +1,7 @@
require('../common'); common = require("../common");
assert = common.assert
error('before'); common.error('before');
var Script = process.binding('evals').Script; var Script = process.binding('evals').Script;
@ -8,4 +9,4 @@ var Script = process.binding('evals').Script;
script = new Script('foo.bar = 5;'); script = new Script('foo.bar = 5;');
script.runInNewContext(); script.runInNewContext();
error('after'); common.error('after');

4
test/message/undefined_reference_in_new_context.out

@ -1,7 +1,7 @@
before before
*test/message/undefined_reference_in_new_context.js:9 *test/message/undefined_reference_in_new_context.js:10
script.runInNewContext(); script.runInNewContext();
^ ^
ReferenceError: foo is not defined ReferenceError: foo is not defined
@ -11,4 +11,4 @@ ReferenceError: foo is not defined
at Module._loadScriptSync (module:*) at Module._loadScriptSync (module:*)
at Module.loadSync (module:*) at Module.loadSync (module:*)
at Object.runMain (module:*) at Object.runMain (module:*)
at node.js:*242:10 at node.js:*

3
test/pummel/test-child-process-spawn-loop.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

7
test/pummel/test-http-client-reconnect-bug.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var tcp = require("tcp"), var tcp = require("tcp"),
sys = require("sys"), sys = require("sys"),
@ -10,9 +11,9 @@ var eofCount = 0;
var server = tcp.createServer(function(socket) { var server = tcp.createServer(function(socket) {
socket.end(); socket.end();
}); });
server.listen(PORT); server.listen(common.PORT);
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
client.addListener("error", function() { client.addListener("error", function() {
console.log("ERROR!"); console.log("ERROR!");

7
test/pummel/test-keep-alive.js

@ -1,5 +1,6 @@
// This test requires the program "ab" // This test requires the program "ab"
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
exec = require("child_process").exec; exec = require("child_process").exec;
@ -18,7 +19,7 @@ var normalReqSec = 0;
function runAb(opts, callback) { function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
console.log("ab not installed? skipping test.\n" + stderr); console.log("ab not installed? skipping test.\n" + stderr);
@ -41,7 +42,7 @@ function runAb(opts, callback) {
}); });
} }
server.listen(PORT, function () { server.listen(common.PORT, function () {
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
keepAliveReqSec = reqSec; keepAliveReqSec = reqSec;
assert.equal(true, keepAliveRequests > 0); assert.equal(true, keepAliveRequests > 0);

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

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
// settings // settings
var bytes = 1024*40; var bytes = 1024*40;
@ -23,7 +24,7 @@ var server = net.createServer(function (c) {
}); });
function runClient (callback) { function runClient (callback) {
var client = net.createConnection(PORT); var client = net.createConnection(common.PORT);
client.connections = 0; client.connections = 0;
@ -59,14 +60,14 @@ function runClient (callback) {
assert.ok(!client.fd); assert.ok(!client.fd);
if (this.connections < connections_per_client) { if (this.connections < connections_per_client) {
this.connect(PORT); this.connect(common.PORT);
} else { } else {
callback(); callback();
} }
}); });
} }
server.listen(PORT, function () { server.listen(common.PORT, function () {
var finished_clients = 0; var finished_clients = 0;
for (var i = 0; i < concurrency; i++) { for (var i = 0; i < concurrency; i++) {
runClient(function () { runClient(function () {

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

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
N = 200; N = 200;
@ -15,13 +16,13 @@ server = net.createServer(function (connection) {
} }
write(0); write(0);
}); });
server.listen(PORT); server.listen(common.PORT);
recv = ""; recv = "";
chars_recved = 0; chars_recved = 0;
client = net.createConnection(PORT); client = net.createConnection(common.PORT);
client.setEncoding("ascii"); client.setEncoding("ascii");
client.addListener("data", function (d) { client.addListener("data", function (d) {
print(d); print(d);
@ -63,5 +64,5 @@ client.addListener("end", function () {
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(N, recv.length); assert.equal(N, recv.length);
debug("Exit"); common.debug("Exit");
}); });

9
test/pummel/test-net-pingpong-delay.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
@ -25,7 +26,7 @@ function pingPongTest (port, host, on_complete) {
}); });
socket.addListener("timeout", function () { socket.addListener("timeout", function () {
debug("server-side timeout!!"); common.debug("server-side timeout!!");
assert.equal(false, true); assert.equal(false, true);
}); });
@ -71,7 +72,7 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("timeout", function () { client.addListener("timeout", function () {
debug("client-side timeout!!"); common.debug("client-side timeout!!");
assert.equal(false, true); assert.equal(false, true);
}); });
@ -84,7 +85,7 @@ function pingPongTest (port, host, on_complete) {
}); });
} }
pingPongTest(PORT); pingPongTest(common.PORT);
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(1, tests_run); assert.equal(1, tests_run);

9
test/pummel/test-net-pingpong.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
var tests_run = 0; var tests_run = 0;
@ -84,12 +85,12 @@ function pingPongTest (port, host, on_complete) {
} }
/* All are run at once, so run on different ports */ /* All are run at once, so run on different ports */
pingPongTest(PORT, "localhost"); pingPongTest(common.PORT, "localhost");
pingPongTest(PORT+1, null); pingPongTest(common.PORT+1, null);
// This IPv6 isn't working on Solaris // This IPv6 isn't working on Solaris
var solaris = /sunos/i.test(process.platform); var solaris = /sunos/i.test(process.platform);
if (!solaris) pingPongTest(PORT+2, "::1"); if (!solaris) pingPongTest(common.PORT+2, "::1");
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(solaris ? 2 : 3, tests_run); assert.equal(solaris ? 2 : 3, tests_run);

9
test/pummel/test-net-throttle.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
N = 160*1024; // 30kb N = 160*1024; // 30kb
@ -8,7 +9,7 @@ for (var i = 0; i < N; i++) {
body += "C"; body += "C";
} }
console.log("start server on port " + PORT); console.log("start server on port " + common.PORT);
server = net.createServer(function (connection) { server = net.createServer(function (connection) {
connection.addListener("connect", function () { connection.addListener("connect", function () {
@ -16,7 +17,7 @@ server = net.createServer(function (connection) {
connection.end(); connection.end();
}); });
}); });
server.listen(PORT); server.listen(common.PORT);
chars_recved = 0; chars_recved = 0;
@ -24,7 +25,7 @@ npauses = 0;
var paused = false; var paused = false;
client = net.createConnection(PORT); client = net.createConnection(common.PORT);
client.setEncoding("ascii"); client.setEncoding("ascii");
client.addListener("data", function (d) { client.addListener("data", function (d) {
chars_recved += d.length; chars_recved += d.length;

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

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
exchanges = 0; exchanges = 0;
starttime = null; starttime = null;
@ -29,11 +30,11 @@ var echo_server = net.createServer(function (socket) {
}); });
}); });
echo_server.listen(PORT, function () { echo_server.listen(common.PORT, function () {
console.log("server listening at " + PORT); console.log("server listening at " + common.PORT);
}); });
var client = net.createConnection(PORT); var client = net.createConnection(common.PORT);
client.setEncoding("UTF8"); client.setEncoding("UTF8");
client.setTimeout(0); // disable the timeout for client client.setTimeout(0); // disable the timeout for client
client.addListener("connect", function () { client.addListener("connect", function () {

13
test/pummel/test-net-tls.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
tcp = require("tcp"); tcp = require("tcp");
fs=require("fs"); fs=require("fs");
@ -105,13 +106,13 @@ try {
} }
if (have_tls) { if (have_tls) {
var caPem = fs.readFileSync(fixturesDir+"/test_ca.pem"); var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem");
var certPem = fs.readFileSync(fixturesDir+"/test_cert.pem"); var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem");
var keyPem = fs.readFileSync(fixturesDir+"/test_key.pem"); var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem");
/* All are run at once, so run on different ports */ /* All are run at once, so run on different ports */
tlsTest(PORT, "localhost", caPem, keyPem, certPem); tlsTest(common.PORT, "localhost", caPem, keyPem, certPem);
tlsTest(PORT+1, null, caPem, keyPem, certPem); tlsTest(common.PORT+1, null, caPem, keyPem, certPem);
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(2, tests_run); assert.equal(2, tests_run);

3
test/pummel/test-timers.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
assert = require('assert'); assert = require('assert');

7
test/pummel/test-watch-file.js

@ -1,10 +1,11 @@
require("../common"); common = require("../common");
assert = common.assert
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var f = path.join(fixturesDir, "x.txt"); var f = path.join(common.fixturesDir, "x.txt");
var f2 = path.join(fixturesDir, "x2.txt"); var f2 = path.join(common.fixturesDir, "x2.txt");
console.log("watching for changes of " + f); console.log("watching for changes of " + f);

3
test/simple/test-assert.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var a = require('assert'); var a = require('assert');

3
test/simple/test-buffer.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
assert = require("assert"); assert = require("assert");
var Buffer = require('buffer').Buffer; var Buffer = require('buffer').Buffer;

3
test/simple/test-byte-length.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
assert.equal(14, process._byteLength("Il était tué")); assert.equal(14, process._byteLength("Il était tué"));
assert.equal(14, process._byteLength("Il était tué", "utf8")); assert.equal(14, process._byteLength("Il était tué", "utf8"));

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

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
var dns = require("dns"); var dns = require("dns");

3
test/simple/test-chdir.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
assert.equal(true, process.cwd() !== __dirname); assert.equal(true, process.cwd() !== __dirname);

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

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

5
test/simple/test-child-process-custom-fds.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var assert = require('assert'); var assert = require('assert');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
@ -7,7 +8,7 @@ var fs = require('fs');
var sys = require('sys'); var sys = require('sys');
function fixtPath(p) { function fixtPath(p) {
return path.join(fixturesDir, p); return path.join(common.fixturesDir, p);
} }
var expected = "hello world"; var expected = "hello world";

3
test/simple/test-child-process-env.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
child = spawn('/usr/bin/env', [], {'HELLO' : 'WORLD'}); child = spawn('/usr/bin/env', [], {'HELLO' : 'WORLD'});

7
test/simple/test-child-process-exit-code.js

@ -1,10 +1,11 @@
require("../common"); common = require("../common");
assert = common.assert
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
path = require('path'); path = require('path');
exits = 0; exits = 0;
exitScript = path.join(fixturesDir, 'exit.js') exitScript = path.join(common.fixturesDir, 'exit.js')
exitChild = spawn(process.argv[0], [exitScript, 23]); exitChild = spawn(process.argv[0], [exitScript, 23]);
exitChild.addListener('exit', function(code, signal) { exitChild.addListener('exit', function(code, signal) {
assert.strictEqual(code, 23); assert.strictEqual(code, 23);
@ -15,7 +16,7 @@ exitChild.addListener('exit', function(code, signal) {
errorScript = path.join(fixturesDir, 'child_process_should_emit_error.js') errorScript = path.join(common.fixturesDir, 'child_process_should_emit_error.js')
errorChild = spawn(process.argv[0], [errorScript]); errorChild = spawn(process.argv[0], [errorScript]);
errorChild.addListener('exit', function(code, signal) { errorChild.addListener('exit', function(code, signal) {
assert.ok(code !== 0); assert.ok(code !== 0);

5
test/simple/test-child-process-ipc.js

@ -1,10 +1,11 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var path = require('path'); var path = require('path');
var sub = path.join(fixturesDir, 'echo.js'); var sub = path.join(common.fixturesDir, 'echo.js');
var gotHelloWorld = false; var gotHelloWorld = false;
var gotEcho = false; var gotEcho = false;

3
test/simple/test-child-process-kill.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

3
test/simple/test-child-process-stdin.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

5
test/simple/test-child-process-stdout-flush.js

@ -1,7 +1,8 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var sub = path.join(fixturesDir, 'print-chars.js'); var sub = path.join(common.fixturesDir, 'print-chars.js');
n = 500000; n = 500000;

9
test/simple/test-crypto.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
try { try {
var crypto = require('crypto'); var crypto = require('crypto');
@ -11,9 +12,9 @@ var fs = require('fs');
var sys = require('sys'); var sys = require('sys');
// Test Certificates // Test Certificates
var caPem = fs.readFileSync(fixturesDir+"/test_ca.pem", 'ascii'); var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem", 'ascii');
var certPem = fs.readFileSync(fixturesDir+"/test_cert.pem", 'ascii'); var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem", 'ascii');
var keyPem = fs.readFileSync(fixturesDir+"/test_key.pem", 'ascii'); var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem", 'ascii');
var credentials = crypto.createCredentials({key:keyPem, cert:certPem, ca:caPem}); var credentials = crypto.createCredentials({key:keyPem, cert:certPem, ca:caPem});

3
test/simple/test-delayed-require.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
setTimeout(function () { setTimeout(function () {
a = require("../fixtures/a"); a = require("../fixtures/a");

3
test/simple/test-dgram-pingpong.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var Buffer = require('buffer').Buffer; var Buffer = require('buffer').Buffer;
var dgram = require("dgram"); var dgram = require("dgram");

3
test/simple/test-dgram-udp4.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var Buffer = require("buffer").Buffer, var Buffer = require("buffer").Buffer,
fs = require("fs"), fs = require("fs"),

3
test/simple/test-dgram-unix-anon.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var Buffer = require("buffer").Buffer, var Buffer = require("buffer").Buffer,
fs = require("fs"), fs = require("fs"),

3
test/simple/test-dgram-unix.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var Buffer = require("buffer").Buffer, var Buffer = require("buffer").Buffer,
fs = require("fs"), fs = require("fs"),

3
test/simple/test-eio-race.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var count = 100; var count = 100;
var fs = require('fs'); var fs = require('fs');

5
test/simple/test-eio-race2.js

@ -1,6 +1,7 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var testTxt = path.join(fixturesDir, "x.txt"); var testTxt = path.join(common.fixturesDir, "x.txt");
var fs = require('fs'); var fs = require('fs');
setTimeout(function () { setTimeout(function () {

3
test/simple/test-eio-race4.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var fs = require('fs'); var fs = require('fs');
var N = 100; var N = 100;
var j = 0; var j = 0;

5
test/simple/test-error-reporting.js

@ -1,11 +1,12 @@
require("../common"); common = require("../common");
assert = common.assert
exec = require('child_process').exec, exec = require('child_process').exec,
path = require('path'); path = require('path');
exits = 0; exits = 0;
function errExec (script, callback) { function errExec (script, callback) {
var cmd = process.argv[0] + ' ' + path.join(fixturesDir, script); var cmd = process.argv[0] + ' ' + path.join(common.fixturesDir, script);
return exec(cmd, function (err, stdout, stderr) { return exec(cmd, function (err, stdout, stderr) {
// There was some error // There was some error
assert.ok(err); assert.ok(err);

13
test/simple/test-eval-cx.js

@ -1,10 +1,11 @@
require("../common"); common = require("../common");
assert = common.assert
debug('evalcx a string'); common.debug('evalcx a string');
var result = process.evalcx('"passed";'); var result = process.evalcx('"passed";');
assert.equal('passed', result); assert.equal('passed', result);
debug('evalcx a thrown error'); common.debug('evalcx a thrown error');
assert.throws(function() { assert.throws(function() {
process.evalcx('throw new Error("test");'); process.evalcx('throw new Error("test");');
}); });
@ -14,7 +15,7 @@ process.evalcx('hello = 2');
assert.equal(5, hello); assert.equal(5, hello);
debug("pass values in and out"); common.debug("pass values in and out");
code = "foo = 1;" code = "foo = 1;"
+ "bar = 2;" + "bar = 2;"
+ "if (baz !== 3) throw new Error('test fail');"; + "if (baz !== 3) throw new Error('test fail');";
@ -25,12 +26,12 @@ assert.equal(1, obj.foo);
assert.equal(2, obj.bar); assert.equal(2, obj.bar);
assert.equal(2, foo); assert.equal(2, foo);
debug("call a function by reference"); common.debug("call a function by reference");
function changeFoo () { foo = 100 } function changeFoo () { foo = 100 }
process.evalcx("f()", { f : changeFoo }); process.evalcx("f()", { f : changeFoo });
assert.equal(foo, 100); assert.equal(foo, 100);
debug("modify an object by reference"); common.debug("modify an object by reference");
var f = { a : 1 }; var f = { a : 1 };
process.evalcx("f.a = 2", { f : f }); process.evalcx("f.a = 2", { f : f });
assert.equal(f.a, 2); assert.equal(f.a, 2);

3
test/simple/test-event-emitter-add-listeners.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var events = require('events'); var events = require('events');
var e = new events.EventEmitter(); var e = new events.EventEmitter();

3
test/simple/test-event-emitter-modify-in-emit.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var events = require('events'); var events = require('events');
var callbacks_called = [ ]; var callbacks_called = [ ];

3
test/simple/test-event-emitter-remove-listeners.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var events = require('events'); var events = require('events');

3
test/simple/test-exception-handler.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var MESSAGE = 'catch me if you can'; var MESSAGE = 'catch me if you can';
var caughtException = false; var caughtException = false;

3
test/simple/test-exec.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var exec = require('child_process').exec; var exec = require('child_process').exec;
success_count = 0; success_count = 0;
error_count = 0; error_count = 0;

3
test/simple/test-executable-path.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
path = require("path"); path = require("path");

9
test/simple/test-file-read-noexist.js

@ -1,15 +1,16 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var got_error = false; var got_error = false;
var filename = path.join(fixturesDir, "does_not_exist.txt"); var filename = path.join(common.fixturesDir, "does_not_exist.txt");
fs.readFile(filename, "raw", function (err, content) { fs.readFile(filename, "raw", function (err, content) {
if (err) { if (err) {
got_error = true; got_error = true;
} else { } else {
debug("cat returned some content: " + content); common.debug("cat returned some content: " + content);
debug("this shouldn't happen as the file doesn't exist..."); common.debug("this shouldn't happen as the file doesn't exist...");
assert.equal(true, false); assert.equal(true, false);
} }
}); });

5
test/simple/test-file-write-stream.js

@ -1,9 +1,10 @@
require('../common'); common = require("../common");
assert = common.assert
var var
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
fn = path.join(fixturesDir, "write.txt"), fn = path.join(common.fixturesDir, "write.txt"),
file = fs.createWriteStream(fn), file = fs.createWriteStream(fn),
EXPECTED = '012345678910', EXPECTED = '012345678910',

5
test/simple/test-fs-chmod.js

@ -1,10 +1,11 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var got_error = false; var got_error = false;
var success_count = 0; var success_count = 0;
var file = path.join(fixturesDir, "a.js"); var file = path.join(common.fixturesDir, "a.js");
fs.chmod(file, 0777, function (err) { fs.chmod(file, 0777, function (err) {
if (err) { if (err) {

7
test/simple/test-fs-error-messages.js

@ -1,9 +1,10 @@
require('../common'); common = require("../common");
assert = common.assert
var path = require('path'), var path = require('path'),
fs = require('fs'), fs = require('fs'),
fn = path.join(fixturesDir, 'non-existent'), fn = path.join(common.fixturesDir, 'non-existent'),
existingFile = path.join(fixturesDir, 'exit.js'); existingFile = path.join(common.fixturesDir, 'exit.js');
// ASYNC_CALL // ASYNC_CALL

17
test/simple/test-fs-fsync.js

@ -1,32 +1,33 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var successes = 0; var successes = 0;
var file = path.join(fixturesDir, "a.js"); var file = path.join(common.fixturesDir, "a.js");
error("open " + file); common.error("open " + file);
fs.open(file, "a", 0777, function (err, fd) { fs.open(file, "a", 0777, function (err, fd) {
error("fd " + fd); common.error("fd " + fd);
if (err) throw err; if (err) throw err;
fs.fdatasyncSync(fd); fs.fdatasyncSync(fd);
error("fdatasync SYNC: ok"); common.error("fdatasync SYNC: ok");
successes++; successes++;
fs.fsyncSync(fd); fs.fsyncSync(fd);
error("fsync SYNC: ok"); common.error("fsync SYNC: ok");
successes++; successes++;
fs.fdatasync(fd, function (err) { fs.fdatasync(fd, function (err) {
if (err) throw err; if (err) throw err;
error("fdatasync ASYNC: ok"); common.error("fdatasync ASYNC: ok");
successes++; successes++;
fs.fsync(fd, function(err) { fs.fsync(fd, function(err) {
if (err) throw err; if (err) throw err;
error("fsync ASYNC: ok"); common.error("fsync ASYNC: ok");
successes++; successes++;
}); });
}); });

5
test/simple/test-fs-read-buffer.js

@ -1,8 +1,9 @@
require('../common'); common = require("../common");
assert = common.assert
var path = require('path'), var path = require('path'),
Buffer = require('buffer').Buffer, Buffer = require('buffer').Buffer,
fs = require('fs'), fs = require('fs'),
filepath = path.join(fixturesDir, 'x.txt'), filepath = path.join(common.fixturesDir, 'x.txt'),
fd = fs.openSync(filepath, 'r'), fd = fs.openSync(filepath, 'r'),
expected = 'xyz\n', expected = 'xyz\n',
bufferAsync = new Buffer(expected.length), bufferAsync = new Buffer(expected.length),

5
test/simple/test-fs-read-file-sync.js

@ -1,8 +1,9 @@
require('../common'); common = require("../common");
assert = common.assert
path = require('path'); path = require('path');
fs = require('fs'); fs = require('fs');
fn = path.join(fixturesDir, 'elipses.txt'); fn = path.join(common.fixturesDir, 'elipses.txt');
var s = fs.readFileSync(fn, 'utf8'); var s = fs.readFileSync(fn, 'utf8');
for (var i = 0; i < s.length; i++) { for (var i = 0; i < s.length; i++) {

5
test/simple/test-fs-read-stream.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
// TODO Improved this test. test_ca.pem is too small. A proper test would // TODO Improved this test. test_ca.pem is too small. A proper test would
// great a large utf8 (with multibyte chars) file and stream it in, // great a large utf8 (with multibyte chars) file and stream it in,
@ -7,7 +8,7 @@ require('../common');
Buffer = require('buffer').Buffer; Buffer = require('buffer').Buffer;
path = require('path'); path = require('path');
fs = require('fs'); fs = require('fs');
fn = path.join(fixturesDir, 'elipses.txt'); fn = path.join(common.fixturesDir, 'elipses.txt');
callbacks = { open: 0, end: 0, close: 0, destroy: 0 }; callbacks = { open: 0, end: 0, close: 0, destroy: 0 };

5
test/simple/test-fs-read.js

@ -1,7 +1,8 @@
require('../common'); common = require("../common");
assert = common.assert
var path = require('path'), var path = require('path'),
fs = require('fs'), fs = require('fs'),
filepath = path.join(fixturesDir, 'x.txt'), filepath = path.join(common.fixturesDir, 'x.txt'),
fd = fs.openSync(filepath, 'r'), fd = fs.openSync(filepath, 'r'),
expected = 'xyz\n', expected = 'xyz\n',
readCalled = 0; readCalled = 0;

5
test/simple/test-fs-readfile-empty.js

@ -1,9 +1,10 @@
require('../common'); common = require("../common");
assert = common.assert
var var
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
fn = path.join(fixturesDir, 'empty.txt'); fn = path.join(common.fixturesDir, 'empty.txt');
fs.readFile(fn, function(err, data) { fs.readFile(fn, function(err, data) {
assert.ok(data); assert.ok(data);

65
test/simple/test-fs-realpath.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var async_completed = 0, async_expected = 0, unlink = []; var async_completed = 0, async_expected = 0, unlink = [];
@ -30,8 +31,8 @@ function bashRealpath(path, callback) {
// sub-tests: // sub-tests:
function test_simple_relative_symlink(callback) { function test_simple_relative_symlink(callback) {
var entry = fixturesDir+'/cycles/symlink', var entry = common.fixturesDir+'/cycles/symlink',
expected = fixturesDir+'/cycles/root.js'; expected = common.fixturesDir+'/cycles/root.js';
[ [
[entry, 'root.js'], [entry, 'root.js'],
].forEach(function(t) { ].forEach(function(t) {
@ -41,15 +42,15 @@ function test_simple_relative_symlink(callback) {
}); });
var result = fs.realpathSync(entry); var result = fs.realpathSync(entry);
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
}); });
} }
function test_simple_absolute_symlink(callback) { function test_simple_absolute_symlink(callback) {
bashRealpath(fixturesDir, function(err, fixturesAbsDir) { bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err); if (err) return callback(err);
var entry = fixturesAbsDir+'/cycles/symlink', var entry = fixturesAbsDir+'/cycles/symlink',
expected = fixturesAbsDir+'/nested-index/one/index.js'; expected = fixturesAbsDir+'/nested-index/one/index.js';
@ -62,23 +63,23 @@ function test_simple_absolute_symlink(callback) {
}); });
var result = fs.realpathSync(entry); var result = fs.realpathSync(entry);
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
}); });
}); });
} }
function test_deep_relative_file_symlink(callback) { function test_deep_relative_file_symlink(callback) {
var expected = path.join(fixturesDir, 'cycles', 'root.js'); var expected = path.join(common.fixturesDir, 'cycles', 'root.js');
var linkData1 = "../../cycles/root.js"; var linkData1 = "../../cycles/root.js";
var linkPath1 = path.join(fixturesDir, "nested-index", 'one', 'symlink1.js'); var linkPath1 = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1.js');
try {fs.unlinkSync(linkPath1);}catch(e){} try {fs.unlinkSync(linkPath1);}catch(e){}
fs.symlinkSync(linkData1, linkPath1); fs.symlinkSync(linkData1, linkPath1);
var linkData2 = "../one/symlink1.js"; var linkData2 = "../one/symlink1.js";
var entry = path.join(fixturesDir, "nested-index", 'two', 'symlink1-b.js'); var entry = path.join(common.fixturesDir, "nested-index", 'two', 'symlink1-b.js');
try {fs.unlinkSync(entry);}catch(e){} try {fs.unlinkSync(entry);}catch(e){}
fs.symlinkSync(linkData2, entry); fs.symlinkSync(linkData2, entry);
unlink.push(linkPath1); unlink.push(linkPath1);
@ -87,19 +88,19 @@ function test_deep_relative_file_symlink(callback) {
assert.equal(fs.realpathSync(entry), expected); assert.equal(fs.realpathSync(entry), expected);
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
}); });
} }
function test_deep_relative_dir_symlink(callback) { function test_deep_relative_dir_symlink(callback) {
var expected = path.join(fixturesDir, 'cycles', 'folder'); var expected = path.join(common.fixturesDir, 'cycles', 'folder');
var linkData1b = "../../cycles/folder"; var linkData1b = "../../cycles/folder";
var linkPath1b = path.join(fixturesDir, "nested-index", 'one', 'symlink1-dir'); var linkPath1b = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1-dir');
try {fs.unlinkSync(linkPath1b);}catch(e){} try {fs.unlinkSync(linkPath1b);}catch(e){}
fs.symlinkSync(linkData1b, linkPath1b); fs.symlinkSync(linkData1b, linkPath1b);
var linkData2b = "../one/symlink1-dir"; var linkData2b = "../one/symlink1-dir";
var entry = path.join(fixturesDir, "nested-index", 'two', 'symlink12-dir'); var entry = path.join(common.fixturesDir, "nested-index", 'two', 'symlink12-dir');
try {fs.unlinkSync(entry);}catch(e){} try {fs.unlinkSync(entry);}catch(e){}
fs.symlinkSync(linkData2b, entry); fs.symlinkSync(linkData2b, entry);
unlink.push(linkPath1b); unlink.push(linkPath1b);
@ -109,16 +110,16 @@ function test_deep_relative_dir_symlink(callback) {
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
}); });
} }
function test_cyclic_link_protection(callback) { function test_cyclic_link_protection(callback) {
var entry = fixturesDir+'/cycles/realpath-3a'; var entry = common.fixturesDir+'/cycles/realpath-3a';
[ [
[entry, '../cycles/realpath-3b'], [entry, '../cycles/realpath-3b'],
[fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'], [common.fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
[fixturesDir+'/cycles/realpath-3c', '../cycles/realpath-3a'], [common.fixturesDir+'/cycles/realpath-3c', '../cycles/realpath-3a'],
].forEach(function(t) { ].forEach(function(t) {
try {fs.unlinkSync(t[0]);}catch(e){} try {fs.unlinkSync(t[0]);}catch(e){}
fs.symlinkSync(t[1], t[0]); fs.symlinkSync(t[1], t[0]);
@ -132,14 +133,14 @@ function test_cyclic_link_protection(callback) {
} }
function test_relative_input_cwd(callback) { function test_relative_input_cwd(callback) {
var p = fixturesDir.lastIndexOf('/'); var p = common.fixturesDir.lastIndexOf('/');
var entrydir = fixturesDir.substr(0, p); var entrydir = common.fixturesDir.substr(0, p);
var entry = fixturesDir.substr(p+1)+'/cycles/realpath-3a'; var entry = common.fixturesDir.substr(p+1)+'/cycles/realpath-3a';
var expected = fixturesDir+'/cycles/root.js'; var expected = common.fixturesDir+'/cycles/root.js';
[ [
[entry, '../cycles/realpath-3b'], [entry, '../cycles/realpath-3b'],
[fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'], [common.fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
[fixturesDir+'/cycles/realpath-3c', 'root.js'], [common.fixturesDir+'/cycles/realpath-3c', 'root.js'],
].forEach(function(t) { ].forEach(function(t) {
var fn = t[0]; var fn = t[0];
if (fn.charAt(0) !== '/') fn = entrydir + '/' + fn; if (fn.charAt(0) !== '/') fn = entrydir + '/' + fn;
@ -153,16 +154,16 @@ function test_relative_input_cwd(callback) {
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
process.chdir(origcwd); process.chdir(origcwd);
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
return true; return true;
}); });
} }
function test_deep_symlink_mix(callback) { function test_deep_symlink_mix(callback) {
// todo: check to see that fixturesDir is not rooted in the // todo: check to see that common.fixturesDir is not rooted in the
// same directory as our test symlink. // same directory as our test symlink.
// obtain our current realpath using bash (so we can test ourselves) // obtain our current realpath using bash (so we can test ourselves)
bashRealpath(fixturesDir, function(err, fixturesAbsDir) { bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err); if (err) return callback(err);
/* /*
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo /tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo
@ -188,7 +189,7 @@ function test_deep_symlink_mix(callback) {
[fixturesAbsDir+'/nested-index/one/realpath-c', fixturesAbsDir+'/nested-index/two/realpath-c'], [fixturesAbsDir+'/nested-index/one/realpath-c', fixturesAbsDir+'/nested-index/two/realpath-c'],
[fixturesAbsDir+'/nested-index/two/realpath-c', '../../cycles/root.js'], [fixturesAbsDir+'/nested-index/two/realpath-c', '../../cycles/root.js'],
].forEach(function(t) { ].forEach(function(t) {
//debug('setting up '+t[0]+' -> '+t[1]); //common.debug('setting up '+t[0]+' -> '+t[1]);
try {fs.unlinkSync(t[0]);}catch(e){} try {fs.unlinkSync(t[0]);}catch(e){}
fs.symlinkSync(t[1], t[0]); fs.symlinkSync(t[1], t[0]);
unlink.push(t[0]); unlink.push(t[0]);
@ -200,14 +201,14 @@ function test_deep_symlink_mix(callback) {
assert.equal(fs.realpathSync(entry), expected); assert.equal(fs.realpathSync(entry), expected);
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
return true; return true;
}); });
}); });
} }
function test_non_symlinks(callback) { function test_non_symlinks(callback) {
bashRealpath(fixturesDir, function(err, fixturesAbsDir) { bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err); if (err) return callback(err);
var p = fixturesAbsDir.lastIndexOf('/'); var p = fixturesAbsDir.lastIndexOf('/');
var entrydir = fixturesAbsDir.substr(0, p); var entrydir = fixturesAbsDir.substr(0, p);
@ -219,7 +220,7 @@ function test_non_symlinks(callback) {
asynctest(fs.realpath, [entry], callback, function(err, result){ asynctest(fs.realpath, [entry], callback, function(err, result){
process.chdir(origcwd); process.chdir(origcwd);
assert.equal(result, expected, assert.equal(result, expected,
'got '+inspect(result)+' expected '+inspect(expected)); 'got '+common.inspect(result)+' expected '+common.inspect(expected));
return true; return true;
}); });
}); });

3
test/simple/test-fs-stat.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var fs = require('fs'); var fs = require('fs');
var got_error = false; var got_error = false;
var success_count = 0; var success_count = 0;

9
test/simple/test-fs-symlink.js

@ -1,11 +1,12 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var completed = 0; var completed = 0;
// test creating and reading symbolic link // test creating and reading symbolic link
var linkData = "../../cycles/root.js"; var linkData = "../../cycles/root.js";
var linkPath = path.join(fixturesDir, "nested-index", 'one', 'symlink1.js'); var linkPath = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1.js');
try {fs.unlinkSync(linkPath);}catch(e){} try {fs.unlinkSync(linkPath);}catch(e){}
fs.symlink(linkData, linkPath, function(err){ fs.symlink(linkData, linkPath, function(err){
if (err) throw err; if (err) throw err;
@ -19,8 +20,8 @@ fs.symlink(linkData, linkPath, function(err){
}); });
// test creating and reading hard link // test creating and reading hard link
var srcPath = path.join(fixturesDir, "cycles", 'root.js'); var srcPath = path.join(common.fixturesDir, "cycles", 'root.js');
var dstPath = path.join(fixturesDir, "nested-index", 'one', 'link1.js'); var dstPath = path.join(common.fixturesDir, "nested-index", 'one', 'link1.js');
try {fs.unlinkSync(dstPath);}catch(e){} try {fs.unlinkSync(dstPath);}catch(e){}
fs.link(srcPath, dstPath, function(err){ fs.link(srcPath, dstPath, function(err){
if (err) throw err; if (err) throw err;

5
test/simple/test-fs-write-buffer.js

@ -1,8 +1,9 @@
require('../common'); common = require("../common");
assert = common.assert
var path = require('path'), var path = require('path'),
Buffer = require('buffer').Buffer, Buffer = require('buffer').Buffer,
fs = require('fs'), fs = require('fs'),
filename = path.join(fixturesDir, 'write.txt'), filename = path.join(common.fixturesDir, 'write.txt'),
expected = new Buffer('hello'), expected = new Buffer('hello'),
openCalled = 0, openCalled = 0,
writeCalled = 0; writeCalled = 0;

21
test/simple/test-fs-write-file.js

@ -1,12 +1,13 @@
require('../common'); common = require("../common");
assert = common.assert
join = require('path').join; join = require('path').join;
fs = require('fs'); fs = require('fs');
Buffer = require('buffer').Buffer; Buffer = require('buffer').Buffer;
filename = join(fixturesDir, 'test.txt'); filename = join(common.fixturesDir, 'test.txt');
error('writing to ' + filename); common.error('writing to ' + filename);
s = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; s = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n";
@ -16,30 +17,30 @@ fs.writeFile(filename, s, function (e) {
if (e) throw e; if (e) throw e;
ncallbacks++; ncallbacks++;
error('file written'); common.error('file written');
fs.readFile(filename, function (e, buffer) { fs.readFile(filename, function (e, buffer) {
if (e) throw e; if (e) throw e;
error('file read'); common.error('file read');
ncallbacks++; ncallbacks++;
assert.equal(Buffer.byteLength(s), buffer.length); assert.equal(Buffer.byteLength(s), buffer.length);
}); });
}); });
// test that writeFile accepts buffers // test that writeFile accepts buffers
filename2 = join(fixturesDir, 'test2.txt'); filename2 = join(common.fixturesDir, 'test2.txt');
buf = new Buffer(s, 'utf8'); buf = new Buffer(s, 'utf8');
error('writing to ' + filename2); common.error('writing to ' + filename2);
fs.writeFile(filename2, buf, function (e) { fs.writeFile(filename2, buf, function (e) {
if (e) throw e; if (e) throw e;
ncallbacks++; ncallbacks++;
error('file2 written'); common.error('file2 written');
fs.readFile(filename2, function (e, buffer) { fs.readFile(filename2, function (e, buffer) {
if (e) throw e; if (e) throw e;
error('file2 read'); common.error('file2 read');
ncallbacks++; ncallbacks++;
assert.equal(buf.length, buffer.length); assert.equal(buf.length, buffer.length);
}); });
@ -47,7 +48,7 @@ fs.writeFile(filename2, buf, function (e) {
process.addListener('exit', function () { process.addListener('exit', function () {
error('done'); common.error('done');
assert.equal(4, ncallbacks); assert.equal(4, ncallbacks);
fs.unlinkSync(filename); fs.unlinkSync(filename);

5
test/simple/test-fs-write-sync.js

@ -1,8 +1,9 @@
require('../common'); common = require("../common");
assert = common.assert
path = require('path'), path = require('path'),
Buffer = require('buffer').Buffer Buffer = require('buffer').Buffer
fs = require('fs') fs = require('fs')
fn = path.join(fixturesDir, 'write.txt'); fn = path.join(common.fixturesDir, 'write.txt');
foo = 'foo' foo = 'foo'

5
test/simple/test-fs-write.js

@ -1,8 +1,9 @@
require("../common"); common = require("../common");
assert = common.assert
var path = require('path'); var path = require('path');
var Buffer = require('buffer').Buffer; var Buffer = require('buffer').Buffer;
var fs = require('fs'); var fs = require('fs');
var fn = path.join(fixturesDir, "write.txt"); var fn = path.join(common.fixturesDir, "write.txt");
var expected = "ümlaut."; var expected = "ümlaut.";
var found; var found;

7
test/simple/test-http-1.0.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
http = require("http"); http = require("http");
@ -13,9 +14,9 @@ var server = http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.end(body); res.end(body);
}) })
server.listen(PORT); server.listen(common.PORT);
var c = net.createConnection(PORT); var c = net.createConnection(common.PORT);
c.setEncoding("utf8"); c.setEncoding("utf8");

16
test/simple/test-http-304.js

@ -1,7 +1,7 @@
require('../common'); common = require("../common");
assert = common.assert
var sys = require('sys'), http = require('http');
http = require('http'),
childProcess = require('child_process'); childProcess = require('child_process');
s = http.createServer(function (request, response) { s = http.createServer(function (request, response) {
@ -9,13 +9,13 @@ s = http.createServer(function (request, response) {
response.end(); response.end();
}); });
s.listen(PORT, function () { s.listen(common.PORT, function () {
childProcess.exec('curl -i http://127.0.0.1:'+PORT+'/', function (err, stdout, stderr) { childProcess.exec('curl -i http://127.0.0.1:'+common.PORT+'/', function (err, stdout, stderr) {
if (err) throw err; if (err) throw err;
s.close(); s.close();
error('curled response correctly'); common.error('curled response correctly');
error(sys.inspect(stdout)); common.error(common.inspect(stdout));
}); });
}); });
console.log('Server running at http://127.0.0.1:'+PORT+'/') console.log('Server running at http://127.0.0.1:'+common.PORT+'/')

13
test/simple/test-http-blank-header.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
http = require('http'); http = require('http');
net = require('net'); net = require('net');
@ -6,7 +7,7 @@ net = require('net');
gotReq = false; gotReq = false;
server = http.createServer(function (req, res) { server = http.createServer(function (req, res) {
error('got req'); common.error('got req');
gotReq = true; gotReq = true;
assert.equal('GET', req.method); assert.equal('GET', req.method);
assert.equal('/blah', req.url); assert.equal('/blah', req.url);
@ -18,11 +19,11 @@ server = http.createServer(function (req, res) {
}); });
server.listen(PORT, function () { server.listen(common.PORT, function () {
var c = net.createConnection(PORT); var c = net.createConnection(common.PORT);
c.addListener('connect', function () { c.addListener('connect', function () {
error('client wrote message'); common.error('client wrote message');
c.write( "GET /blah HTTP/1.1\r\n" c.write( "GET /blah HTTP/1.1\r\n"
+ "Host: mapdevel.trolologames.ru:443\r\n" + "Host: mapdevel.trolologames.ru:443\r\n"
+ "Cookie:\r\n" + "Cookie:\r\n"
@ -36,7 +37,7 @@ server.listen(PORT, function () {
}); });
c.addListener('close', function () { c.addListener('close', function () {
error('client close'); common.error('client close');
server.close(); server.close();
}); });
}); });

7
test/simple/test-http-cat.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
var body = "exports.A = function() { return 'A';}"; var body = "exports.A = function() { return 'A';}";
@ -14,8 +15,8 @@ var server = http.createServer(function (req, res) {
var got_good_server_content = false; var got_good_server_content = false;
var bad_server_got_error = false; var bad_server_got_error = false;
server.listen(PORT, function () { server.listen(common.PORT, function () {
http.cat("http://localhost:"+PORT+"/", "utf8", function (err, content) { http.cat("http://localhost:"+common.PORT+"/", "utf8", function (err, content) {
if (err) { if (err) {
throw err; throw err;
} else { } else {

7
test/simple/test-http-chunked.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var http = require("http"); var http = require("http");
var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、经济现状。"; var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、经济现状。";
@ -7,9 +8,9 @@ var server = http.createServer(function(req, res) {
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"}); res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
res.end(UTF8_STRING, 'utf8'); res.end(UTF8_STRING, 'utf8');
}); });
server.listen(PORT); server.listen(common.PORT);
http.cat("http://127.0.0.1:"+PORT+"/", "utf8", function (err, data) { http.cat("http://127.0.0.1:"+common.PORT+"/", "utf8", function (err, data) {
if (err) throw err; if (err) throw err;
assert.equal('string', typeof data); assert.equal('string', typeof data);
console.log('here is the response:'); console.log('here is the response:');

9
test/simple/test-http-client-race-2.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
url = require("url"); url = require("url");
@ -26,9 +27,9 @@ var server = http.createServer(function (req, res) {
}); });
res.end(body); res.end(body);
}); });
server.listen(PORT); server.listen(common.PORT);
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
var body1 = ""; var body1 = "";
var body2 = ""; var body2 = "";
@ -57,7 +58,7 @@ req1.addListener('response', function (res1) {
// parser that previously belonged to Client #1. But we're not finished // parser that previously belonged to Client #1. But we're not finished
// with Client #1 yet! // with Client #1 yet!
// //
var client2 = http.createClient(PORT); var client2 = http.createClient(common.PORT);
// //
// At this point, the bug would manifest itself and crash because the // At this point, the bug would manifest itself and crash because the

7
test/simple/test-http-client-race.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
url = require("url"); url = require("url");
@ -12,9 +13,9 @@ var server = http.createServer(function (req, res) {
}); });
res.end(body); res.end(body);
}); });
server.listen(PORT); server.listen(common.PORT);
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
var body1 = ""; var body1 = "";
var body2 = ""; var body2 = "";

9
test/simple/test-http-client-upload.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
var sent_body = ""; var sent_body = "";
@ -22,16 +23,16 @@ var server = http.createServer(function(req, res) {
res.end(); res.end();
}); });
}); });
server.listen(PORT); server.listen(common.PORT);
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
var req = client.request('POST', '/'); var req = client.request('POST', '/');
req.write('1\n'); req.write('1\n');
req.write('2\n'); req.write('2\n');
req.write('3\n'); req.write('3\n');
req.end(); req.end();
error("client finished sending request"); common.error("client finished sending request");
req.addListener('response', function(res) { req.addListener('response', function(res) {
res.setEncoding("utf8"); res.setEncoding("utf8");

7
test/simple/test-http-eof-on-connect.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
http = require("http"); http = require("http");
@ -7,9 +8,9 @@ http = require("http");
// reproduceable on the first packet on the first connection to a server. // reproduceable on the first packet on the first connection to a server.
server = http.createServer(function (req, res) {}); server = http.createServer(function (req, res) {});
server.listen(PORT); server.listen(common.PORT);
net.createConnection(PORT).addListener("connect", function () { net.createConnection(common.PORT).addListener("connect", function () {
this.close(); this.close();
}).addListener("close", function () { }).addListener("close", function () {
server.close(); server.close();

7
test/simple/test-http-exceptions.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
var http = require("http"), var http = require("http"),
sys = require("sys"), sys = require("sys"),
server, server,
@ -27,7 +28,7 @@ function check_reqs() {
} }
function add_client(num) { function add_client(num) {
var req = http.createClient(PORT).request('GET', '/busy/' + num); var req = http.createClient(common.PORT).request('GET', '/busy/' + num);
req.end(); req.end();
req.addListener('response', function(res) { req.addListener('response', function(res) {
@ -46,7 +47,7 @@ function add_client(num) {
return req; return req;
} }
server.listen(PORT, function () { server.listen(common.PORT, function () {
for (req_num = 0; req_num < 4 ; req_num += 1) { for (req_num = 0; req_num < 4 ; req_num += 1) {
client_requests.push(add_client(req_num)); client_requests.push(add_client(req_num));
} }

7
test/simple/test-http-full-response.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
// This test requires the program "ab" // This test requires the program "ab"
http = require("http"); http = require("http");
exec = require("child_process").exec; exec = require("child_process").exec;
@ -19,7 +20,7 @@ server = http.createServer(function (req, res) {
runs = 0; runs = 0;
function runAb(opts, callback) { function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
console.log("ab not installed? skipping test.\n" + stderr); console.log("ab not installed? skipping test.\n" + stderr);
@ -45,7 +46,7 @@ function runAb(opts, callback) {
}); });
} }
server.listen(PORT, function () { server.listen(common.PORT, function () {
runAb("-c 1 -n 10", function () { runAb("-c 1 -n 10", function () {
console.log("-c 1 -n 10 okay"); console.log("-c 1 -n 10 okay");

13
test/simple/test-http-head-request.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
assert = require("assert"); assert = require("assert");
http = require("http"); http = require("http");
@ -8,7 +9,7 @@ sys = require("sys");
body = "hello world\n"; body = "hello world\n";
server = http.createServer(function (req, res) { server = http.createServer(function (req, res) {
error('req: ' + req.method); common.error('req: ' + req.method);
res.writeHead(200, {"Content-Length": body.length}); res.writeHead(200, {"Content-Length": body.length});
res.end(); res.end();
server.close(); server.close();
@ -16,14 +17,14 @@ server = http.createServer(function (req, res) {
var gotEnd = false; var gotEnd = false;
server.listen(PORT, function () { server.listen(common.PORT, function () {
var client = http.createClient(PORT); var client = http.createClient(common.PORT);
var request = client.request("HEAD", "/"); var request = client.request("HEAD", "/");
request.end(); request.end();
request.addListener('response', function (response) { request.addListener('response', function (response) {
error('response start'); common.error('response start');
response.addListener("end", function () { response.addListener("end", function () {
error('response end'); common.error('response end');
gotEnd = true; gotEnd = true;
}); });
}); });

13
test/simple/test-http-head-response-has-no-body.js

@ -1,4 +1,5 @@
require('../common'); common = require("../common");
assert = common.assert
var http = require('http'); var http = require('http');
@ -10,17 +11,17 @@ var server = http.createServer(function(req, res) {
res.writeHead(200); // broken: defaults to TE chunked res.writeHead(200); // broken: defaults to TE chunked
res.end(); res.end();
}); });
server.listen(PORT); server.listen(common.PORT);
responseComplete = false; responseComplete = false;
var req = http.createClient(PORT).request('HEAD', '/') var req = http.createClient(common.PORT).request('HEAD', '/')
error('req'); common.error('req');
req.end(); req.end();
req.addListener('response', function (res) { req.addListener('response', function (res) {
error('response'); common.error('response');
res.addListener('end', function() { res.addListener('end', function() {
error('response end'); common.error('response end');
server.close(); server.close();
responseComplete = true; responseComplete = true;
}); });

7
test/simple/test-http-malformed-request.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
http = require("http"); http = require("http");
url = require("url"); url = require("url");
@ -18,9 +19,9 @@ var s = http.createServer(function (req, res) {
if (++nrequests_completed == nrequests_expected) s.close(); if (++nrequests_completed == nrequests_expected) s.close();
}); });
s.listen(PORT); s.listen(common.PORT);
var c = net.createConnection(PORT); var c = net.createConnection(common.PORT);
c.addListener("connect", function () { c.addListener("connect", function () {
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
c.end(); c.end();

3
test/simple/test-http-parser.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
// The purpose of this test is not to check HTTP compliance but to test the // The purpose of this test is not to check HTTP compliance but to test the
// binding. Tests for pathological http messages should be submitted // binding. Tests for pathological http messages should be submitted

23
test/simple/test-http-proxy.js

@ -1,12 +1,13 @@
require("../common"); common = require("../common");
assert = common.assert
http = require("http"); http = require("http");
url = require("url"); url = require("url");
var PROXY_PORT = PORT; var PROXY_PORT = common.PORT;
var BACKEND_PORT = PORT+1; var BACKEND_PORT = common.PORT+1;
var backend = http.createServer(function (req, res) { var backend = http.createServer(function (req, res) {
debug("backend request"); common.debug("backend request");
res.writeHead(200, {"content-type": "text/plain"}); res.writeHead(200, {"content-type": "text/plain"});
res.write("hello world\n"); res.write("hello world\n");
res.end(); res.end();
@ -14,7 +15,7 @@ var backend = http.createServer(function (req, res) {
var proxy_client = http.createClient(BACKEND_PORT); var proxy_client = http.createClient(BACKEND_PORT);
var proxy = http.createServer(function (req, res) { var proxy = http.createServer(function (req, res) {
debug("proxy req headers: " + JSON.stringify(req.headers)); common.debug("proxy req headers: " + JSON.stringify(req.headers));
var proxy_req = proxy_client.request(url.parse(req.url).pathname); var proxy_req = proxy_client.request(url.parse(req.url).pathname);
proxy_req.end(); proxy_req.end();
proxy_req.addListener('response', function(proxy_res) { proxy_req.addListener('response', function(proxy_res) {
@ -24,7 +25,7 @@ var proxy = http.createServer(function (req, res) {
}); });
proxy_res.addListener("end", function() { proxy_res.addListener("end", function() {
res.end(); res.end();
debug("proxy res"); common.debug("proxy res");
}); });
}); });
}); });
@ -38,25 +39,25 @@ function startReq () {
var client = http.createClient(PROXY_PORT); var client = http.createClient(PROXY_PORT);
var req = client.request("/test"); var req = client.request("/test");
debug("client req") common.debug("client req")
req.addListener('response', function (res) { req.addListener('response', function (res) {
debug("got res"); common.debug("got res");
assert.equal(200, res.statusCode); assert.equal(200, res.statusCode);
res.setBodyEncoding("utf8"); res.setBodyEncoding("utf8");
res.addListener('data', function (chunk) { body += chunk; }); res.addListener('data', function (chunk) { body += chunk; });
res.addListener('end', function () { res.addListener('end', function () {
proxy.close(); proxy.close();
backend.close(); backend.close();
debug("closed both"); common.debug("closed both");
}); });
}); });
req.end(); req.end();
} }
debug("listen proxy") common.debug("listen proxy")
proxy.listen(PROXY_PORT, startReq); proxy.listen(PROXY_PORT, startReq);
debug("listen backend") common.debug("listen backend")
backend.listen(BACKEND_PORT, startReq); backend.listen(BACKEND_PORT, startReq);
process.addListener("exit", function () { process.addListener("exit", function () {

7
test/simple/test-http-server-multiheaders.js

@ -2,7 +2,8 @@
// of the same header as per RFC2616: joining the handful of fields by ', ' // of the same header as per RFC2616: joining the handful of fields by ', '
// that support it, and dropping duplicates for other fields. // that support it, and dropping duplicates for other fields.
require('../common'); common = require("../common");
assert = common.assert
var http = require('http'); var http = require('http');
var srv = http.createServer(function(req, res) { var srv = http.createServer(function(req, res) {
@ -17,8 +18,8 @@ var srv = http.createServer(function(req, res) {
srv.close(); srv.close();
}); });
srv.listen(PORT, function () { srv.listen(common.PORT, function () {
var hc = http.createClient(PORT, 'localhost'); var hc = http.createClient(common.PORT, 'localhost');
var hr = hc.request('/', var hr = hc.request('/',
[ [
['accept', 'abc'], ['accept', 'abc'],

15
test/simple/test-http-server.js

@ -1,4 +1,5 @@
require("../common"); common = require("../common");
assert = common.assert
net = require("net"); net = require("net");
http = require("http"); http = require("http");
url = require("url"); url = require("url");
@ -21,21 +22,21 @@ http.createServer(function (req, res) {
} }
if (req.id == 1) { if (req.id == 1) {
error("req 1"); common.error("req 1");
assert.equal("POST", req.method); assert.equal("POST", req.method);
assert.equal("/quit", url.parse(req.url).pathname); assert.equal("/quit", url.parse(req.url).pathname);
} }
if (req.id == 2) { if (req.id == 2) {
error("req 2"); common.error("req 2");
assert.equal("foo", req.headers['x-x']); assert.equal("foo", req.headers['x-x']);
} }
if (req.id == 3) { if (req.id == 3) {
error("req 3"); common.error("req 3");
assert.equal("bar", req.headers['x-x']); assert.equal("bar", req.headers['x-x']);
this.close(); this.close();
error("server closed"); common.error("server closed");
} }
setTimeout(function () { setTimeout(function () {
@ -44,9 +45,9 @@ http.createServer(function (req, res) {
res.end(); res.end();
}, 1); }, 1);
}).listen(PORT); }).listen(common.PORT);
var c = net.createConnection(PORT); var c = net.createConnection(common.PORT);
c.setEncoding("utf8"); c.setEncoding("utf8");

12
test/simple/test-http-set-timeout.js

@ -1,5 +1,5 @@
require("../common"); common = require("../common");
var sys = require('sys'), assert = common.assert;
http = require('http'); http = require('http');
server = http.createServer(function (req, res) { server = http.createServer(function (req, res) {
@ -7,19 +7,19 @@ server = http.createServer(function (req, res) {
req.connection.setTimeout(500); req.connection.setTimeout(500);
req.connection.addListener('timeout', function(){ req.connection.addListener('timeout', function(){
sys.debug("TIMEOUT"); common.debug("TIMEOUT");
server.close(); server.close();
}); });
}); });
server.listen(PORT, function () { server.listen(common.PORT, function () {
console.log('Server running at http://127.0.0.1:'+PORT+'/'); console.log('Server running at http://127.0.0.1:'+common.PORT+'/');
errorTimer = setTimeout(function () { errorTimer = setTimeout(function () {
throw new Error('Timeout was not sucessful'); throw new Error('Timeout was not sucessful');
}, 2000); }, 2000);
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) { http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
clearTimeout(errorTimer); clearTimeout(errorTimer);
console.log('HTTP REQUEST COMPLETE (this is good)'); console.log('HTTP REQUEST COMPLETE (this is good)');
}); });

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save