Browse Source

:%s/sys.puts/console.log/g

and there was much rejoicing
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
ba792ea202
  1. 12
      benchmark/http_simple.js
  2. 4
      benchmark/run.js
  3. 6
      bin/node-repl
  4. 246
      doc/api.markdown
  5. 5
      doc/index.html
  6. 9
      src/node.js
  7. 4
      test/disabled/test-cat.js
  8. 4
      test/disabled/test-dns.js
  9. 6
      test/disabled/test-eio-race3.js
  10. 4
      test/disabled/test-http-big-proxy-responses.js
  11. 4
      test/disabled/test-http-head-request.js
  12. 2
      test/disabled/test-http-stress.js
  13. 2
      test/disabled/test-remote-module-loading.js
  14. 10
      test/disabled/tls_client.js
  15. 4
      test/disabled/tls_server.js
  16. 2
      test/fixtures/b/c.js
  17. 2
      test/fixtures/child_process_should_emit_error.js
  18. 2
      test/fixtures/print-10-lines.js
  19. 2
      test/message/2100bytes.js
  20. 2
      test/message/hello_world.js
  21. 10
      test/message/undefined_reference_in_new_context.out
  22. 2
      test/pummel/test-child-process-spawn-loop.js
  23. 6
      test/pummel/test-http-client-reconnect-bug.js
  24. 6
      test/pummel/test-keep-alive.js
  25. 6
      test/pummel/test-net-many-clients.js
  26. 8
      test/pummel/test-net-pause.js
  27. 12
      test/pummel/test-net-pingpong-delay.js
  28. 6
      test/pummel/test-net-pingpong.js
  29. 10
      test/pummel/test-net-throttle.js
  30. 18
      test/pummel/test-net-timeout.js
  31. 6
      test/pummel/test-net-tls.js
  32. 4
      test/pummel/test-timers.js
  33. 4
      test/pummel/test-watch-file.js
  34. 4
      test/simple/test-buffer.js
  35. 4
      test/simple/test-child-process-buffering.js
  36. 14
      test/simple/test-child-process-custom-fds.js
  37. 2
      test/simple/test-child-process-env.js
  38. 6
      test/simple/test-child-process-ipc.js
  39. 4
      test/simple/test-child-process-stdin.js
  40. 6
      test/simple/test-child-process-stdout-flush.js
  41. 2
      test/simple/test-crypto.js
  42. 12
      test/simple/test-dgram-pingpong.js
  43. 10
      test/simple/test-eio-race.js
  44. 6
      test/simple/test-eio-race2.js
  45. 2
      test/simple/test-eio-race4.js
  46. 2
      test/simple/test-error-reporting.js
  47. 6
      test/simple/test-event-emitter-add-listeners.js
  48. 6
      test/simple/test-event-emitter-remove-listeners.js
  49. 6
      test/simple/test-exception-handler.js
  50. 12
      test/simple/test-exec.js
  51. 4
      test/simple/test-executable-path.js
  52. 2
      test/simple/test-file-read-noexist.js
  53. 2
      test/simple/test-fs-chmod.js
  54. 2
      test/simple/test-fs-realpath.js
  55. 16
      test/simple/test-fs-stat.js
  56. 4
      test/simple/test-fs-symlink.js
  57. 8
      test/simple/test-fs-write.js
  58. 2
      test/simple/test-http-1.0.js
  59. 2
      test/simple/test-http-304.js
  60. 8
      test/simple/test-http-cat.js
  61. 4
      test/simple/test-http-chunked.js
  62. 6
      test/simple/test-http-client-upload.js
  63. 4
      test/simple/test-http-exceptions.js
  64. 8
      test/simple/test-http-full-response.js
  65. 2
      test/simple/test-http-malformed-request.js
  66. 8
      test/simple/test-http-parser.js
  67. 6
      test/simple/test-http-set-timeout.js
  68. 4
      test/simple/test-http-tls.js
  69. 6
      test/simple/test-http-wget.js
  70. 2
      test/simple/test-http-write-empty-string.js
  71. 2
      test/simple/test-memory-usage.js
  72. 10
      test/simple/test-mkdir-rmdir.js
  73. 2
      test/simple/test-module-loading.js
  74. 6
      test/simple/test-net-binary.js
  75. 14
      test/simple/test-net-pingpong.js
  76. 10
      test/simple/test-net-reconnect.js
  77. 2
      test/simple/test-net-tls.js
  78. 6
      test/simple/test-next-tick-ordering.js
  79. 8
      test/simple/test-readdir.js
  80. 4
      test/simple/test-regression-object-prototype.js
  81. 8
      test/simple/test-signal-handler.js
  82. 6
      test/simple/test-signal-unregister.js
  83. 4
      test/simple/test-stdin-from-file.js
  84. 8
      test/simple/test-stdout-to-file.js
  85. 2
      test/simple/test-string-decoder.js
  86. 2
      test/simple/test-utf8-scripts.js

12
benchmark/http_simple.js

@ -3,14 +3,14 @@ Buffer = require("buffer").Buffer;
port = parseInt(process.env.PORT || 8000); port = parseInt(process.env.PORT || 8000);
var puts = require("sys").puts; var console.log = require("sys").console.log;
var old = (process.argv[2] == 'old'); var old = (process.argv[2] == 'old');
puts('pid ' + process.pid); console.log('pid ' + process.pid);
http = require(old ? "http_old" : 'http'); http = require(old ? "http_old" : 'http');
if (old) puts('old version'); if (old) console.log('old version');
fixed = "" fixed = ""
for (var i = 0; i < 20*1024; i++) { for (var i = 0; i < 20*1024; i++) {
@ -32,7 +32,7 @@ http.createServer(function (req, res) {
if (n <= 0) if (n <= 0)
throw "bytes called with n <= 0" throw "bytes called with n <= 0"
if (stored[n] === undefined) { if (stored[n] === undefined) {
puts("create stored[n]"); console.log("create stored[n]");
stored[n] = ""; stored[n] = "";
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
stored[n] += "C" stored[n] += "C"
@ -44,7 +44,7 @@ http.createServer(function (req, res) {
var n = parseInt(arg, 10) var n = parseInt(arg, 10)
if (n <= 0) throw new Error("bytes called with n <= 0"); if (n <= 0) throw new Error("bytes called with n <= 0");
if (storedBuffer[n] === undefined) { if (storedBuffer[n] === undefined) {
puts("create storedBuffer[n]"); console.log("create storedBuffer[n]");
storedBuffer[n] = new Buffer(n); storedBuffer[n] = new Buffer(n);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
storedBuffer[n][i] = "C".charCodeAt(0); storedBuffer[n][i] = "C".charCodeAt(0);
@ -79,4 +79,4 @@ http.createServer(function (req, res) {
} }
}).listen(port); }).listen(port);
puts('Listening at http://127.0.0.1:'+port+'/'); console.log('Listening at http://127.0.0.1:'+port+'/');

4
benchmark/run.js

@ -22,9 +22,9 @@ function runNext (i) {
sys.print(benchmarks[i] + ": "); sys.print(benchmarks[i] + ": ");
exec(benchmarks[i], function (elapsed, code) { exec(benchmarks[i], function (elapsed, code) {
if (code != 0) { if (code != 0) {
sys.puts("ERROR "); console.log("ERROR ");
} }
sys.puts(elapsed); console.log(elapsed);
runNext(i+1); runNext(i+1);
}); });
}; };

6
bin/node-repl

@ -1,9 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
var puts = require("sys").puts; console.log("Type '.help' for options.");
console.log("(The REPL can also be started by typing 'node' without arguments)");
puts("Type '.help' for options.");
puts("(The REPL can also be started by typing 'node' without arguments)");
require('repl').start(); require('repl').start();

246
doc/api.markdown

@ -6,15 +6,14 @@ node(1) -- evented I/O for V8 JavaScript
An example of a web server written with Node which responds with 'Hello An example of a web server written with Node which responds with 'Hello
World': World':
var sys = require('sys'), var http = require('http');
http = require('http');
http.createServer(function (request, response) { http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'}); response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n'); response.end('Hello World\n');
}).listen(8124); }).listen(8124);
sys.puts('Server running at http://127.0.0.1:8124/'); console.log('Server running at http://127.0.0.1:8124/');
To run the server, put the code into a file called `example.js` and execute To run the server, put the code into a file called `example.js` and execute
it with the node program it with the node program
@ -85,13 +84,12 @@ of `'utf8'` encoding, the method will not write partial characters.
Example: write a utf8 string into a buffer, then print it Example: write a utf8 string into a buffer, then print it
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
buf = new Buffer(256), buf = new Buffer(256),
len; len;
len = buf.write('\u00bd + \u00bc = \u00be', 'utf8', 0); len = buf.write('\u00bd + \u00bc = \u00be', 'utf8', 0);
sys.puts(len + " bytes: " + buf.toString('utf8', 0, len)); console.log(len + " bytes: " + buf.toString('utf8', 0, len));
// 12 bytes: ½ + ¼ = ¾ // 12 bytes: ½ + ¼ = ¾
@ -111,8 +109,7 @@ so the legal range is between `0x00` and `0xFF` hex or `0` and `255`.
Example: copy an ASCII string into a buffer, one byte at a time: Example: copy an ASCII string into a buffer, one byte at a time:
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
str = "node.js", str = "node.js",
buf = new Buffer(str.length), buf = new Buffer(str.length),
i; i;
@ -121,7 +118,7 @@ Example: copy an ASCII string into a buffer, one byte at a time:
buf[i] = str.charCodeAt(i); buf[i] = str.charCodeAt(i);
} }
sys.puts(buf); console.log(buf);
// node.js // node.js
@ -134,11 +131,10 @@ string.
Example: Example:
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
str = '\u00bd + \u00bc = \u00be'; str = '\u00bd + \u00bc = \u00be';
sys.puts(str + ": " + str.length + " characters, " + console.log(str + ": " + str.length + " characters, " +
Buffer.byteLength(str, 'utf8') + " bytes"); Buffer.byteLength(str, 'utf8') + " bytes");
// ½ + ¼ = ¾: 9 characters, 12 bytes // ½ + ¼ = ¾: 9 characters, 12 bytes
@ -150,13 +146,12 @@ The size of the buffer in bytes. Note that this is not necessarily the size
of the contents. `length` refers to the amount of memory allocated for the of the contents. `length` refers to the amount of memory allocated for the
buffer object. It does not change when the contents of the buffer are changed. buffer object. It does not change when the contents of the buffer are changed.
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
buf = new Buffer(1234); buf = new Buffer(1234);
sys.puts(buf.length); console.log(buf.length);
buf.write("some string", "ascii", 0); buf.write("some string", "ascii", 0);
sys.puts(buf.length); console.log(buf.length);
// 1234 // 1234
// 1234 // 1234
@ -168,8 +163,7 @@ Does a memcpy() between buffers.
Example: build two Buffers, then copy `buf1` from byte 16 through byte 20 Example: build two Buffers, then copy `buf1` from byte 16 through byte 20
into `buf2`, starting at the 8th byte in `buf2`. into `buf2`, starting at the 8th byte in `buf2`.
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
buf1 = new Buffer(26), buf1 = new Buffer(26),
buf2 = new Buffer(26), buf2 = new Buffer(26),
i; i;
@ -180,7 +174,7 @@ into `buf2`, starting at the 8th byte in `buf2`.
} }
buf1.copy(buf2, 8, 16, 20); buf1.copy(buf2, 8, 16, 20);
sys.puts(buf2.toString('ascii', 0, 25)); console.log(buf2.toString('ascii', 0, 25));
// !!!!!!!!qrst!!!!!!!!!!!!! // !!!!!!!!qrst!!!!!!!!!!!!!
@ -196,8 +190,7 @@ indexes.
Example: build a Buffer with the ASCII alphabet, take a slice, then modify one byte Example: build a Buffer with the ASCII alphabet, take a slice, then modify one byte
from the original Buffer. from the original Buffer.
var sys = require('sys'), var Buffer = require('buffer').Buffer,
Buffer = require('buffer').Buffer,
buf1 = new Buffer(26), buf2, buf1 = new Buffer(26), buf2,
i; i;
@ -206,9 +199,9 @@ from the original Buffer.
} }
buf2 = buf1.slice(0, 3); buf2 = buf1.slice(0, 3);
sys.puts(buf2.toString('ascii', 0, buf2.length)); console.log(buf2.toString('ascii', 0, buf2.length));
buf1[0] = 33; buf1[0] = 33;
sys.puts(buf2.toString('ascii', 0, buf2.length)); console.log(buf2.toString('ascii', 0, buf2.length));
// abc // abc
// !bc // !bc
@ -254,7 +247,7 @@ terminate execution and display the exception's stack trace.
Adds a listener to the end of the listeners array for the specified event. Adds a listener to the end of the listeners array for the specified event.
server.addListener('stream', function (stream) { server.addListener('stream', function (stream) {
sys.puts('someone connected!'); console.log('someone connected!');
}); });
@ -415,10 +408,8 @@ An array of search paths for `require()`. This array can be modified to add cus
Example: add a new path to the beginning of the search list Example: add a new path to the beginning of the search list
var sys = require('sys');
require.paths.unshift('/usr/local/node'); require.paths.unshift('/usr/local/node');
sys.puts(require.paths); console.log(require.paths);
// /usr/local/node,/Users/mjr/.node_libraries // /usr/local/node,/Users/mjr/.node_libraries
@ -433,9 +424,8 @@ The dirname of the script being executed.
Example: running `node example.js` from `/Users/mjr` Example: running `node example.js` from `/Users/mjr`
var sys = require('sys'); console.log(__filename);
sys.puts(__filename); console.log(__dirname);
sys.puts(__dirname);
// /Users/mjr/example.js // /Users/mjr/example.js
// /Users/mjr // /Users/mjr
@ -464,13 +454,11 @@ timers may not be scheduled.
Example of listening for `exit`: Example of listening for `exit`:
var sys = require('sys');
process.addListener('exit', function () { process.addListener('exit', function () {
process.nextTick(function () { process.nextTick(function () {
sys.puts('This will not run'); console.log('This will not run');
}); });
sys.puts('About to exit.'); console.log('About to exit.');
}); });
### Event: 'uncaughtException' ### Event: 'uncaughtException'
@ -483,19 +471,17 @@ a stack trace and exit) will not occur.
Example of listening for `uncaughtException`: Example of listening for `uncaughtException`:
var sys = require('sys');
process.addListener('uncaughtException', function (err) { process.addListener('uncaughtException', function (err) {
sys.puts('Caught exception: ' + err); console.log('Caught exception: ' + err);
}); });
setTimeout(function () { setTimeout(function () {
sys.puts('This will still run.'); console.log('This will still run.');
}, 500); }, 500);
// Intentionally cause an exception, but don't catch it. // Intentionally cause an exception, but don't catch it.
nonexistentFunc(); nonexistentFunc();
sys.puts('This will not run.'); console.log('This will not run.');
Note that `uncaughtException` is a very crude mechanism for exception Note that `uncaughtException` is a very crude mechanism for exception
handling. Using try / catch in your program will give you more control over handling. Using try / catch in your program will give you more control over
@ -512,11 +498,10 @@ standard POSIX signal names such as SIGINT, SIGUSR1, etc.
Example of listening for `SIGINT`: Example of listening for `SIGINT`:
var sys = require('sys'), var stdin = process.openStdin();
stdin = process.openStdin();
process.addListener('SIGINT', function () { process.addListener('SIGINT', function () {
sys.puts('Got SIGINT. Press Control-D to exit.'); console.log('Got SIGINT. Press Control-D to exit.');
}); });
An easy way to send the `SIGINT` signal is with `Control-C` in most terminal An easy way to send the `SIGINT` signal is with `Control-C` in most terminal
@ -527,9 +512,9 @@ programs.
A writable stream to `stdout`. A writable stream to `stdout`.
Example: the definition of `sys.puts` Example: the definition of `console.log`
exports.puts = function (d) { console.log = function (d) {
process.stdout.write(d + '\n'); process.stdout.write(d + '\n');
}; };
@ -560,10 +545,8 @@ An array containing the command line arguments. The first element will be
next elements will be any additional command line arguments. next elements will be any additional command line arguments.
// print process.argv // print process.argv
var sys = require('sys');
process.argv.forEach(function (val, index, array) { process.argv.forEach(function (val, index, array) {
sys.puts(index + ': ' + val); console.log(index + ': ' + val);
}); });
This will generate: This will generate:
@ -585,15 +568,13 @@ This is the absolute pathname of the executable that started the process.
Changes the current working directory of the process or throws an exception if that fails. Changes the current working directory of the process or throws an exception if that fails.
var sys = require('sys'); console.log('Starting directory: ' + process.cwd());
sys.puts('Starting directory: ' + process.cwd());
try { try {
process.chdir('/tmp'); process.chdir('/tmp');
sys.puts('New directory: ' + process.cwd()); console.log('New directory: ' + process.cwd());
} }
catch (err) { catch (err) {
sys.puts('chdir: ' + err); console.log('chdir: ' + err);
} }
@ -605,14 +586,13 @@ will be used as a filename if a stack trace is generated by the compiled code.
Example of using `process.compile` and `eval` to run the same code: Example of using `process.compile` and `eval` to run the same code:
var sys = require('sys'), var localVar = 123,
localVar = 123,
compiled, evaled; compiled, evaled;
compiled = process.compile('localVar = 1;', 'myfile.js'); compiled = process.compile('localVar = 1;', 'myfile.js');
sys.puts('localVar: ' + localVar + ', compiled: ' + compiled); console.log('localVar: ' + localVar + ', compiled: ' + compiled);
evaled = eval('localVar = 1;'); evaled = eval('localVar = 1;');
sys.puts('localVar: ' + localVar + ', evaled: ' + evaled); console.log('localVar: ' + localVar + ', evaled: ' + evaled);
// localVar: 123, compiled: 1 // localVar: 123, compiled: 1
// localVar: 1, evaled: 1 // localVar: 1, evaled: 1
@ -629,7 +609,7 @@ See also: `Script`
Returns the current working directory of the process. Returns the current working directory of the process.
require('sys').puts('Current directory: ' + process.cwd()); console.log('Current directory: ' + process.cwd());
### process.env ### process.env
@ -653,15 +633,13 @@ The shell that executed node should see the exit code as 1.
Gets/sets the group identity of the process. (See setgid(2).) This is the numerical group id, not the group name. Gets/sets the group identity of the process. (See setgid(2).) This is the numerical group id, not the group name.
var sys = require('sys'); console.log('Current gid: ' + process.getgid());
sys.puts('Current gid: ' + process.getgid());
try { try {
process.setgid(501); process.setgid(501);
sys.puts('New gid: ' + process.getgid()); console.log('New gid: ' + process.getgid());
} }
catch (err) { catch (err) {
sys.puts('Failed to set gid: ' + err); console.log('Failed to set gid: ' + err);
} }
@ -669,15 +647,13 @@ Gets/sets the group identity of the process. (See setgid(2).) This is the numer
Gets/sets the user identity of the process. (See setuid(2).) This is the numerical userid, not the username. Gets/sets the user identity of the process. (See setuid(2).) This is the numerical userid, not the username.
var sys = require('sys'); console.log('Current uid: ' + process.getuid());
sys.puts('Current uid: ' + process.getuid());
try { try {
process.setuid(501); process.setuid(501);
sys.puts('New uid: ' + process.getuid()); console.log('New uid: ' + process.getuid());
} }
catch (err) { catch (err) {
sys.puts('Failed to set uid: ' + err); console.log('Failed to set uid: ' + err);
} }
@ -685,13 +661,13 @@ Gets/sets the user identity of the process. (See setuid(2).) This is the numeri
A compiled-in property that exposes `NODE_VERSION`. A compiled-in property that exposes `NODE_VERSION`.
require('sys').puts('Version: ' + process.version); console.log('Version: ' + process.version);
### process.installPrefix ### process.installPrefix
A compiled-in property that exposes `NODE_PREFIX`. A compiled-in property that exposes `NODE_PREFIX`.
require('sys').puts('Prefix: ' + process.installPrefix); console.log('Prefix: ' + process.installPrefix);
### process.kill(pid, signal) ### process.kill(pid, signal)
@ -707,14 +683,12 @@ may do something other than kill the target process.
Example of sending a signal to yourself: Example of sending a signal to yourself:
var sys = require('sys');
process.addListener('SIGHUP', function () { process.addListener('SIGHUP', function () {
sys.puts('Got SIGHUP signal.'); console.log('Got SIGHUP signal.');
}); });
setTimeout(function () { setTimeout(function () {
sys.puts('Exiting.'); console.log('Exiting.');
process.exit(0); process.exit(0);
}, 100); }, 100);
@ -725,14 +699,14 @@ Example of sending a signal to yourself:
The PID of the process. The PID of the process.
require('sys').puts('This process is pid ' + process.pid); console.log('This process is pid ' + process.pid);
### process.platform ### process.platform
What platform you're running on. `'linux2'`, `'darwin'`, etc. What platform you're running on. `'linux2'`, `'darwin'`, etc.
require('sys').puts('This platform is ' + process.platform); console.log('This platform is ' + process.platform);
### process.memoryUsage() ### process.memoryUsage()
@ -741,7 +715,7 @@ Returns an object describing the memory usage of the Node process.
var sys = require('sys'); var sys = require('sys');
sys.puts(sys.inspect(process.memoryUsage())); console.log(sys.inspect(process.memoryUsage()));
This will generate: This will generate:
@ -760,10 +734,8 @@ On the next loop around the event loop call this callback.
This is *not* a simple alias to `setTimeout(fn, 0)`, it's much more This is *not* a simple alias to `setTimeout(fn, 0)`, it's much more
efficient. efficient.
var sys = require('sys');
process.nextTick(function () { process.nextTick(function () {
sys.puts('nextTick callback'); console.log('nextTick callback');
}); });
@ -773,11 +745,10 @@ Sets or read the process's file mode creation mask. Child processes inherit
the mask from the parent process. Returns the old mask if `mask` argument is the mask from the parent process. Returns the old mask if `mask` argument is
given, otherwise returns the current mask. given, otherwise returns the current mask.
var sys = require('sys'), var oldmask, newmask = 0644;
oldmask, newmask = 0644;
oldmask = process.umask(newmask); oldmask = process.umask(newmask);
sys.puts('Changed umask from: ' + oldmask.toString(8) + console.log('Changed umask from: ' + oldmask.toString(8) +
' to ' + newmask.toString(8)); ' to ' + newmask.toString(8));
@ -788,16 +759,9 @@ These functions are in the module `'sys'`. Use `require('sys')` to access
them. them.
### sys.puts(string)
Outputs `string` and a trailing newline to `stdout`.
require('sys').puts('String with a newline');
### sys.print(string) ### sys.print(string)
Like `puts()` but without the trailing newline. Like `console.log()` but without the trailing newline.
require('sys').print('String with no newline'); require('sys').print('String with no newline');
@ -834,7 +798,7 @@ Example of inspecting all properties of the `sys` object:
var sys = require('sys'); var sys = require('sys');
sys.puts(sys.inspect(sys, true, null)); console.log(sys.inspect(sys, true, null));
### sys.pump(readableStream, writeableStream, [callback]) ### sys.pump(readableStream, writeableStream, [callback])
@ -920,19 +884,18 @@ Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit cod
}); });
ls.addListener('exit', function (code) { ls.addListener('exit', function (code) {
sys.puts('child process exited with code ' + code); console.log('child process exited with code ' + code);
}); });
Example of checking for failed exec: Example of checking for failed exec:
var sys = require('sys'), var spawn = require('child_process').spawn,
spawn = require('child_process').spawn,
child = spawn('bad_command'); child = spawn('bad_command');
child.stderr.addListener('data', function (data) { child.stderr.addListener('data', function (data) {
if (/^execvp\(\)/.test(data.asciiSlice(0,data.length))) { if (/^execvp\(\)/.test(data.asciiSlice(0,data.length))) {
sys.puts('Failed to start child process.'); console.log('Failed to start child process.');
} }
}); });
@ -945,12 +908,11 @@ See also: `child_process.exec()`
Send a signal to the child process. If no argument is given, the process will Send a signal to the child process. If no argument is given, the process will
be sent `'SIGTERM'`. See `signal(7)` for a list of available signals. be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
var sys = require('sys'), var spawn = require('child_process').spawn,
spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']); grep = spawn('grep', ['ssh']);
grep.addListener('exit', function (code, signal) { grep.addListener('exit', function (code, signal) {
sys.puts('child process terminated due to receipt of signal '+signal); console.log('child process terminated due to receipt of signal '+signal);
}); });
// send SIGHUP to process // send SIGHUP to process
@ -968,11 +930,10 @@ The PID of the child process.
Example: Example:
var sys = require('sys'), var spawn = require('child_process').spawn,
spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']); grep = spawn('grep', ['ssh']);
sys.puts('Spawned child pid: ' + grep.pid); console.log('Spawned child pid: ' + grep.pid);
grep.stdin.end(); grep.stdin.end();
@ -999,7 +960,7 @@ Example: A very elaborate way to run 'ps ax | grep ssh'
ps.addListener('exit', function (code) { ps.addListener('exit', function (code) {
if (code !== 0) { if (code !== 0) {
sys.puts('ps process exited with code ' + code); console.log('ps process exited with code ' + code);
} }
grep.stdin.end(); grep.stdin.end();
}); });
@ -1014,7 +975,7 @@ Example: A very elaborate way to run 'ps ax | grep ssh'
grep.addListener('exit', function (code) { grep.addListener('exit', function (code) {
if (code !== 0) { if (code !== 0) {
sys.puts('grep process exited with code ' + code); console.log('grep process exited with code ' + code);
} }
}); });
@ -1025,12 +986,11 @@ Closes the child process's `stdin` stream. This often causes the child process
Example: Example:
var sys = require('sys'), var spawn = require('child_process').spawn,
spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']); grep = spawn('grep', ['ssh']);
grep.addListener('exit', function (code) { grep.addListener('exit', function (code) {
sys.puts('child process exited with code ' + code); console.log('child process exited with code ' + code);
}); });
grep.stdin.end(); grep.stdin.end();
@ -1050,7 +1010,7 @@ output, and return it all in a callback.
sys.print('stdout: ' + stdout); sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr); sys.print('stderr: ' + stderr);
if (error !== null) { if (error !== null) {
sys.puts('exec error: ' + error); console.log('exec error: ' + error);
} }
}); });
@ -1091,17 +1051,16 @@ runs it and returns the result. Running code does not have access to local scope
Example of using `Script.runInThisContext` and `eval` to run the same code: Example of using `Script.runInThisContext` and `eval` to run the same code:
var sys = require('sys'), var localVar = 123,
localVar = 123,
usingscript, evaled, usingscript, evaled,
Script = process.binding('evals').Script; Script = process.binding('evals').Script;
usingscript = Script.runInThisContext('localVar = 1;', usingscript = Script.runInThisContext('localVar = 1;',
'myfile.js'); 'myfile.js');
sys.puts('localVar: ' + localVar + ', usingscript: ' + console.log('localVar: ' + localVar + ', usingscript: ' +
usingscript); usingscript);
evaled = eval('localVar = 1;'); evaled = eval('localVar = 1;');
sys.puts('localVar: ' + localVar + ', evaled: ' + console.log('localVar: ' + localVar + ', evaled: ' +
evaled); evaled);
// localVar: 123, usingscript: 1 // localVar: 123, usingscript: 1
@ -1133,7 +1092,7 @@ These globals are contained in the sandbox.
Script.runInNewContext( Script.runInNewContext(
'count += 1; name = "kitty"', sandbox, 'myfile.js'); 'count += 1; name = "kitty"', sandbox, 'myfile.js');
sys.puts(sys.inspect(sandbox)); console.log(sys.inspect(sandbox));
// { animal: 'cat', count: 3, name: 'kitty' } // { animal: 'cat', count: 3, name: 'kitty' }
@ -1166,8 +1125,7 @@ Running code does not have access to local scope, but does have access to the `g
Example of using `script.runInThisContext` to compile code once and run it multiple times: Example of using `script.runInThisContext` to compile code once and run it multiple times:
var sys = require('sys'), var Script = process.binding('evals').Script,
Script = process.binding('evals').Script,
scriptObj, i; scriptObj, i;
globalVar = 0; globalVar = 0;
@ -1178,7 +1136,7 @@ Example of using `script.runInThisContext` to compile code once and run it multi
scriptObj.runInThisContext(); scriptObj.runInThisContext();
} }
sys.puts(globalVar); console.log(globalVar);
// 1000 // 1000
@ -1207,7 +1165,7 @@ These globals are contained in the sandbox.
scriptObj.runInNewContext(sandbox); scriptObj.runInNewContext(sandbox);
} }
sys.puts(sys.inspect(sandbox)); console.log(sys.inspect(sandbox));
// { animal: 'cat', count: 12, name: 'kitty' } // { animal: 'cat', count: 12, name: 'kitty' }
@ -1229,32 +1187,30 @@ completed successfully, then the first argument will be `null` or `undefined`.
Here is an example of the asynchronous version: Here is an example of the asynchronous version:
var fs = require('fs'), var fs = require('fs');
sys = require('sys');
fs.unlink('/tmp/hello', function (err) { fs.unlink('/tmp/hello', function (err) {
if (err) throw err; if (err) throw err;
sys.puts('successfully deleted /tmp/hello'); console.log('successfully deleted /tmp/hello');
}); });
Here is the synchronous version: Here is the synchronous version:
var fs = require('fs'), var fs = require('fs');
sys = require('sys');
fs.unlinkSync('/tmp/hello') fs.unlinkSync('/tmp/hello')
sys.puts('successfully deleted /tmp/hello'); console.log('successfully deleted /tmp/hello');
With the asynchronous methods there is no guaranteed ordering. So the With the asynchronous methods there is no guaranteed ordering. So the
following is prone to error: following is prone to error:
fs.rename('/tmp/hello', '/tmp/world', function (err) { fs.rename('/tmp/hello', '/tmp/world', function (err) {
if (err) throw err; if (err) throw err;
sys.puts('renamed complete'); console.log('renamed complete');
}); });
fs.stat('/tmp/world', function (err, stats) { fs.stat('/tmp/world', function (err, stats) {
if (err) throw err; if (err) throw err;
sys.puts('stats: ' + JSON.stringify(stats)); console.log('stats: ' + JSON.stringify(stats));
}); });
It could be that `fs.stat` is executed before `fs.rename`. It could be that `fs.stat` is executed before `fs.rename`.
@ -1264,7 +1220,7 @@ The correct way to do this is to chain the callbacks.
if (err) throw err; if (err) throw err;
fs.stat('/tmp/world', function (err, stats) { fs.stat('/tmp/world', function (err, stats) {
if (err) throw err; if (err) throw err;
sys.puts('stats: ' + JSON.stringify(stats)); console.log('stats: ' + JSON.stringify(stats));
}); });
}); });
@ -1448,7 +1404,7 @@ Asynchronously reads the entire contents of a file. Example:
fs.readFile('/etc/passwd', function (err, data) { fs.readFile('/etc/passwd', function (err, data) {
if (err) throw err; if (err) throw err;
sys.puts(data); console.log(data);
}); });
The callback is passed two arguments `(err, data)`, where `data` is the The callback is passed two arguments `(err, data)`, where `data` is the
@ -1471,7 +1427,7 @@ Asynchronously writes data to a file. Example:
fs.writeFile('message.txt', 'Hello Node', function (err) { fs.writeFile('message.txt', 'Hello Node', function (err) {
if (err) throw err; if (err) throw err;
sys.puts('It\'s saved!'); console.log('It\'s saved!');
}); });
### fs.writeFileSync(filename, data, encoding='utf8') ### fs.writeFileSync(filename, data, encoding='utf8')
@ -1491,8 +1447,8 @@ The `listener` gets two arguments the current stat object and the previous
stat object: stat object:
fs.watchFile(f, function (curr, prev) { fs.watchFile(f, function (curr, prev) {
sys.puts('the current mtime is: ' + curr.mtime); console.log('the current mtime is: ' + curr.mtime);
sys.puts('the previous mtime was: ' + prev.mtime); console.log('the previous mtime was: ' + prev.mtime);
}); });
These stat objects are instances of `fs.Stat`. These stat objects are instances of `fs.Stat`.
@ -1874,18 +1830,17 @@ stream. _Currently the implementation does not pipeline requests._
Example of connecting to `google.com`: Example of connecting to `google.com`:
var sys = require('sys'), var http = require('http');
http = require('http');
var google = http.createClient(80, 'www.google.com'); var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/', var request = google.request('GET', '/',
{'host': 'www.google.com'}); {'host': 'www.google.com'});
request.end(); request.end();
request.addListener('response', function (response) { request.addListener('response', function (response) {
sys.puts('STATUS: ' + response.statusCode); console.log('STATUS: ' + response.statusCode);
sys.puts('HEADERS: ' + JSON.stringify(response.headers)); console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8'); response.setEncoding('utf8');
response.addListener('data', function (chunk) { response.addListener('data', function (chunk) {
sys.puts('BODY: ' + chunk); console.log('BODY: ' + chunk);
}); });
}); });
@ -1950,7 +1905,7 @@ event, the entire body will be caught.
// Good // Good
request.addListener('response', function (response) { request.addListener('response', function (response) {
response.addListener('data', function (chunk) { response.addListener('data', function (chunk) {
sys.puts('BODY: ' + chunk); console.log('BODY: ' + chunk);
}); });
}); });
@ -1958,7 +1913,7 @@ event, the entire body will be caught.
request.addListener('response', function (response) { request.addListener('response', function (response) {
setTimeout(function () { setTimeout(function () {
response.addListener('data', function (chunk) { response.addListener('data', function (chunk) {
sys.puts('BODY: ' + chunk); console.log('BODY: ' + chunk);
}); });
}, 10); }, 10);
}); });
@ -2433,22 +2388,21 @@ Use `require('dns')` to access this module.
Here is an example which resolves `'www.google.com'` then reverse Here is an example which resolves `'www.google.com'` then reverse
resolves the IP addresses which are returned. resolves the IP addresses which are returned.
var dns = require('dns'), var dns = require('dns');
sys = require('sys');
dns.resolve4('www.google.com', function (err, addresses) { dns.resolve4('www.google.com', function (err, addresses) {
if (err) throw err; if (err) throw err;
sys.puts('addresses: ' + JSON.stringify(addresses)); console.log('addresses: ' + JSON.stringify(addresses));
for (var i = 0; i < addresses.length; i++) { for (var i = 0; i < addresses.length; i++) {
var a = addresses[i]; var a = addresses[i];
dns.reverse(a, function (err, domains) { dns.reverse(a, function (err, domains) {
if (err) { if (err) {
sys.puts('reverse for ' + a + ' failed: ' + console.log('reverse for ' + a + ' failed: ' +
err.message); err.message);
} else { } else {
sys.puts('reverse for ' + a + ': ' + console.log('reverse for ' + a + ': ' +
JSON.stringify(domains)); JSON.stringify(domains));
} }
}); });
@ -2789,7 +2743,7 @@ dropped into the REPL. It has simplistic emacs line-editting.
node> a = [ 1, 2, 3]; node> a = [ 1, 2, 3];
[ 1, 2, 3 ] [ 1, 2, 3 ]
node> a.forEach(function (v) { node> a.forEach(function (v) {
... sys.puts(v); ... console.log(v);
... }); ... });
1 1
2 2
@ -2814,8 +2768,7 @@ will share the same global object but will have unique I/O.
Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket: Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket:
var sys = require("sys"), var net = require("net"),
net = require("net"),
repl = require("repl"); repl = require("repl");
connections = 0; connections = 0;
@ -2892,9 +2845,8 @@ one-to-one correspondence. As an example, `foo.js` loads the module
The contents of `foo.js`: The contents of `foo.js`:
var circle = require('./circle'), var circle = require('./circle');
sys = require('sys'); console.log( 'The area of a circle of radius 4 is '
sys.puts( 'The area of a circle of radius 4 is '
+ circle.area(4)); + circle.area(4));
The contents of `circle.js`: The contents of `circle.js`:

5
doc/index.html

@ -42,13 +42,12 @@
</p> </p>
<pre> <pre>
var sys = require('sys'), var http = require('http');
http = require('http');
http.createServer(function (req, res) { http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n'); res.end('Hello World\n');
}).listen(8124, "127.0.0.1"); }).listen(8124, "127.0.0.1");
sys.puts('Server running at http://127.0.0.1:8124/'); console.log('Server running at http://127.0.0.1:8124/');
</pre> </pre>
<p> <p>

9
src/node.js

@ -187,6 +187,13 @@ process.openStdin = function () {
}; };
global.console = {};
global.console.log = function (x) {
process.stdout.write(x + '\n');
};
process.exit = function (code) { process.exit = function (code) {
process.emit("exit"); process.emit("exit");
process.reallyExit(code); process.reallyExit(code);
@ -209,7 +216,7 @@ if (process.argv[1]) {
} else { } else {
// No arguments, run the repl // No arguments, run the repl
var repl = module.requireNative('repl'); var repl = module.requireNative('repl');
process.stdout.write("Type '.help' for options.\n"); console.log("Type '.help' for options.");
repl.start(); repl.start();
} }

4
test/disabled/test-cat.js

@ -1,11 +1,11 @@
require("../common.js"); require("../common.js");
http = require("/http.js"); http = require("/http.js");
puts("hello world"); console.log("hello world");
var body = "exports.A = function() { return 'A';}"; var body = "exports.A = function() { return 'A';}";
var server = http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
puts("req?"); console.log("req?");
res.sendHeader(200, { res.sendHeader(200, {
"Content-Length": body.length, "Content-Length": body.length,
"Content-Type": "text/plain" "Content-Type": "text/plain"

4
test/disabled/test-dns.js

@ -126,7 +126,7 @@ function cmpResults(expected, result, ttl, cname) {
if (expected.length == 1 && expected[0] == '3(NXDOMAIN)' && result.length == 0) { if (expected.length == 1 && expected[0] == '3(NXDOMAIN)' && result.length == 0) {
// it's ok, dig returns NXDOMAIN, while dns module returns nothing // it's ok, dig returns NXDOMAIN, while dns module returns nothing
} else { } else {
puts('---WARNING---\nexpected ' + expected + '\nresult ' + result + '\n-------------'); console.log('---WARNING---\nexpected ' + expected + '\nresult ' + result + '\n-------------');
} }
return; return;
} }
@ -136,6 +136,6 @@ function cmpResults(expected, result, ttl, cname) {
ll = expected.length; ll = expected.length;
while (ll--) { while (ll--) {
assert.equal(result[ll], expected[ll]); assert.equal(result[ll], expected[ll]);
puts("Result " + result[ll] + " was equal to expected " + expected[ll]); console.log("Result " + result[ll] + " was equal to expected " + expected[ll]);
} }
} }

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

@ -3,16 +3,16 @@
require("../common"); require("../common");
puts('first stat ...'); console.log('first stat ...');
fs.stat(__filename) fs.stat(__filename)
.addCallback( function(stats) { .addCallback( function(stats) {
puts('second stat ...'); console.log('second stat ...');
fs.stat(__filename) fs.stat(__filename)
.timeout(1000) .timeout(1000)
.wait(); .wait();
puts('test passed'); console.log('test passed');
}) })
.addErrback(function() { .addErrback(function() {
throw new Exception(); throw new Exception();

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

@ -30,7 +30,7 @@ var proxy = http.createServer(function (req, res) {
c.addListener('error', function (e) { c.addListener('error', function (e) {
puts('proxy client error. sent ' + sent); console.log('proxy client error. sent ' + sent);
throw e; throw e;
}); });
@ -86,7 +86,7 @@ function call_chargen(list) {
req.end(); req.end();
} else { } else {
sys.puts("End of list. closing servers"); console.log("End of list. closing servers");
proxy.close(); proxy.close();
chargen.close(); chargen.close();
done = true; done = true;

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

@ -10,7 +10,7 @@ server = http.createServer(function (req, res) {
res.writeHeader(200 , { 'Content-Length': body.length.toString() res.writeHeader(200 , { 'Content-Length': body.length.toString()
, 'Content-Type': 'text/plain' , 'Content-Type': 'text/plain'
}); });
sys.puts('method: ' + req.method); console.log('method: ' + req.method);
if (req.method != 'HEAD') res.write(body); if (req.method != 'HEAD') res.write(body);
res.end(); res.end();
}); });
@ -22,7 +22,7 @@ server.addListener('listening', function() {
var client = http.createClient(PORT); var client = http.createClient(PORT);
var request = client.request("HEAD", "/"); var request = client.request("HEAD", "/");
request.addListener('response', function (response) { request.addListener('response', function (response) {
sys.puts('got response'); console.log('got response');
response.addListener("data", function () { response.addListener("data", function () {
process.exit(2); process.exit(2);
}); });

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

@ -27,7 +27,7 @@ server.addListener('listening', function () {
requests_ok++; requests_ok++;
} }
if (requests_complete == request_count) { if (requests_complete == request_count) {
puts("\nrequests ok: " + requests_ok); console.log("\nrequests ok: " + requests_ok);
server.close(); server.close();
} }
}); });

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

@ -27,7 +27,7 @@ var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+PORT+'/moduleB
sys.exec(cmd, function (err, stdout, stderr) { sys.exec(cmd, function (err, stdout, stderr) {
if (err) throw err; if (err) throw err;
puts('success!'); console.log('success!');
modulesLoaded++; modulesLoaded++;
server.close(); server.close();
}); });

10
test/disabled/tls_client.js

@ -15,14 +15,14 @@ var credentials = crypto.createCredentials({ca:caPem});
client.setEncoding("UTF8"); client.setEncoding("UTF8");
client.addListener("connect", function () { client.addListener("connect", function () {
sys.puts("client connected."); console.log("client connected.");
client.setSecure(credentials); client.setSecure(credentials);
}); });
client.addListener("secure", function () { client.addListener("secure", function () {
sys.puts("client secure : "+JSON.stringify(client.getCipher())); console.log("client secure : "+JSON.stringify(client.getCipher()));
sys.puts(JSON.stringify(client.getPeerCertificate())); console.log(JSON.stringify(client.getPeerCertificate()));
sys.puts("verifyPeer : "+client.verifyPeer()); console.log("verifyPeer : "+client.verifyPeer());
client.write("GET / HTTP/1.0\r\n\r\n"); client.write("GET / HTTP/1.0\r\n\r\n");
}); });
@ -31,6 +31,6 @@ client.addListener("data", function (chunk) {
}); });
client.addListener("end", function () { client.addListener("end", function () {
sys.puts("client disconnected."); console.log("client disconnected.");
}); });

4
test/disabled/tls_server.js

@ -15,11 +15,11 @@ var server = net.createServer(function (connection) {
connection.setEncoding("binary"); connection.setEncoding("binary");
connection.addListener("secure", function () { connection.addListener("secure", function () {
//sys.puts("Secure"); //console.log("Secure");
}); });
connection.addListener("data", function (chunk) { connection.addListener("data", function (chunk) {
sys.puts("recved: " + JSON.stringify(chunk)); console.log("recved: " + JSON.stringify(chunk));
connection.write("HTTP/1.0 200 OK\r\nContent-type: text/plain\r\nContent-length: 9\r\n\r\nOK : "+i+"\r\n\r\n"); connection.write("HTTP/1.0 200 OK\r\nContent-type: text/plain\r\nContent-length: 9\r\n\r\nOK : "+i+"\r\n\r\n");
i=i+1; i=i+1;
connection.end(); connection.end();

2
test/fixtures/b/c.js

@ -24,5 +24,5 @@ exports.D = function () {
process.addListener("exit", function () { process.addListener("exit", function () {
string = "C done"; string = "C done";
puts("b/c.js exit"); console.log("b/c.js exit");
}); });

2
test/fixtures/child_process_should_emit_error.js

@ -3,7 +3,7 @@ var exec = require('child_process').exec,
[0, 1].forEach(function(i) { [0, 1].forEach(function(i) {
exec('ls', function(err, stdout, stderr) { exec('ls', function(err, stdout, stderr) {
puts(i); console.log(i);
throw new Error('hello world'); throw new Error('hello world');
}); });
}); });

2
test/fixtures/print-10-lines.js

@ -1,4 +1,4 @@
puts = require('sys').puts; puts = require('sys').puts;
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
puts('count ' + i); console.log('count ' + i);
} }

2
test/message/2100bytes.js

@ -1,7 +1,7 @@
require('../common'); require('../common');
sys = require('sys'); sys = require('sys');
sys.puts([ console.log([
'_______________________________________________50', '_______________________________________________50',
'______________________________________________100', '______________________________________________100',
'______________________________________________150', '______________________________________________150',

2
test/message/hello_world.js

@ -1,3 +1,3 @@
require('../common'); require('../common');
puts('hello world'); console.log('hello world');

10
test/message/undefined_reference_in_new_context.out

@ -7,8 +7,8 @@ script.runInNewContext();
ReferenceError: foo is not defined ReferenceError: foo is not defined
at evalmachine.<anonymous>:1:1 at evalmachine.<anonymous>:1:1
at Object.<anonymous> (*test/message/undefined_reference_in_new_context.js:9:8) at Object.<anonymous> (*test/message/undefined_reference_in_new_context.js:9:8)
at Module._compile (module:384:23) at Module._compile (module:*:23)
at Module._loadScriptSync (module:393:8) at Module._loadScriptSync (module:*:8)
at Module.loadSync (module:296:10) at Module.loadSync (module:*:*)
at Object.runMain (module:447:22) at Object.runMain (module:*:*)
at node.js:208:10 at node.js:*:*

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

@ -16,7 +16,7 @@ function doSpawn (i) {
}); });
child.stderr.addListener("data", function (chunk) { child.stderr.addListener("data", function (chunk) {
puts('stderr: ' + chunk); console.log('stderr: ' + chunk);
}); });
child.addListener("exit", function () { child.addListener("exit", function () {

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

@ -15,19 +15,19 @@ server.listen(PORT);
var client = http.createClient(PORT); var client = http.createClient(PORT);
client.addListener("error", function() { client.addListener("error", function() {
sys.puts("ERROR!"); console.log("ERROR!");
errorCount++; errorCount++;
}); });
client.addListener("end", function() { client.addListener("end", function() {
sys.puts("EOF!"); console.log("EOF!");
eofCount++; eofCount++;
}); });
var request = client.request("GET", "/", {"host": "localhost"}); var request = client.request("GET", "/", {"host": "localhost"});
request.end(); request.end();
request.addListener('response', function(response) { request.addListener('response', function(response) {
sys.puts("STATUS: " + response.statusCode); console.log("STATUS: " + response.statusCode);
}); });
setTimeout(function () { setTimeout(function () {

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

@ -21,7 +21,7 @@ function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
puts("ab not installed? skipping test.\n" + stderr); console.log("ab not installed? skipping test.\n" + stderr);
process.exit(); process.exit();
return; return;
} }
@ -45,12 +45,12 @@ server.listen(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);
puts("keep-alive: " + keepAliveReqSec + " req/sec"); console.log("keep-alive: " + keepAliveReqSec + " req/sec");
runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) { runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) {
normalReqSec = reqSec; normalReqSec = reqSec;
assert.equal(0, keepAliveRequests); assert.equal(0, keepAliveRequests);
puts("normal: " + normalReqSec + " req/sec"); console.log("normal: " + normalReqSec + " req/sec");
server.close(); server.close();
}); });
}); });

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

@ -44,7 +44,7 @@ function runClient (callback) {
}); });
client.addListener("error", function (e) { client.addListener("error", function (e) {
puts("\n\nERROOOOOr"); console.log("\n\nERROOOOOr");
throw e; throw e;
}); });
@ -54,7 +54,7 @@ function runClient (callback) {
assert.equal(bytes, client.recved.length); assert.equal(bytes, client.recved.length);
if (client.fd) { if (client.fd) {
puts(client.fd); console.log(client.fd);
} }
assert.ok(!client.fd); assert.ok(!client.fd);
@ -77,5 +77,5 @@ server.listen(PORT, function () {
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(connections_per_client * concurrency, total_connections); assert.equal(connections_per_client * concurrency, total_connections);
puts("\nokay!"); console.log("\nokay!");
}); });

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

@ -30,21 +30,21 @@ client.addListener("data", function (d) {
setTimeout(function () { setTimeout(function () {
chars_recved = recv.length; chars_recved = recv.length;
puts("pause at: " + chars_recved); console.log("pause at: " + chars_recved);
assert.equal(true, chars_recved > 1); assert.equal(true, chars_recved > 1);
client.pause(); client.pause();
setTimeout(function () { setTimeout(function () {
puts("resume at: " + chars_recved); console.log("resume at: " + chars_recved);
assert.equal(chars_recved, recv.length); assert.equal(chars_recved, recv.length);
client.resume(); client.resume();
setTimeout(function () { setTimeout(function () {
chars_recved = recv.length; chars_recved = recv.length;
puts("pause at: " + chars_recved); console.log("pause at: " + chars_recved);
client.pause(); client.pause();
setTimeout(function () { setTimeout(function () {
puts("resume at: " + chars_recved); console.log("resume at: " + chars_recved);
assert.equal(chars_recved, recv.length); assert.equal(chars_recved, recv.length);
client.resume(); client.resume();

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

@ -14,7 +14,7 @@ function pingPongTest (port, host, on_complete) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("data", function (data) { socket.addListener("data", function (data) {
puts(data); console.log(data);
assert.equal("PING", data); assert.equal("PING", data);
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
assert.equal(true, count <= N); assert.equal(true, count <= N);
@ -30,13 +30,13 @@ function pingPongTest (port, host, on_complete) {
}); });
socket.addListener("end", function () { socket.addListener("end", function () {
puts("server-side socket EOF"); console.log("server-side socket EOF");
assert.equal("writeOnly", socket.readyState); assert.equal("writeOnly", socket.readyState);
socket.end(); socket.end();
}); });
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
puts("server-side socket.end"); console.log("server-side socket.end");
assert.equal(false, had_error); assert.equal(false, had_error);
assert.equal("closed", socket.readyState); assert.equal("closed", socket.readyState);
socket.server.close(); socket.server.close();
@ -54,7 +54,7 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
puts(data); console.log(data);
assert.equal("PONG", data); assert.equal("PONG", data);
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
@ -63,7 +63,7 @@ function pingPongTest (port, host, on_complete) {
if (count++ < N) { if (count++ < N) {
client.write("PING"); client.write("PING");
} else { } else {
puts("closing client"); console.log("closing client");
client.end(); client.end();
client_ended = true; client_ended = true;
} }
@ -76,7 +76,7 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("close", function () { client.addListener("close", function () {
puts("client.end"); console.log("client.end");
assert.equal(N+1, count); assert.equal(N+1, count);
assert.ok(client_ended); assert.ok(client_ended);
if (on_complete) on_complete(); if (on_complete) on_complete();

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

@ -14,7 +14,7 @@ function pingPongTest (port, host, on_complete) {
if (host === "127.0.0.1" || host === "localhost" || !host) { if (host === "127.0.0.1" || host === "localhost" || !host) {
assert.equal(socket.remoteAddress, "127.0.0.1"); assert.equal(socket.remoteAddress, "127.0.0.1");
} else { } else {
puts('host = ' + host + ', remoteAddress = ' + socket.remoteAddress); console.log('host = ' + host + ', remoteAddress = ' + socket.remoteAddress);
assert.equal(socket.remoteAddress, "::1"); assert.equal(socket.remoteAddress, "::1");
} }
@ -23,7 +23,7 @@ function pingPongTest (port, host, on_complete) {
socket.timeout = 0; socket.timeout = 0;
socket.addListener("data", function (data) { socket.addListener("data", function (data) {
puts("server got: " + JSON.stringify(data)); console.log("server got: " + JSON.stringify(data));
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
assert.equal(true, count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
@ -54,7 +54,7 @@ function pingPongTest (port, host, on_complete) {
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
puts('client got: ' + data); console.log('client got: ' + data);
assert.equal("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;

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

@ -2,13 +2,13 @@ require("../common");
net = require("net"); net = require("net");
N = 160*1024; // 30kb N = 160*1024; // 30kb
puts("build big string"); console.log("build big string");
var body = ""; var body = "";
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
body += "C"; body += "C";
} }
puts("start server on port " + PORT); console.log("start server on port " + PORT);
server = net.createServer(function (connection) { server = net.createServer(function (connection) {
connection.addListener("connect", function () { connection.addListener("connect", function () {
@ -28,17 +28,17 @@ client = net.createConnection(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;
puts("got " + chars_recved); console.log("got " + chars_recved);
if (!paused) { if (!paused) {
client.pause(); client.pause();
npauses += 1; npauses += 1;
paused = true; paused = true;
puts("pause"); console.log("pause");
x = chars_recved; x = chars_recved;
setTimeout(function () { setTimeout(function () {
assert.equal(chars_recved, x); assert.equal(chars_recved, x);
client.resume(); client.resume();
puts("resume"); console.log("resume");
paused = false; paused = false;
}, 100); }, 100);
} }

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

@ -9,7 +9,7 @@ var echo_server = net.createServer(function (socket) {
socket.setTimeout(timeout); socket.setTimeout(timeout);
socket.addListener("timeout", function () { socket.addListener("timeout", function () {
puts("server timeout"); console.log("server timeout");
timeouttime = new Date; timeouttime = new Date;
p(timeouttime); p(timeouttime);
socket.destroy(); socket.destroy();
@ -20,7 +20,7 @@ var echo_server = net.createServer(function (socket) {
}) })
socket.addListener("data", function (d) { socket.addListener("data", function (d) {
puts(d); console.log(d);
socket.write(d); socket.write(d);
}); });
@ -30,14 +30,14 @@ var echo_server = net.createServer(function (socket) {
}); });
echo_server.listen(PORT, function () { echo_server.listen(PORT, function () {
puts("server listening at " + PORT); console.log("server listening at " + PORT);
}); });
var client = net.createConnection(PORT); var client = net.createConnection(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 () {
puts("client connected."); console.log("client connected.");
client.write("hello\r\n"); client.write("hello\r\n");
}); });
@ -45,12 +45,12 @@ client.addListener("data", function (chunk) {
assert.equal("hello\r\n", chunk); assert.equal("hello\r\n", chunk);
if (exchanges++ < 5) { if (exchanges++ < 5) {
setTimeout(function () { setTimeout(function () {
puts("client write 'hello'"); console.log("client write 'hello'");
client.write("hello\r\n"); client.write("hello\r\n");
}, 500); }, 500);
if (exchanges == 5) { if (exchanges == 5) {
puts("wait for timeout - should come in " + timeout + " ms"); console.log("wait for timeout - should come in " + timeout + " ms");
starttime = new Date; starttime = new Date;
p(starttime); p(starttime);
} }
@ -62,12 +62,12 @@ client.addListener("timeout", function () {
}); });
client.addListener("end", function () { client.addListener("end", function () {
puts("client end"); console.log("client end");
client.end(); client.end();
}); });
client.addListener("close", function () { client.addListener("close", function () {
puts("client disconnect"); console.log("client disconnect");
echo_server.close(); echo_server.close();
}); });
@ -76,7 +76,7 @@ process.addListener("exit", function () {
assert.ok(timeouttime != null); assert.ok(timeouttime != null);
diff = timeouttime - starttime; diff = timeouttime - starttime;
puts("diff = " + diff); console.log("diff = " + diff);
assert.ok(timeout < diff); assert.ok(timeout < diff);

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

@ -27,7 +27,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
assert.equal(verified, 1); assert.equal(verified, 1);
assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
puts("server got: " + JSON.stringify(data)); console.log("server got: " + JSON.stringify(data));
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
assert.equal(true, count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
@ -69,7 +69,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
assert.equal("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;
puts("client got PONG"); console.log("client got PONG");
if (sent_final_ping) { if (sent_final_ping) {
assert.equal("readOnly", client.readyState); assert.equal("readOnly", client.readyState);
@ -117,6 +117,6 @@ if (have_tls) {
assert.equal(2, tests_run); assert.equal(2, tests_run);
}); });
} else { } else {
puts("Not compiled with TLS support -- skipping test"); console.log("Not compiled with TLS support -- skipping test");
process.exit(0); process.exit(0);
} }

4
test/pummel/test-timers.js

@ -12,7 +12,7 @@ setTimeout(function () {
var diff = endtime - starttime; var diff = endtime - starttime;
assert.ok(diff > 0); assert.ok(diff > 0);
puts("diff: " + diff); console.log("diff: " + diff);
assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW); assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW);
setTimeout_called = true; setTimeout_called = true;
@ -28,7 +28,7 @@ setInterval(function () {
var diff = endtime - starttime; var diff = endtime - starttime;
assert.ok(diff > 0); assert.ok(diff > 0);
puts("diff: " + diff); console.log("diff: " + diff);
var t = interval_count * 1000; var t = interval_count * 1000;

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

@ -6,12 +6,12 @@ var path = require("path");
var f = path.join(fixturesDir, "x.txt"); var f = path.join(fixturesDir, "x.txt");
var f2 = path.join(fixturesDir, "x2.txt"); var f2 = path.join(fixturesDir, "x2.txt");
puts("watching for changes of " + f); console.log("watching for changes of " + f);
var changes = 0; var changes = 0;
function watchFile () { function watchFile () {
fs.watchFile(f, function (curr, prev) { fs.watchFile(f, function (curr, prev) {
puts(f + " change"); console.log(f + " change");
changes++; changes++;
assert.ok(curr.mtime != prev.mtime); assert.ok(curr.mtime != prev.mtime);
fs.unwatchFile(f); fs.unwatchFile(f);

4
test/simple/test-buffer.js

@ -5,7 +5,7 @@ var Buffer = require('buffer').Buffer;
var b = new Buffer(1024); var b = new Buffer(1024);
puts("b.length == " + b.length); console.log("b.length == " + b.length);
assert.equal(1024, b.length); assert.equal(1024, b.length);
for (var i = 0; i < 1024; i++) { for (var i = 0; i < 1024; i++) {
@ -90,7 +90,7 @@ assert.deepEqual([0xDEADBEEF], b.unpack('N', 4));
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語 var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
var buffer = new Buffer(32); var buffer = new Buffer(32);
var size = buffer.utf8Write(testValue, 0); var size = buffer.utf8Write(testValue, 0);
puts('bytes written to buffer: ' + size); console.log('bytes written to buffer: ' + size);
var slice = buffer.toString('utf8', 0, size); var slice = buffer.toString('utf8', 0, size);
assert.equal(slice, testValue); assert.equal(slice, testValue);

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

@ -10,12 +10,12 @@ function pwd (callback) {
child.stdout.setEncoding('utf8'); child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (s) { child.stdout.addListener("data", function (s) {
puts("stdout: " + JSON.stringify(s)); console.log("stdout: " + JSON.stringify(s));
output += s; output += s;
}); });
child.addListener("exit", function (c) { child.addListener("exit", function (c) {
puts("exit: " + c); console.log("exit: " + c);
assert.equal(0, c); assert.equal(0, c);
callback(output); callback(output);
pwd_called = true; pwd_called = true;

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

@ -17,7 +17,7 @@ var expected = "hello world";
var helloPath = fixtPath("hello.txt"); var helloPath = fixtPath("hello.txt");
function test1(next) { function test1(next) {
puts("Test 1..."); console.log("Test 1...");
fs.open(helloPath, 'w', 400, function (err, fd) { fs.open(helloPath, 'w', 400, function (err, fd) {
if (err) throw err; if (err) throw err;
var child = spawn('/bin/echo', [expected], undefined, [-1, fd] ); var child = spawn('/bin/echo', [expected], undefined, [-1, fd] );
@ -34,7 +34,7 @@ function test1(next) {
fs.readFile(helloPath, function (err, data) { fs.readFile(helloPath, function (err, data) {
if (err) throw err; if (err) throw err;
assert.equal(data.toString(), expected + "\n"); assert.equal(data.toString(), expected + "\n");
puts(' File was written.'); console.log(' File was written.');
next(test3); next(test3);
}); });
}); });
@ -45,7 +45,7 @@ function test1(next) {
// Test the equivalent of: // Test the equivalent of:
// $ node ../fixture/stdio-filter.js < hello.txt // $ node ../fixture/stdio-filter.js < hello.txt
function test2(next) { function test2(next) {
puts("Test 2..."); console.log("Test 2...");
fs.open(helloPath, 'r', undefined, function (err, fd) { fs.open(helloPath, 'r', undefined, function (err, fd) {
var child = spawn(process.argv[0] var child = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a'] , [fixtPath('stdio-filter.js'), 'o', 'a']
@ -59,7 +59,7 @@ function test2(next) {
child.addListener('exit', function (code) { child.addListener('exit', function (code) {
if (err) throw err; if (err) throw err;
assert.equal(actualData, "hella warld\n"); assert.equal(actualData, "hella warld\n");
puts(" File was filtered successfully"); console.log(" File was filtered successfully");
fs.close(fd, function () { fs.close(fd, function () {
next(test3); next(test3);
}); });
@ -70,19 +70,19 @@ function test2(next) {
// Test the equivalent of: // Test the equivalent of:
// $ /bin/echo "hello world" | ../stdio-filter.js a o // $ /bin/echo "hello world" | ../stdio-filter.js a o
function test3(next) { function test3(next) {
puts("Test 3..."); console.log("Test 3...");
var filter = spawn(process.argv[0] var filter = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a']); , [fixtPath('stdio-filter.js'), 'o', 'a']);
var echo = spawn('/bin/echo', [expected], undefined, [-1, filter.fds[0]]); var echo = spawn('/bin/echo', [expected], undefined, [-1, filter.fds[0]]);
var actualData = ''; var actualData = '';
filter.stdout.addListener('data', function(data) { filter.stdout.addListener('data', function(data) {
puts(" Got data --> " + data); console.log(" Got data --> " + data);
actualData += data; actualData += data;
}); });
filter.addListener('exit', function(code) { filter.addListener('exit', function(code) {
if (code) throw "Return code was " + code; if (code) throw "Return code was " + code;
assert.equal(actualData, "hella warld\n"); assert.equal(actualData, "hella warld\n");
puts(" Talked to another process successfully"); console.log(" Talked to another process successfully");
}); });
echo.addListener('exit', function(code) { echo.addListener('exit', function(code) {
if (code) throw "Return code was " + code; if (code) throw "Return code was " + code;

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

@ -8,7 +8,7 @@ response = "";
child.stdout.setEncoding('utf8'); child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (chunk) { child.stdout.addListener("data", function (chunk) {
puts("stdout: " + chunk); console.log("stdout: " + chunk);
response += chunk; response += chunk;
}); });

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

@ -12,13 +12,13 @@ var gotEcho = false;
var child = spawn(process.argv[0], [sub]); var child = spawn(process.argv[0], [sub]);
child.stderr.addListener("data", function (data){ child.stderr.addListener("data", function (data){
puts("parent stderr: " + data); console.log("parent stderr: " + data);
}); });
child.stdout.setEncoding('utf8'); child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (data){ child.stdout.addListener("data", function (data){
puts('child said: ' + JSON.stringify(data)); console.log('child said: ' + JSON.stringify(data));
if (!gotHelloWorld) { if (!gotHelloWorld) {
assert.equal("hello world\r\n", data); assert.equal("hello world\r\n", data);
gotHelloWorld = true; gotHelloWorld = true;
@ -31,7 +31,7 @@ child.stdout.addListener("data", function (data){
}); });
child.stdout.addListener("end", function (data){ child.stdout.addListener("end", function (data){
puts('child end'); console.log('child end');
}); });

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

@ -15,7 +15,7 @@ var gotStdoutEOF = false;
cat.stdout.setEncoding('utf8'); cat.stdout.setEncoding('utf8');
cat.stdout.addListener("data", function (chunk) { cat.stdout.addListener("data", function (chunk) {
puts("stdout: " + chunk); console.log("stdout: " + chunk);
response += chunk; response += chunk;
}); });
@ -37,7 +37,7 @@ cat.stderr.addListener("end", function (chunk) {
cat.addListener("exit", function (status) { cat.addListener("exit", function (status) {
puts("exit event"); console.log("exit event");
exitStatus = status; exitStatus = status;
assert.equal("hello world", response); assert.equal("hello world", response);
}); });

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

@ -11,17 +11,17 @@ var count = 0;
child.stderr.setEncoding('utf8'); child.stderr.setEncoding('utf8');
child.stderr.addListener("data", function (data) { child.stderr.addListener("data", function (data) {
puts("parent stderr: " + data); console.log("parent stderr: " + data);
assert.ok(false); assert.ok(false);
}); });
child.stderr.setEncoding('utf8'); child.stderr.setEncoding('utf8');
child.stdout.addListener("data", function (data) { child.stdout.addListener("data", function (data) {
count += data.length; count += data.length;
puts(count); console.log(count);
}); });
child.addListener("exit", function (data) { child.addListener("exit", function (data) {
assert.equal(n, count); assert.equal(n, count);
puts("okay"); console.log("okay");
}); });

2
test/simple/test-crypto.js

@ -3,7 +3,7 @@ require("../common");
try { try {
var crypto = require('crypto'); var crypto = require('crypto');
} catch (e) { } catch (e) {
puts("Not compiled with OPENSSL support."); console.log("Not compiled with OPENSSL support.");
process.exit(); process.exit();
} }

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

@ -12,9 +12,9 @@ function pingPongTest (port, host) {
var sent_final_ping = false; var sent_final_ping = false;
var server = dgram.createSocket(function (msg, rinfo) { var server = dgram.createSocket(function (msg, rinfo) {
puts("connection: " + rinfo.address + ":"+ rinfo.port); console.log("connection: " + rinfo.address + ":"+ rinfo.port);
puts("server got: " + msg); console.log("server got: " + msg);
if (/PING/.exec(msg)) { if (/PING/.exec(msg)) {
var buf = new Buffer(4); var buf = new Buffer(4);
@ -33,7 +33,7 @@ function pingPongTest (port, host) {
server.bind(port, host); server.bind(port, host);
server.addListener("listening", function () { server.addListener("listening", function () {
puts("server listening on " + port + " " + host); console.log("server listening on " + port + " " + host);
var buf = new Buffer(4); var buf = new Buffer(4);
buf.write('PING'); buf.write('PING');
@ -41,7 +41,7 @@ function pingPongTest (port, host) {
var client = dgram.createSocket(); var client = dgram.createSocket();
client.addListener("message", function (msg, rinfo) { client.addListener("message", function (msg, rinfo) {
puts("client got: " + msg); console.log("client got: " + msg);
assert.equal("PONG", msg.toString('ascii')); assert.equal("PONG", msg.toString('ascii'));
count += 1; count += 1;
@ -58,7 +58,7 @@ function pingPongTest (port, host) {
}); });
client.addListener("close", function () { client.addListener("close", function () {
puts('client.close'); console.log('client.close');
assert.equal(N, count); assert.equal(N, count);
tests_run += 1; tests_run += 1;
server.close(); server.close();
@ -84,5 +84,5 @@ pingPongTest(20997, "::1");
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(4, tests_run); assert.equal(4, tests_run);
puts('done'); console.log('done');
}); });

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

@ -4,19 +4,19 @@ var count = 100;
var fs = require('fs'); var fs = require('fs');
function tryToKillEventLoop() { function tryToKillEventLoop() {
puts('trying to kill event loop ...'); console.log('trying to kill event loop ...');
fs.stat(__filename, function (err) { fs.stat(__filename, function (err) {
if (err) { if (err) {
throw new Exception('first fs.stat failed') throw new Exception('first fs.stat failed')
} else { } else {
puts('first fs.stat succeeded ...'); console.log('first fs.stat succeeded ...');
fs.stat(__filename, function (err) { fs.stat(__filename, function (err) {
if (err) { if (err) {
throw new Exception('second fs.stat failed') throw new Exception('second fs.stat failed')
} else { } else {
puts('second fs.stat succeeded ...'); console.log('second fs.stat succeeded ...');
puts('could not kill event loop, retrying...'); console.log('could not kill event loop, retrying...');
setTimeout(function () { setTimeout(function () {
if (--count) { if (--count) {
@ -41,7 +41,7 @@ fs.open('/dev/zero', "r", 0666, function (err, fd) {
if (err) throw err; if (err) throw err;
if (chunk) { if (chunk) {
pos += bytesRead; pos += bytesRead;
//puts(pos); //console.log(pos);
readChunk(); readChunk();
} else { } else {
fs.closeSync(fd); fs.closeSync(fd);

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

@ -8,13 +8,13 @@ setTimeout(function () {
// require() calls.. // require() calls..
N = 30; N = 30;
for (var i=0; i < N; i++) { for (var i=0; i < N; i++) {
puts("start " + i); console.log("start " + i);
fs.readFile(testTxt, function(err, data) { fs.readFile(testTxt, function(err, data) {
if (err) { if (err) {
puts("error! " + e); console.log("error! " + e);
process.exit(1); process.exit(1);
} else { } else {
puts("finish"); console.log("finish");
} }
}); });
} }

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

@ -8,7 +8,7 @@ for (var i = 0; i < N; i++) {
fs.stat("does-not-exist-" + i, function (err) { fs.stat("does-not-exist-" + i, function (err) {
if (err) { if (err) {
j++; // only makes it to about 17 j++; // only makes it to about 17
puts("finish " + j); console.log("finish " + j);
} else { } else {
throw new Error("this shouldn't be called"); throw new Error("this shouldn't be called");
} }

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

@ -22,7 +22,7 @@ function errExec (script, callback) {
// Count the tests // Count the tests
exits++; exits++;
puts('.'); console.log('.');
}); });
} }

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

@ -7,18 +7,18 @@ var events_new_listener_emited = [];
var times_hello_emited = 0; var times_hello_emited = 0;
e.addListener("newListener", function (event, listener) { e.addListener("newListener", function (event, listener) {
puts("newListener: " + event); console.log("newListener: " + event);
events_new_listener_emited.push(event); events_new_listener_emited.push(event);
}); });
e.addListener("hello", function (a, b) { e.addListener("hello", function (a, b) {
puts("hello"); console.log("hello");
times_hello_emited += 1 times_hello_emited += 1
assert.equal("a", a); assert.equal("a", a);
assert.equal("b", b); assert.equal("b", b);
}); });
puts("start"); console.log("start");
e.emit("hello", "a", "b"); e.emit("hello", "a", "b");

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

@ -5,17 +5,17 @@ var events = require('events');
count = 0; count = 0;
function listener1 () { function listener1 () {
puts('listener1'); console.log('listener1');
count++; count++;
} }
function listener2 () { function listener2 () {
puts('listener2'); console.log('listener2');
count++; count++;
} }
function listener3 () { function listener3 () {
puts('listener3'); console.log('listener3');
count++; count++;
} }

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

@ -4,13 +4,13 @@ var MESSAGE = 'catch me if you can';
var caughtException = false; var caughtException = false;
process.addListener('uncaughtException', function (e) { process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 1"); console.log("uncaught exception! 1");
assert.equal(MESSAGE, e.message); assert.equal(MESSAGE, e.message);
caughtException = true; caughtException = true;
}); });
process.addListener('uncaughtException', function (e) { process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 2"); console.log("uncaught exception! 2");
assert.equal(MESSAGE, e.message); assert.equal(MESSAGE, e.message);
caughtException = true; caughtException = true;
}); });
@ -20,6 +20,6 @@ setTimeout(function() {
}, 10); }, 10);
process.addListener("exit", function () { process.addListener("exit", function () {
puts("exit"); console.log("exit");
assert.equal(true, caughtException); assert.equal(true, caughtException);
}); });

12
test/simple/test-exec.js

@ -6,9 +6,9 @@ error_count = 0;
exec("ls /", function (err, stdout, stderr) { exec("ls /", function (err, stdout, stderr) {
if (err) { if (err) {
error_count++; error_count++;
puts("error!: " + err.code); console.log("error!: " + err.code);
puts("stdout: " + JSON.stringify(stdout)); console.log("stdout: " + JSON.stringify(stdout));
puts("stderr: " + JSON.stringify(stderr)); console.log("stderr: " + JSON.stringify(stderr));
assert.equal(false, err.killed); assert.equal(false, err.killed);
} else { } else {
success_count++; success_count++;
@ -24,9 +24,9 @@ exec("ls /DOES_NOT_EXIST", function (err, stdout, stderr) {
assert.equal(true, err.code != 0); assert.equal(true, err.code != 0);
assert.equal(false, err.killed); assert.equal(false, err.killed);
assert.strictEqual(null, err.signal); assert.strictEqual(null, err.signal);
puts("error code: " + err.code); console.log("error code: " + err.code);
puts("stdout: " + JSON.stringify(stdout)); console.log("stdout: " + JSON.stringify(stdout));
puts("stderr: " + JSON.stringify(stderr)); console.log("stderr: " + JSON.stringify(stderr));
} else { } else {
success_count++; success_count++;
p(stdout); p(stdout);

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

@ -12,8 +12,8 @@ nodePath = path.join(__dirname,
isDebug ? 'node_g' : 'node'); isDebug ? 'node_g' : 'node');
nodePath = path.normalize(nodePath); nodePath = path.normalize(nodePath);
puts('nodePath: ' + nodePath); console.log('nodePath: ' + nodePath);
puts('process.execPath: ' + process.execPath); console.log('process.execPath: ' + process.execPath);
assert.equal(nodePath, process.execPath); assert.equal(nodePath, process.execPath);

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

@ -15,6 +15,6 @@ fs.readFile(filename, "raw", function (err, content) {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
puts("done"); console.log("done");
assert.equal(true, got_error); assert.equal(true, got_error);
}); });

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

@ -10,7 +10,7 @@ fs.chmod(file, 0777, function (err) {
if (err) { if (err) {
got_error = true; got_error = true;
} else { } else {
puts(fs.statSync(file).mode); console.log(fs.statSync(file).mode);
assert.equal(0777, fs.statSync(file).mode & 0777); assert.equal(0777, fs.statSync(file).mode & 0777);
fs.chmodSync(file, 0644); fs.chmodSync(file, 0644);

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

@ -241,7 +241,7 @@ var numtests = tests.length;
function runNextTest(err) { function runNextTest(err) {
if (err) throw err; if (err) throw err;
var test = tests.shift() var test = tests.shift()
if (!test) puts(numtests+' subtests completed OK for fs.realpath'); if (!test) console.log(numtests+' subtests completed OK for fs.realpath');
else test(runNextTest); else test(runNextTest);
} }
runNextTest(); runNextTest();

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

@ -56,7 +56,7 @@ fs.open(".", "r", undefined, function(err, fd) {
fs.close(fd); fs.close(fd);
}); });
puts("stating: " + __filename); console.log("stating: " + __filename);
fs.stat(__filename, function (err, s) { fs.stat(__filename, function (err, s) {
if (err) { if (err) {
got_error = true; got_error = true;
@ -64,25 +64,25 @@ fs.stat(__filename, function (err, s) {
p(s); p(s);
success_count++; success_count++;
puts("isDirectory: " + JSON.stringify( s.isDirectory() ) ); console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) );
assert.equal(false, s.isDirectory()); assert.equal(false, s.isDirectory());
puts("isFile: " + JSON.stringify( s.isFile() ) ); console.log("isFile: " + JSON.stringify( s.isFile() ) );
assert.equal(true, s.isFile()); assert.equal(true, s.isFile());
puts("isSocket: " + JSON.stringify( s.isSocket() ) ); console.log("isSocket: " + JSON.stringify( s.isSocket() ) );
assert.equal(false, s.isSocket()); assert.equal(false, s.isSocket());
puts("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) ); console.log("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) );
assert.equal(false, s.isBlockDevice()); assert.equal(false, s.isBlockDevice());
puts("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) ); console.log("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) );
assert.equal(false, s.isCharacterDevice()); assert.equal(false, s.isCharacterDevice());
puts("isFIFO: " + JSON.stringify( s.isFIFO() ) ); console.log("isFIFO: " + JSON.stringify( s.isFIFO() ) );
assert.equal(false, s.isFIFO()); assert.equal(false, s.isFIFO());
puts("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) ); console.log("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) );
assert.equal(false, s.isSymbolicLink()); assert.equal(false, s.isSymbolicLink());
assert.ok(s.mtime instanceof Date); assert.ok(s.mtime instanceof Date);

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

@ -9,7 +9,7 @@ var linkPath = path.join(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;
puts('symlink done'); console.log('symlink done');
// todo: fs.lstat? // todo: fs.lstat?
fs.readlink(linkPath, function(err, destination) { fs.readlink(linkPath, function(err, destination) {
if (err) throw err; if (err) throw err;
@ -24,7 +24,7 @@ var dstPath = path.join(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;
puts('hard link done'); console.log('hard link done');
var srcContent = fs.readFileSync(srcPath, 'utf8'); var srcContent = fs.readFileSync(srcPath, 'utf8');
var dstContent = fs.readFileSync(dstPath, 'utf8'); var dstContent = fs.readFileSync(dstPath, 'utf8');
assert.equal(srcContent, dstContent); assert.equal(srcContent, dstContent);

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

@ -8,15 +8,15 @@ var found;
fs.open(fn, 'w', 0644, function (err, fd) { fs.open(fn, 'w', 0644, function (err, fd) {
if (err) throw err; if (err) throw err;
puts('open done'); console.log('open done');
fs.write(fd, expected, 0, "utf8", function (err, written) { fs.write(fd, expected, 0, "utf8", function (err, written) {
puts('write done'); console.log('write done');
if (err) throw err; if (err) throw err;
assert.equal(Buffer.byteLength(expected), written); assert.equal(Buffer.byteLength(expected), written);
fs.closeSync(fd); fs.closeSync(fd);
found = fs.readFileSync(fn, 'utf8'); found = fs.readFileSync(fn, 'utf8');
puts('expected: ' + expected.toJSON()); console.log('expected: ' + expected.toJSON());
puts('found: ' + found.toJSON()); console.log('found: ' + found.toJSON());
fs.unlinkSync(fn); fs.unlinkSync(fn);
}); });
}); });

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

@ -24,7 +24,7 @@ c.addListener("connect", function () {
}); });
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
puts(chunk); console.log(chunk);
server_response += chunk; server_response += chunk;
}); });

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

@ -18,4 +18,4 @@ s.listen(PORT, function () {
}); });
}); });
sys.puts('Server running at http://127.0.0.1:'+PORT+'/') console.log('Server running at http://127.0.0.1:'+PORT+'/')

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

@ -3,7 +3,7 @@ http = require("http");
var body = "exports.A = function() { return 'A';}"; var body = "exports.A = function() { return 'A';}";
var server = http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
puts("got request"); console.log("got request");
res.writeHead(200, [ res.writeHead(200, [
["Content-Length", body.length], ["Content-Length", body.length],
["Content-Type", "text/plain"] ["Content-Type", "text/plain"]
@ -19,7 +19,7 @@ server.listen(PORT, function () {
if (err) { if (err) {
throw err; throw err;
} else { } else {
puts("got response"); console.log("got response");
got_good_server_content = true; got_good_server_content = true;
assert.equal(body, content); assert.equal(body, content);
server.close(); server.close();
@ -28,14 +28,14 @@ server.listen(PORT, function () {
http.cat("http://localhost:12312/", "utf8", function (err, content) { http.cat("http://localhost:12312/", "utf8", function (err, content) {
if (err) { if (err) {
puts("got error (this should happen)"); console.log("got error (this should happen)");
bad_server_got_error = true; bad_server_got_error = true;
} }
}); });
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
puts("exit"); console.log("exit");
assert.equal(true, got_good_server_content); assert.equal(true, got_good_server_content);
assert.equal(true, bad_server_got_error); assert.equal(true, bad_server_got_error);
}); });

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

@ -12,8 +12,8 @@ server.listen(PORT);
http.cat("http://127.0.0.1:"+PORT+"/", "utf8", function (err, data) { http.cat("http://127.0.0.1:"+PORT+"/", "utf8", function (err, data) {
if (err) throw err; if (err) throw err;
assert.equal('string', typeof data); assert.equal('string', typeof data);
puts('here is the response:'); console.log('here is the response:');
assert.equal(UTF8_STRING, data); assert.equal(UTF8_STRING, data);
puts(data); console.log(data);
server.close(); server.close();
}) })

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

@ -10,13 +10,13 @@ var server = http.createServer(function(req, res) {
req.setBodyEncoding("utf8"); req.setBodyEncoding("utf8");
req.addListener('data', function (chunk) { req.addListener('data', function (chunk) {
puts("server got: " + JSON.stringify(chunk)); console.log("server got: " + JSON.stringify(chunk));
sent_body += chunk; sent_body += chunk;
}); });
req.addListener('end', function () { req.addListener('end', function () {
server_req_complete = true; server_req_complete = true;
puts("request complete from server"); console.log("request complete from server");
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello\n'); res.write('hello\n');
res.end(); res.end();
@ -36,7 +36,7 @@ error("client finished sending request");
req.addListener('response', function(res) { req.addListener('response', function(res) {
res.setEncoding("utf8"); res.setEncoding("utf8");
res.addListener('data', function(chunk) { res.addListener('data', function(chunk) {
puts(chunk); console.log(chunk);
}); });
res.addListener('end', function() { res.addListener('end', function() {
client_res_complete = true; client_res_complete = true;

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

@ -21,7 +21,7 @@ function check_reqs() {
} }
}); });
if (done_reqs === 4) { if (done_reqs === 4) {
sys.puts("Got all requests, which is bad."); console.log("Got all requests, which is bad.");
clearTimeout(timer); clearTimeout(timer);
} }
} }
@ -60,7 +60,7 @@ server.listen(PORT, function () {
}); });
function exception_handler(err) { function exception_handler(err) {
sys.puts("Caught an exception: " + err); console.log("Caught an exception: " + err);
if (err.name === "AssertionError") { if (err.name === "AssertionError") {
throw(err); throw(err);
} }

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

@ -22,7 +22,7 @@ function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
puts("ab not installed? skipping test.\n" + stderr); console.log("ab not installed? skipping test.\n" + stderr);
process.exit(); process.exit();
return; return;
} }
@ -47,13 +47,13 @@ function runAb(opts, callback) {
server.listen(PORT, function () { server.listen(PORT, function () {
runAb("-c 1 -n 10", function () { runAb("-c 1 -n 10", function () {
puts("-c 1 -n 10 okay"); console.log("-c 1 -n 10 okay");
runAb("-c 1 -n 100", function () { runAb("-c 1 -n 100", function () {
puts("-c 1 -n 100 okay"); console.log("-c 1 -n 100 okay");
runAb("-c 1 -n 1000", function () { runAb("-c 1 -n 1000", function () {
puts("-c 1 -n 1000 okay"); console.log("-c 1 -n 1000 okay");
server.close(); server.close();
}); });
}); });

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

@ -10,7 +10,7 @@ nrequests_completed = 0;
nrequests_expected = 1; nrequests_expected = 1;
var s = http.createServer(function (req, res) { var s = http.createServer(function (req, res) {
puts("req: " + JSON.stringify(url.parse(req.url))); console.log("req: " + JSON.stringify(url.parse(req.url)));
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Hello World"); res.write("Hello World");

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

@ -19,12 +19,12 @@ buffer.asciiWrite(request, 0, request.length);
var callbacks = 0; var callbacks = 0;
parser.onMessageBegin = function () { parser.onMessageBegin = function () {
puts("message begin"); console.log("message begin");
callbacks++; callbacks++;
}; };
parser.onHeadersComplete = function (info) { parser.onHeadersComplete = function (info) {
puts("headers complete: " + JSON.stringify(info)); console.log("headers complete: " + JSON.stringify(info));
assert.equal('GET', info.method); assert.equal('GET', info.method);
assert.equal(1, info.versionMajor); assert.equal(1, info.versionMajor);
assert.equal(1, info.versionMinor); assert.equal(1, info.versionMinor);
@ -37,9 +37,9 @@ parser.onURL = function (b, off, len) {
}; };
parser.onPath = function (b, off, length) { parser.onPath = function (b, off, length) {
puts("path [" + off + ", " + length + "]"); console.log("path [" + off + ", " + length + "]");
var path = b.asciiSlice(off, off+length); var path = b.asciiSlice(off, off+length);
puts("path = '" + path + "'"); console.log("path = '" + path + "'");
assert.equal('/hello', path); assert.equal('/hello', path);
callbacks++; callbacks++;
}; };

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

@ -3,7 +3,7 @@ var sys = require('sys'),
http = require('http'); http = require('http');
server = http.createServer(function (req, res) { server = http.createServer(function (req, res) {
sys.puts('got request. setting 1 second timeout'); console.log('got request. setting 1 second timeout');
req.connection.setTimeout(500); req.connection.setTimeout(500);
req.connection.addListener('timeout', function(){ req.connection.addListener('timeout', function(){
@ -13,7 +13,7 @@ server = http.createServer(function (req, res) {
}); });
server.listen(PORT, function () { server.listen(PORT, function () {
sys.puts('Server running at http://127.0.0.1:'+PORT+'/'); console.log('Server running at http://127.0.0.1:'+PORT+'/');
errorTimer =setTimeout(function () { errorTimer =setTimeout(function () {
throw new Error('Timeout was not sucessful'); throw new Error('Timeout was not sucessful');
@ -21,6 +21,6 @@ server.listen(PORT, function () {
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) { http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) {
clearTimeout(errorTimer); clearTimeout(errorTimer);
sys.puts('HTTP REQUEST COMPLETE (this is good)'); console.log('HTTP REQUEST COMPLETE (this is good)');
}); });
}); });

4
test/simple/test-http-tls.js

@ -14,7 +14,7 @@ try {
have_openssl=true; have_openssl=true;
} catch (e) { } catch (e) {
have_openssl=false; have_openssl=false;
puts("Not compiled with OPENSSL support."); console.log("Not compiled with OPENSSL support.");
process.exit(); process.exit();
} }
@ -61,7 +61,7 @@ var https_server = http.createServer(function (req, res) {
if (req.id == 3) { if (req.id == 3) {
assert.equal("bar", req.headers['x-x']); assert.equal("bar", req.headers['x-x']);
this.close(); this.close();
//puts("server closed"); //console.log("server closed");
} }
setTimeout(function () { setTimeout(function () {
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});

6
test/simple/test-http-wget.js

@ -39,19 +39,19 @@ c.addListener("connect", function () {
}); });
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
puts(chunk); console.log(chunk);
server_response += chunk; server_response += chunk;
}); });
c.addListener("end", function () { c.addListener("end", function () {
client_got_eof = true; client_got_eof = true;
puts('got end'); console.log('got end');
c.end(); c.end();
}); });
c.addListener("close", function () { c.addListener("close", function () {
connection_was_closed = true; connection_was_closed = true;
puts('got close'); console.log('got close');
server.close(); server.close();
}); });

2
test/simple/test-http-write-empty-string.js

@ -5,7 +5,7 @@ http = require('http');
assert = require('assert'); assert = require('assert');
server = http.createServer(function (request, response) { server = http.createServer(function (request, response) {
sys.puts('responding to ' + request.url); console.log('responding to ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'}); response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('1\n'); response.write('1\n');

2
test/simple/test-memory-usage.js

@ -1,6 +1,6 @@
require("../common"); require("../common");
var r = process.memoryUsage(); var r = process.memoryUsage();
puts(inspect(r)); console.log(inspect(r));
assert.equal(true, r["rss"] > 0); assert.equal(true, r["rss"] > 0);
assert.equal(true, r["vsize"] > 0); assert.equal(true, r["vsize"] > 0);

10
test/simple/test-mkdir-rmdir.js

@ -11,16 +11,16 @@ var rmdir_error = false;
fs.mkdir(d, 0666, function (err) { fs.mkdir(d, 0666, function (err) {
if (err) { if (err) {
puts("mkdir error: " + err.message); console.log("mkdir error: " + err.message);
mkdir_error = true; mkdir_error = true;
} else { } else {
puts("mkdir okay!"); console.log("mkdir okay!");
fs.rmdir(d, function (err) { fs.rmdir(d, function (err) {
if (err) { if (err) {
puts("rmdir error: " + err.message); console.log("rmdir error: " + err.message);
rmdir_error = true; rmdir_error = true;
} else { } else {
puts("rmdir okay!"); console.log("rmdir okay!");
} }
}); });
} }
@ -29,5 +29,5 @@ fs.mkdir(d, 0666, function (err) {
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(false, mkdir_error); assert.equal(false, mkdir_error);
assert.equal(false, rmdir_error); assert.equal(false, rmdir_error);
puts("exit"); console.log("exit");
}); });

2
test/simple/test-module-loading.js

@ -113,5 +113,5 @@ process.addListener("exit", function () {
assert.equal(true, errorThrownAsync); assert.equal(true, errorThrownAsync);
puts("exit"); console.log("exit");
}); });

6
test/simple/test-net-binary.js

@ -57,17 +57,17 @@ c.addListener("close", function () {
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
puts("recv: " + JSON.stringify(recv)); console.log("recv: " + JSON.stringify(recv));
assert.equal(2*256, recv.length); assert.equal(2*256, recv.length);
var a = recv.split(""); var a = recv.split("");
var first = a.slice(0,256).reverse().join(""); var first = a.slice(0,256).reverse().join("");
puts("first: " + JSON.stringify(first)); console.log("first: " + JSON.stringify(first));
var second = a.slice(256,2*256).join(""); var second = a.slice(256,2*256).join("");
puts("second: " + JSON.stringify(second)); console.log("second: " + JSON.stringify(second));
assert.equal(first, second); assert.equal(first, second);
}); });

14
test/simple/test-net-pingpong.js

@ -10,7 +10,7 @@ function pingPongTest (port, host) {
var sent_final_ping = false; var sent_final_ping = false;
var server = net.createServer(function (socket) { var server = net.createServer(function (socket) {
puts("connection: " + socket.remoteAddress); console.log("connection: " + socket.remoteAddress);
assert.equal(server, socket.server); assert.equal(server, socket.server);
socket.setNoDelay(); socket.setNoDelay();
@ -18,7 +18,7 @@ function pingPongTest (port, host) {
socket.setEncoding('utf8'); socket.setEncoding('utf8');
socket.addListener("data", function (data) { socket.addListener("data", function (data) {
puts("server got: " + data); console.log("server got: " + data);
assert.equal(true, socket.writable); assert.equal(true, socket.writable);
assert.equal(true, socket.readable); assert.equal(true, socket.readable);
assert.equal(true, count <= N); assert.equal(true, count <= N);
@ -38,7 +38,7 @@ function pingPongTest (port, host) {
}); });
socket.addListener("close", function () { socket.addListener("close", function () {
puts('server socket.endd'); console.log('server socket.endd');
assert.equal(false, socket.writable); assert.equal(false, socket.writable);
assert.equal(false, socket.readable); assert.equal(false, socket.readable);
socket.server.close(); socket.server.close();
@ -47,7 +47,7 @@ function pingPongTest (port, host) {
server.listen(port, host, function () { server.listen(port, host, function () {
puts("server listening on " + port + " " + host); console.log("server listening on " + port + " " + host);
var client = net.createConnection(port, host); var client = net.createConnection(port, host);
@ -59,7 +59,7 @@ function pingPongTest (port, host) {
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
puts("client got: " + data); console.log("client got: " + data);
assert.equal("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;
@ -83,7 +83,7 @@ function pingPongTest (port, host) {
}); });
client.addListener("close", function () { client.addListener("close", function () {
puts('client.endd'); console.log('client.endd');
assert.equal(N+1, count); assert.equal(N+1, count);
assert.equal(true, sent_final_ping); assert.equal(true, sent_final_ping);
tests_run += 1; tests_run += 1;
@ -103,5 +103,5 @@ pingPongTest("/tmp/pingpong.sock");
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(4, tests_run); assert.equal(4, tests_run);
puts('done'); console.log('done');
}); });

10
test/simple/test-net-reconnect.js

@ -16,30 +16,30 @@ var server = net.createServer(function (socket) {
}); });
socket.addListener("close", function (had_error) { socket.addListener("close", function (had_error) {
//puts("server had_error: " + JSON.stringify(had_error)); //console.log("server had_error: " + JSON.stringify(had_error));
assert.equal(false, had_error); assert.equal(false, had_error);
}); });
}); });
server.listen(PORT, function () { server.listen(PORT, function () {
puts('listening'); console.log('listening');
var client = net.createConnection(PORT); var client = net.createConnection(PORT);
client.setEncoding("UTF8"); client.setEncoding("UTF8");
client.addListener("connect", function () { client.addListener("connect", function () {
puts("client connected."); console.log("client connected.");
}); });
client.addListener("data", function (chunk) { client.addListener("data", function (chunk) {
client_recv_count += 1; client_recv_count += 1;
puts("client_recv_count " + client_recv_count); console.log("client_recv_count " + client_recv_count);
assert.equal("hello\r\n", chunk); assert.equal("hello\r\n", chunk);
client.end(); client.end();
}); });
client.addListener("close", function (had_error) { client.addListener("close", function (had_error) {
puts("disconnect"); console.log("disconnect");
assert.equal(false, had_error); assert.equal(false, had_error);
if (disconnect_count++ < N) if (disconnect_count++ < N)
client.connect(PORT); // reconnect client.connect(PORT); // reconnect

2
test/simple/test-net-tls.js

@ -9,7 +9,7 @@ try {
have_openssl=true; have_openssl=true;
} catch (e) { } catch (e) {
have_openssl=false; have_openssl=false;
puts("Not compiled with OPENSSL support."); console.log("Not compiled with OPENSSL support.");
process.exit(); process.exit();
} }

6
test/simple/test-next-tick-ordering.js

@ -6,13 +6,13 @@ var done = [];
function get_printer(timeout) { function get_printer(timeout) {
return function () { return function () {
sys.puts("Running from setTimeout " + timeout); console.log("Running from setTimeout " + timeout);
done.push(timeout); done.push(timeout);
}; };
} }
process.nextTick(function () { process.nextTick(function () {
sys.puts("Running from nextTick"); console.log("Running from nextTick");
done.push('nextTick'); done.push('nextTick');
}) })
@ -20,7 +20,7 @@ for (i = 0; i < N; i += 1) {
setTimeout(get_printer(i), i); setTimeout(get_printer(i), i);
} }
sys.puts("Running from main."); console.log("Running from main.");
process.addListener('exit', function () { process.addListener('exit', function () {

8
test/simple/test-readdir.js

@ -16,16 +16,16 @@ var files = ['are'
]; ];
puts('readdirSync ' + readdirDir); console.log('readdirSync ' + readdirDir);
var f = fs.readdirSync(readdirDir); var f = fs.readdirSync(readdirDir);
p(f); p(f);
assert.deepEqual(files, f.sort()); assert.deepEqual(files, f.sort());
puts("readdir " + readdirDir); console.log("readdir " + readdirDir);
fs.readdir(readdirDir, function (err, f) { fs.readdir(readdirDir, function (err, f) {
if (err) { if (err) {
puts("error"); console.log("error");
got_error = true; got_error = true;
} else { } else {
p(f); p(f);
@ -35,5 +35,5 @@ fs.readdir(readdirDir, function (err, f) {
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(false, got_error); assert.equal(false, got_error);
puts("exit"); console.log("exit");
}); });

4
test/simple/test-regression-object-prototype.js

@ -1,8 +1,8 @@
var sys = require('sys'); var sys = require('sys');
//sys.puts('puts before'); //console.log('puts before');
Object.prototype.xadsadsdasasdxx = function () { Object.prototype.xadsadsdasasdxx = function () {
}; };
sys.puts('puts after'); console.log('puts after');

8
test/simple/test-signal-handler.js

@ -1,26 +1,26 @@
require("../common"); require("../common");
puts("process.pid: " + process.pid); console.log("process.pid: " + process.pid);
var first = 0, var first = 0,
second = 0; second = 0;
process.addListener('SIGUSR1', function () { process.addListener('SIGUSR1', function () {
puts("Interrupted by SIGUSR1"); console.log("Interrupted by SIGUSR1");
first += 1; first += 1;
}); });
process.addListener('SIGUSR1', function () { process.addListener('SIGUSR1', function () {
second += 1; second += 1;
setTimeout(function () { setTimeout(function () {
puts("End."); console.log("End.");
process.exit(0); process.exit(0);
}, 5); }, 5);
}); });
i = 0; i = 0;
setInterval(function () { setInterval(function () {
puts("running process..." + ++i); console.log("running process..." + ++i);
if (i == 5) { if (i == 5) {
process.kill(process.pid, "SIGUSR1"); process.kill(process.pid, "SIGUSR1");

6
test/simple/test-signal-unregister.js

@ -13,14 +13,14 @@ child.addListener('exit', function () {
}); });
setTimeout(function () { setTimeout(function () {
sys.puts("Sending SIGINT"); console.log("Sending SIGINT");
child.kill("SIGINT"); child.kill("SIGINT");
setTimeout(function () { setTimeout(function () {
sys.puts("Chance has been given to die"); console.log("Chance has been given to die");
done = true; done = true;
if (!childKilled) { if (!childKilled) {
// Cleanup // Cleanup
sys.puts("Child did not die on SIGINT, sending SIGTERM"); console.log("Child did not die on SIGINT, sending SIGTERM");
child.kill("SIGTERM"); child.kill("SIGTERM");
} }
}, 200); }, 200);

4
test/simple/test-stdin-from-file.js

@ -13,7 +13,7 @@ string = "abc\nümlaut.\nsomething else\n"
+ "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n"; + "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n";
puts(cmd + "\n\n"); console.log(cmd + "\n\n");
try { try {
fs.unlinkSync(tmpFile); fs.unlinkSync(tmpFile);
@ -25,7 +25,7 @@ childProccess.exec(cmd, function(err, stdout, stderr) {
fs.unlinkSync(tmpFile); fs.unlinkSync(tmpFile);
if (err) throw err; if (err) throw err;
puts(stdout); console.log(stdout);
assert.equal(stdout, "hello world\r\n" + string); assert.equal(stdout, "hello world\r\n" + string);
assert.equal("", stderr); assert.equal("", stderr);
}); });

8
test/simple/test-stdout-to-file.js

@ -25,11 +25,11 @@ function test (size, useBuffer, cb) {
childProccess.exec(cmd, function(err) { childProccess.exec(cmd, function(err) {
if (err) throw err; if (err) throw err;
puts('done!'); console.log('done!');
var stat = fs.statSync(tmpFile); var stat = fs.statSync(tmpFile);
puts(tmpFile + ' has ' + stat.size + ' bytes'); console.log(tmpFile + ' has ' + stat.size + ' bytes');
assert.equal(size, stat.size); assert.equal(size, stat.size);
fs.unlinkSync(tmpFile); fs.unlinkSync(tmpFile);
@ -40,9 +40,9 @@ function test (size, useBuffer, cb) {
finished = false; finished = false;
test(1024*1024, false, function () { test(1024*1024, false, function () {
puts("Done printing with string"); console.log("Done printing with string");
test(1024*1024, true, function () { test(1024*1024, true, function () {
puts("Done printing with buffer"); console.log("Done printing with buffer");
finished = true; finished = true;
}); });
}); });

2
test/simple/test-string-decoder.js

@ -59,5 +59,5 @@ for (var j = 2; j < buffer.length; j++) {
print("."); print(".");
} }
} }
puts(" crayon!"); console.log(" crayon!");

2
test/simple/test-utf8-scripts.js

@ -2,7 +2,7 @@ require("../common");
// üäö // üäö
puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη"); console.log("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
assert.equal(true, /Hellö Wörld/.test("Hellö Wörld") ); assert.equal(true, /Hellö Wörld/.test("Hellö Wörld") );

Loading…
Cancel
Save