Browse Source

GJSLint part of tests

v0.7.4-release
Oleg Efimov 14 years ago
committed by Ryan Dahl
parent
commit
c0d69a4883
  1. 16
      test/fixtures/a.js
  2. 22
      test/fixtures/b/c.js
  3. 10
      test/fixtures/b/d.js
  4. 4
      test/fixtures/b/package/index.js
  5. 4
      test/fixtures/cycles/folder/foo.js
  6. 8
      test/fixtures/cycles/root.js
  7. 8
      test/fixtures/echo.js
  8. 6
      test/fixtures/global/plain.js
  9. 2
      test/fixtures/nested-index/one/hello.js
  10. 2
      test/fixtures/nested-index/two/hello.js
  11. 20
      test/fixtures/net-fd-passing-receiver.js
  12. 10
      test/fixtures/print-chars-from-buffer.js
  13. 6
      test/fixtures/print-chars.js
  14. 2
      test/fixtures/recvfd.js
  15. 8
      test/fixtures/require-path/p1/bar.js
  16. 2
      test/fixtures/require-path/p1/foo.js
  17. 2
      test/fixtures/require-path/p2/foo.js
  18. 6
      test/fixtures/should_exit.js
  19. 2
      test/fixtures/stdio-filter.js
  20. 2
      test/fixtures/throws_error.js
  21. 2
      test/fixtures/throws_error1.js
  22. 2
      test/fixtures/throws_error3.js
  23. 6
      test/message/2100bytes.js
  24. 4
      test/message/hello_world.js
  25. 4
      test/message/undefined_reference_in_new_context.js
  26. 18
      test/pummel/test-child-process-spawn-loop.js
  27. 28
      test/pummel/test-http-client-reconnect-bug.js
  28. 4
      test/pummel/test-http-upload-timeout.js
  29. 38
      test/pummel/test-keep-alive.js
  30. 48
      test/pummel/test-net-many-clients.js
  31. 44
      test/pummel/test-net-pause.js
  32. 76
      test/pummel/test-net-pingpong-delay.js
  33. 71
      test/pummel/test-net-pingpong.js
  34. 38
      test/pummel/test-net-throttle.js
  35. 58
      test/pummel/test-net-timeout.js
  36. 38
      test/pummel/test-timers.js
  37. 20
      test/pummel/test-watch-file.js
  38. 20
      test/simple/test-next-tick-ordering.js
  39. 8
      test/simple/test-next-tick-ordering2.js
  40. 4
      test/simple/test-script-context.js
  41. 4
      test/simple/test-script-static-context.js
  42. 24
      test/simple/test-signal-unregister.js
  43. 13
      test/simple/test-string-decoder.js
  44. 8
      test/simple/test-sync-fileread.js
  45. 108
      test/simple/test-sys.js
  46. 4
      test/simple/test-umask.js
  47. 8
      test/simple/test-url.js
  48. 8
      test/simple/test-utf8-scripts.js
  49. 15
      test/simple/test-zerolengthbufferbug.js

16
test/fixtures/a.js

@ -1,25 +1,25 @@
var c = require("./b/c"); var c = require('./b/c');
common.debug("load fixtures/a.js"); common.debug('load fixtures/a.js');
var string = "A"; var string = 'A';
exports.SomeClass = c.SomeClass; exports.SomeClass = c.SomeClass;
exports.A = function () { exports.A = function() {
return string; return string;
}; };
exports.C = function () { exports.C = function() {
return c.C(); return c.C();
}; };
exports.D = function () { exports.D = function() {
return c.D(); return c.D();
}; };
exports.number = 42; exports.number = 42;
process.addListener("exit", function () { process.addListener('exit', function() {
string = "A done"; string = 'A done';
}); });

22
test/fixtures/b/c.js

@ -1,28 +1,28 @@
var d = require("./d"); var d = require('./d');
var assert = require("assert"); var assert = require('assert');
var package = require("./package"); var package = require('./package');
assert.equal("world", package.hello); assert.equal('world', package.hello);
common.debug("load fixtures/b/c.js"); common.debug('load fixtures/b/c.js');
var string = "C"; var string = 'C';
exports.SomeClass = function() { exports.SomeClass = function() {
}; };
exports.C = function () { exports.C = function() {
return string; return string;
}; };
exports.D = function () { exports.D = function() {
return d.D(); return d.D();
}; };
process.addListener("exit", function () { process.addListener('exit', function() {
string = "C done"; string = 'C done';
console.log("b/c.js exit"); console.log('b/c.js exit');
}); });

10
test/fixtures/b/d.js

@ -1,12 +1,12 @@
common.debug("load fixtures/b/d.js"); common.debug('load fixtures/b/d.js');
var string = "D"; var string = 'D';
exports.D = function () { exports.D = function() {
return string; return string;
}; };
process.addListener("exit", function () { process.addListener('exit', function() {
string = "D done"; string = 'D done';
}); });

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

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

4
test/fixtures/cycles/folder/foo.js

@ -1,6 +1,6 @@
var root = require("./../root"); var root = require('./../root');
exports.hello = function () { exports.hello = function() {
return root.calledFromFoo(); return root.calledFromFoo();
}; };

8
test/fixtures/cycles/root.js

@ -1,10 +1,10 @@
var foo = exports.foo = require("./folder/foo"); var foo = exports.foo = require('./folder/foo');
exports.hello = "hello"; exports.hello = 'hello';
exports.sayHello = function () { exports.sayHello = function() {
return foo.hello(); return foo.hello();
}; };
exports.calledFromFoo = function () { exports.calledFromFoo = function() {
return exports.hello; return exports.hello;
}; };

8
test/fixtures/echo.js

@ -1,14 +1,14 @@
common = require("../common"); common = require('../common');
assert = common.assert; assert = common.assert;
common.print("hello world\r\n"); common.print('hello world\r\n');
var stdin = process.openStdin(); var stdin = process.openStdin();
stdin.addListener("data", function (data) { stdin.addListener('data', function(data) {
process.stdout.write(data.toString()); process.stdout.write(data.toString());
}); });
stdin.addListener("end", function () { stdin.addListener('end', function() {
process.stdout.end(); process.stdout.end();
}); });

6
test/fixtures/global/plain.js

@ -1,4 +1,4 @@
foo = "foo"; foo = 'foo';
global.bar = "bar"; global.bar = 'bar';
exports.fooBar = {foo: global.foo, bar:bar}; exports.fooBar = {foo: global.foo, bar: bar};

2
test/fixtures/nested-index/one/hello.js

@ -1,2 +1,2 @@
exports.hello = "hello from one!"; exports.hello = 'hello from one!';

2
test/fixtures/nested-index/two/hello.js

@ -1,2 +1,2 @@
exports.hello = "hello from two!"; exports.hello = 'hello from two!';

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

@ -1,32 +1,32 @@
process.mixin(require("../common")); process.mixin(require('../common'));
net = require("net"); net = require('net');
path = process.ARGV[2]; path = process.ARGV[2];
greeting = process.ARGV[3]; greeting = process.ARGV[3];
receiver = net.createServer(function(socket) { receiver = net.createServer(function(socket) {
socket.addListener("fd", function(fd) { socket.addListener('fd', function(fd) {
var peerInfo = process.getpeername(fd); var peerInfo = process.getpeername(fd);
peerInfo.fd = fd; peerInfo.fd = fd;
var passedSocket = new net.Socket(peerInfo); var passedSocket = new net.Socket(peerInfo);
passedSocket.addListener("eof", function() { passedSocket.addListener('eof', function() {
passedSocket.close(); passedSocket.close();
}); });
passedSocket.addListener("data", function(data) { passedSocket.addListener('data', function(data) {
passedSocket.send("[echo] " + data); passedSocket.send('[echo] ' + data);
}); });
passedSocket.addListener("close", function() { passedSocket.addListener('close', function() {
receiver.close(); receiver.close();
}); });
passedSocket.send("[greeting] " + greeting); passedSocket.send('[greeting] ' + greeting);
}); });
}); });
/* To signal the test runne we're up and listening */ /* To signal the test runne we're up and listening */
receiver.addListener("listening", function() { receiver.addListener('listening', function() {
common.print("ready"); common.print('ready');
}); });
receiver.listen(path); receiver.listen(path);

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

@ -1,10 +1,12 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
Buffer = require("buffer").Buffer; Buffer = require('buffer').Buffer;
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);
b = new Buffer(n); b = new Buffer(n);
for (var i = 0; i < n; i++) { b[i] = 100; } for (var i = 0; i < n; i++) {
b[i] = 100;
}
process.stdout.write(b); process.stdout.write(b);

6
test/fixtures/print-chars.js

@ -1,9 +1,9 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);
var s = ""; var s = '';
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
s += 'c'; s += 'c';
} }

2
test/fixtures/recvfd.js

@ -36,7 +36,7 @@ function processData(s) {
if (pipeStream.write(JSON.stringify(d) + '\n')) { if (pipeStream.write(JSON.stringify(d) + '\n')) {
drainFunc(); drainFunc();
} }
}; }
// Create a UNIX socket to the path defined by argv[2] and read a file // Create a UNIX socket to the path defined by argv[2] and read a file
// descriptor and misc data from it. // descriptor and misc data from it.

8
test/fixtures/require-path/p1/bar.js

@ -1,8 +1,8 @@
var path = require("path"); var path = require('path');
require.paths.unshift(path.join(__dirname,"../p2")); require.paths.unshift(path.join(__dirname, '../p2'));
exports.foo = require("foo"); exports.foo = require('foo');
exports.expect = require(path.join(__dirname, "../p2/bar")); exports.expect = require(path.join(__dirname, '../p2/bar'));
exports.actual = exports.foo.bar; exports.actual = exports.foo.bar;

2
test/fixtures/require-path/p1/foo.js

@ -1,2 +1,2 @@
require.paths.unshift(__dirname); require.paths.unshift(__dirname);
exports.bar = require("bar"); exports.bar = require('bar');

2
test/fixtures/require-path/p2/foo.js

@ -1,2 +1,2 @@
require.paths.unshift(__dirname); require.paths.unshift(__dirname);
exports.bar = require("bar"); // surprise! this is not /p2/bar, this is /p1/bar exports.bar = require('bar'); // surprise! this is not /p2/bar, this is /p1/bar

6
test/fixtures/should_exit.js

@ -1,6 +1,6 @@
function tmp() {} function tmp() {}
process.addListener("SIGINT", tmp); process.addListener('SIGINT', tmp);
process.removeListener("SIGINT", tmp); process.removeListener('SIGINT', tmp);
setInterval(function () { setInterval(function() {
process.stdout.write('keep alive\n'); process.stdout.write('keep alive\n');
}, 1000); }, 1000);

2
test/fixtures/stdio-filter.js

@ -5,7 +5,7 @@ var replacement = process.argv[3];
var re = new RegExp(regexIn, 'g'); var re = new RegExp(regexIn, 'g');
var stdin = process.openStdin(); var stdin = process.openStdin();
stdin.addListener("data", function (data) { stdin.addListener('data', function(data) {
data = data.toString(); data = data.toString();
process.stdout.write(data.replace(re, replacement)); process.stdout.write(data.replace(re, replacement));
}); });

2
test/fixtures/throws_error.js

@ -1 +1 @@
throw new Error("blah"); throw new Error('blah');

2
test/fixtures/throws_error1.js

@ -1 +1 @@
throw new Error("blah"); throw new Error('blah');

2
test/fixtures/throws_error3.js

@ -1,3 +1,3 @@
process.nextTick(function () { process.nextTick(function() {
JSON.parse(undefined); JSON.parse(undefined);
}); });

6
test/message/2100bytes.js

@ -1,5 +1,5 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
util = require('util'); util = require('util');
console.log([ console.log([
@ -44,6 +44,6 @@ console.log([
'_____________________________________________1950', '_____________________________________________1950',
'_____________________________________________2000', '_____________________________________________2000',
'_____________________________________________2050', '_____________________________________________2050',
'_____________________________________________2100', '_____________________________________________2100'
].join('\n')); ].join('\n'));

4
test/message/hello_world.js

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

4
test/message/undefined_reference_in_new_context.js

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

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

@ -1,5 +1,5 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
@ -7,23 +7,23 @@ var SIZE = 1000 * 1024;
var N = 40; var N = 40;
var finished = false; var finished = false;
function doSpawn (i) { function doSpawn(i) {
var child = spawn( 'python', ['-c', 'print ' + SIZE + ' * "C"']); var child = spawn('python', ['-c', 'print ' + SIZE + ' * "C"']);
var count = 0; var count = 0;
child.stdout.setEncoding('ascii'); child.stdout.setEncoding('ascii');
child.stdout.addListener("data", function (chunk) { child.stdout.addListener('data', function(chunk) {
count += chunk.length; count += chunk.length;
}); });
child.stderr.addListener("data", function (chunk) { child.stderr.addListener('data', function(chunk) {
console.log('stderr: ' + chunk); console.log('stderr: ' + chunk);
}); });
child.addListener("exit", function () { child.addListener('exit', function() {
assert.equal(SIZE + 1, count); // + 1 for \n assert.equal(SIZE + 1, count); // + 1 for \n
if (i < N) { if (i < N) {
doSpawn(i+1); doSpawn(i + 1);
} else { } else {
finished = true; finished = true;
} }
@ -32,6 +32,6 @@ function doSpawn (i) {
doSpawn(0); doSpawn(0);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.ok(finished); assert.ok(finished);
}); });

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

@ -1,9 +1,9 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var net = require("net"), var net = require('net'),
util = require("util"), util = require('util'),
http = require("http"); http = require('http');
var errorCount = 0; var errorCount = 0;
var eofCount = 0; var eofCount = 0;
@ -11,33 +11,33 @@ var eofCount = 0;
var server = net.createServer(function(socket) { var server = net.createServer(function(socket) {
socket.end(); socket.end();
}); });
server.on('listening', function(){ server.on('listening', function() {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);
client.addListener("error", function(err) { client.addListener('error', function(err) {
console.log("ERROR! "+(err.stack||err)); console.log('ERROR! ' + (err.stack || err));
errorCount++; errorCount++;
}); });
client.addListener("end", function() { client.addListener('end', function() {
console.log("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) {
console.log("STATUS: " + response.statusCode); console.log('STATUS: ' + response.statusCode);
}); });
}); });
server.listen(common.PORT); server.listen(common.PORT);
setTimeout(function () { setTimeout(function() {
server.close(); server.close();
}, 500); }, 500);
process.addListener('exit', function () { process.addListener('exit', function() {
assert.equal(0, errorCount); assert.equal(0, errorCount);
assert.equal(1, eofCount); assert.equal(1, eofCount);
}); });

4
test/pummel/test-http-upload-timeout.js

@ -1,8 +1,8 @@
// This tests setTimeout() by having multiple clients connecting and sending // This tests setTimeout() by having multiple clients connecting and sending
// data in random intervals. Clients are also randomly disconnecting until there // data in random intervals. Clients are also randomly disconnecting until there
// are no more clients left. If no false timeout occurs, this test has passed. // are no more clients left. If no false timeout occurs, this test has passed.
var common = require("../common"), var common = require('../common'),
assert = require("assert"), assert = require('assert'),
http = require('http'), http = require('http'),
server = http.createServer(), server = http.createServer(),
connections = 0; connections = 0;

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

@ -1,14 +1,14 @@
// This test requires the program "ab" // This test requires the program 'ab'
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
http = require("http"); http = require('http');
exec = require("child_process").exec; exec = require('child_process').exec;
body = "hello world\n"; body = 'hello world\n';
server = http.createServer(function (req, res) { server = http.createServer(function(req, res) {
res.writeHead(200, { res.writeHead(200, {
"Content-Length": body.length, 'Content-Length': body.length,
"Content-Type": "text/plain" 'Content-Type': 'text/plain'
}); });
res.write(body); res.write(body);
res.end(); res.end();
@ -19,11 +19,11 @@ var normalReqSec = 0;
function runAb(opts, callback) { function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/"; var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/';
exec(command, function (err, stdout, stderr) { exec(command, function(err, stdout, stderr) {
if (err) { if (err) {
if (stderr.indexOf("ab") >= 0) { if (stderr.indexOf('ab') >= 0) {
console.log("ab not installed? skipping test.\n" + stderr); console.log('ab not installed? skipping test.\n' + stderr);
process.reallyExit(0); process.reallyExit(0);
} }
return; return;
@ -44,22 +44,22 @@ function runAb(opts, callback) {
}); });
} }
server.listen(common.PORT, function () { server.listen(common.PORT, function() {
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { runAb('-k -c 100 -t 2', function(reqSec, keepAliveRequests) {
keepAliveReqSec = reqSec; keepAliveReqSec = reqSec;
assert.equal(true, keepAliveRequests > 0); assert.equal(true, keepAliveRequests > 0);
console.log("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);
console.log("normal: " + normalReqSec + " req/sec"); console.log('normal: ' + normalReqSec + ' req/sec');
server.close(); server.close();
}); });
}); });
}); });
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(true, normalReqSec > 50); assert.equal(true, normalReqSec > 50);
assert.equal(true, keepAliveReqSec > 50); assert.equal(true, keepAliveReqSec > 50);
assert.equal(true, normalReqSec < keepAliveReqSec); assert.equal(true, normalReqSec < keepAliveReqSec);

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

@ -1,56 +1,56 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
net = require("net"); net = require('net');
// settings // settings
var bytes = 1024*40; var bytes = 1024 * 40;
var concurrency = 100; var concurrency = 100;
var connections_per_client = 5; var connections_per_client = 5;
// measured // measured
var total_connections = 0; var total_connections = 0;
var body = ""; var body = '';
for (var i = 0; i < bytes; i++) { for (var i = 0; i < bytes; i++) {
body += "C"; body += 'C';
} }
var server = net.createServer(function (c) { var server = net.createServer(function(c) {
c.addListener("connect", function () { c.addListener('connect', function() {
total_connections++; total_connections++;
common.print("#"); common.print('#');
c.write(body); c.write(body);
c.end(); c.end();
}); });
}); });
function runClient (callback) { function runClient(callback) {
var client = net.createConnection(common.PORT); var client = net.createConnection(common.PORT);
client.connections = 0; client.connections = 0;
client.setEncoding("utf8"); client.setEncoding('utf8');
client.addListener("connect", function () { client.addListener('connect', function() {
common.print("c"); common.print('c');
client.recved = ""; client.recved = '';
client.connections += 1; client.connections += 1;
}); });
client.addListener("data", function (chunk) { client.addListener('data', function(chunk) {
this.recved += chunk; this.recved += chunk;
}); });
client.addListener("end", function () { client.addListener('end', function() {
client.end(); client.end();
}); });
client.addListener("error", function (e) { client.addListener('error', function(e) {
console.log("\n\nERROOOOOr"); console.log('\n\nERROOOOOr');
throw e; throw e;
}); });
client.addListener("close", function (had_error) { client.addListener('close', function(had_error) {
common.print("."); common.print('.');
assert.equal(false, had_error); assert.equal(false, had_error);
assert.equal(bytes, client.recved.length); assert.equal(bytes, client.recved.length);
@ -67,16 +67,16 @@ function runClient (callback) {
}); });
} }
server.listen(common.PORT, function () { server.listen(common.PORT, function() {
var finished_clients = 0; var finished_clients = 0;
for (var i = 0; i < concurrency; i++) { for (var i = 0; i < concurrency; i++) {
runClient(function () { runClient(function() {
if (++finished_clients == concurrency) server.close(); if (++finished_clients == concurrency) server.close();
}); });
} }
}); });
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(connections_per_client * concurrency, total_connections); assert.equal(connections_per_client * concurrency, total_connections);
console.log("\nokay!"); console.log('\nokay!');
}); });

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

@ -1,47 +1,47 @@
var common = require("../common"); var common = require('../common');
var assert = common.assert; var assert = common.assert;
var net = require("net"); var net = require('net');
var N = 200; var N = 200;
var recv = "", chars_recved = 0; var recv = '', chars_recved = 0;
server = net.createServer(function (connection) { server = net.createServer(function(connection) {
function write (j) { function write(j) {
if (j >= N) { if (j >= N) {
connection.end(); connection.end();
return; return;
} }
setTimeout(function () { setTimeout(function() {
connection.write("C"); connection.write('C');
write(j+1); write(j + 1);
}, 10); }, 10);
} }
write(0); write(0);
}); });
server.on('listening', function(){ server.on('listening', function() {
client = net.createConnection(common.PORT); client = net.createConnection(common.PORT);
client.setEncoding("ascii"); client.setEncoding('ascii');
client.addListener("data", function (d) { client.addListener('data', function(d) {
common.print(d); common.print(d);
recv += d; recv += d;
}); });
setTimeout(function () { setTimeout(function() {
chars_recved = recv.length; chars_recved = recv.length;
console.log("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() {
console.log("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;
console.log("pause at: " + chars_recved); console.log('pause at: ' + chars_recved);
client.pause(); client.pause();
setTimeout(function () { setTimeout(function() {
console.log("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();
@ -53,14 +53,14 @@ server.on('listening', function(){
}, 500); }, 500);
client.addListener("end", function () { client.addListener('end', function() {
server.close(); server.close();
client.end(); client.end();
}); });
}); });
server.listen(common.PORT); server.listen(common.PORT);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(N, recv.length); assert.equal(N, recv.length);
common.debug("Exit"); common.debug('Exit');
}); });

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

@ -1,84 +1,84 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
net = require("net"); net = require('net');
var tests_run = 0; var tests_run = 0;
function pingPongTest (port, host, on_complete) { function pingPongTest(port, host, on_complete) {
var N = 100; var N = 100;
var DELAY = 1; var DELAY = 1;
var count = 0; var count = 0;
var client_ended = false; var client_ended = false;
var server = net.createServer({ allowHalfOpen: true }, function (socket) { var server = net.createServer({ allowHalfOpen: true }, function(socket) {
socket.setEncoding("utf8"); socket.setEncoding('utf8');
socket.addListener("data", function (data) { socket.addListener('data', function(data) {
console.log(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);
setTimeout(function () { setTimeout(function() {
assert.equal("open", socket.readyState); assert.equal('open', socket.readyState);
socket.write("PONG"); socket.write('PONG');
}, DELAY); }, DELAY);
}); });
socket.addListener("timeout", function () { socket.addListener('timeout', function() {
common.debug("server-side timeout!!"); common.debug('server-side timeout!!');
assert.equal(false, true); assert.equal(false, true);
}); });
socket.addListener("end", function () { socket.addListener('end', function() {
console.log("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) {
console.log("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();
}); });
}); });
server.listen(port, host, function () { server.listen(port, host, function() {
var client = net.createConnection(port, host); var client = net.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding('utf8');
client.addListener("connect", function () { client.addListener('connect', function() {
assert.equal("open", client.readyState); assert.equal('open', client.readyState);
client.write("PING"); client.write('PING');
}); });
client.addListener("data", function (data) { client.addListener('data', function(data) {
console.log(data); console.log(data);
assert.equal("PONG", data); assert.equal('PONG', data);
assert.equal("open", client.readyState); assert.equal('open', client.readyState);
setTimeout(function () { setTimeout(function() {
assert.equal("open", client.readyState); assert.equal('open', client.readyState);
if (count++ < N) { if (count++ < N) {
client.write("PING"); client.write('PING');
} else { } else {
console.log("closing client"); console.log('closing client');
client.end(); client.end();
client_ended = true; client_ended = true;
} }
}, DELAY); }, DELAY);
}); });
client.addListener("timeout", function () { client.addListener('timeout', function() {
common.debug("client-side timeout!!"); common.debug('client-side timeout!!');
assert.equal(false, true); assert.equal(false, true);
}); });
client.addListener("close", function () { client.addListener('close', function() {
console.log("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();
tests_run += 1; tests_run += 1;
@ -88,6 +88,6 @@ function pingPongTest (port, host, on_complete) {
pingPongTest(common.PORT); pingPongTest(common.PORT);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(1, tests_run); assert.equal(1, tests_run);
}); });

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

@ -1,83 +1,84 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
net = require("net"); net = require('net');
var tests_run = 0; var tests_run = 0;
function pingPongTest (port, host, on_complete) { function pingPongTest(port, host, on_complete) {
var N = 1000; var N = 1000;
var count = 0; var count = 0;
var sent_final_ping = false; var sent_final_ping = false;
var server = net.createServer({ allowHalfOpen: true }, function (socket) { var server = net.createServer({ allowHalfOpen: true }, function(socket) {
assert.equal(true, socket.remoteAddress !== null); assert.equal(true, socket.remoteAddress !== null);
assert.equal(true, socket.remoteAddress !== undefined); assert.equal(true, socket.remoteAddress !== undefined);
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 {
console.log('host = ' + host + ', remoteAddress = ' + socket.remoteAddress); console.log('host = ' + host +
assert.equal(socket.remoteAddress, "::1"); ', remoteAddress = ' + socket.remoteAddress);
assert.equal(socket.remoteAddress, '::1');
} }
socket.setEncoding("utf8"); socket.setEncoding('utf8');
socket.setNoDelay(); socket.setNoDelay();
socket.timeout = 0; socket.timeout = 0;
socket.addListener("data", function (data) { socket.addListener('data', function(data) {
console.log("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)) {
socket.write("PONG"); socket.write('PONG');
} }
}); });
socket.addListener("end", function () { socket.addListener('end', function() {
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) {
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();
}); });
}); });
server.listen(port, host, function () { server.listen(port, host, function() {
var client = net.createConnection(port, host); var client = net.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding('utf8');
client.addListener("connect", function () { client.addListener('connect', function() {
assert.equal("open", client.readyState); assert.equal('open', client.readyState);
client.write("PING"); client.write('PING');
}); });
client.addListener("data", function (data) { client.addListener('data', function(data) {
console.log('client got: ' + data); console.log('client got: ' + data);
assert.equal("PONG", data); assert.equal('PONG', data);
count += 1; count += 1;
if (sent_final_ping) { if (sent_final_ping) {
assert.equal("readOnly", client.readyState); assert.equal('readOnly', client.readyState);
return; return;
} else { } else {
assert.equal("open", client.readyState); assert.equal('open', client.readyState);
} }
if (count < N) { if (count < N) {
client.write("PING"); client.write('PING');
} else { } else {
sent_final_ping = true; sent_final_ping = true;
client.write("PING"); client.write('PING');
client.end(); client.end();
} }
}); });
client.addListener("close", function () { client.addListener('close', function() {
assert.equal(N+1, count); assert.equal(N + 1, count);
assert.equal(true, sent_final_ping); assert.equal(true, sent_final_ping);
if (on_complete) on_complete(); if (on_complete) on_complete();
tests_run += 1; tests_run += 1;
@ -86,13 +87,13 @@ function pingPongTest (port, host, on_complete) {
} }
/* All are run at once, so run on different ports */ /* All are run at once, so run on different ports */
pingPongTest(common.PORT, "localhost"); pingPongTest(common.PORT, 'localhost');
pingPongTest(common.PORT+1, null); pingPongTest(common.PORT + 1, null);
// This IPv6 isn't working on Solaris // This IPv6 isn't working on Solaris
var solaris = /sunos/i.test(process.platform); var solaris = /sunos/i.test(process.platform);
if (!solaris) pingPongTest(common.PORT+2, "::1"); if (!solaris) pingPongTest(common.PORT + 2, '::1');
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(solaris ? 2 : 3, tests_run); assert.equal(solaris ? 2 : 3, tests_run);
}); });

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

@ -1,49 +1,49 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
net = require("net"); net = require('net');
N = 160*1024; // 30kb N = 160 * 1024; // 30kb
chars_recved = 0; chars_recved = 0;
npauses = 0; npauses = 0;
console.log("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';
} }
console.log("start server on port " + common.PORT); console.log('start server on port ' + common.PORT);
server = net.createServer(function (connection) { server = net.createServer(function(connection) {
connection.addListener("connect", function () { connection.addListener('connect', function() {
assert.equal(false, connection.write(body)); assert.equal(false, connection.write(body));
connection.end(); connection.end();
}); });
}); });
server.listen(common.PORT, function () { server.listen(common.PORT, function() {
var paused = false; var paused = false;
client = net.createConnection(common.PORT); client = net.createConnection(common.PORT);
client.setEncoding("ascii"); client.setEncoding('ascii');
client.addListener("data", function (d) { client.addListener('data', function(d) {
chars_recved += d.length; chars_recved += d.length;
console.log("got " + chars_recved); console.log('got ' + chars_recved);
if (!paused) { if (!paused) {
client.pause(); client.pause();
npauses += 1; npauses += 1;
paused = true; paused = true;
console.log("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();
console.log("resume"); console.log('resume');
paused = false; paused = false;
}, 100); }, 100);
} }
}); });
client.addListener("end", function () { client.addListener('end', function() {
server.close(); server.close();
client.end(); client.end();
}); });
@ -51,7 +51,7 @@ server.listen(common.PORT, function () {
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(N, chars_recved); assert.equal(N, chars_recved);
assert.equal(true, npauses > 2); assert.equal(true, npauses > 2);
}); });

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

@ -1,83 +1,83 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
net = require("net"); net = require('net');
exchanges = 0; exchanges = 0;
starttime = null; starttime = null;
timeouttime = null; timeouttime = null;
timeout = 1000; timeout = 1000;
var echo_server = net.createServer(function (socket) { var echo_server = net.createServer(function(socket) {
socket.setTimeout(timeout); socket.setTimeout(timeout);
socket.addListener("timeout", function () { socket.addListener('timeout', function() {
console.log("server timeout"); console.log('server timeout');
timeouttime = new Date; timeouttime = new Date;
console.dir(timeouttime); console.dir(timeouttime);
socket.destroy(); socket.destroy();
}); });
socket.addListener("error", function (e) { socket.addListener('error', function(e) {
throw new Error("Server side socket should not get error. We disconnect willingly."); throw new Error('Server side socket should not get error. We disconnect willingly.');
}) })
socket.addListener("data", function (d) { socket.addListener('data', function(d) {
console.log(d); console.log(d);
socket.write(d); socket.write(d);
}); });
socket.addListener("end", function () { socket.addListener('end', function() {
socket.end(); socket.end();
}); });
}); });
echo_server.listen(common.PORT, function () { echo_server.listen(common.PORT, function() {
console.log("server listening at " + common.PORT); console.log('server listening at ' + common.PORT);
var client = net.createConnection(common.PORT); var client = net.createConnection(common.PORT);
client.setEncoding("UTF8"); client.setEncoding('UTF8');
client.setTimeout(0); // disable the timeout for client client.setTimeout(0); // disable the timeout for client
client.addListener("connect", function () { client.addListener('connect', function() {
console.log("client connected."); console.log('client connected.');
client.write("hello\r\n"); client.write('hello\r\n');
}); });
client.addListener("data", function (chunk) { 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() {
console.log("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) {
console.log("wait for timeout - should come in " + timeout + " ms"); console.log('wait for timeout - should come in ' + timeout + ' ms');
starttime = new Date; starttime = new Date;
console.dir(starttime); console.dir(starttime);
} }
} }
}); });
client.addListener("timeout", function () { client.addListener('timeout', function() {
throw new Error("client timeout - this shouldn't happen"); throw new Error("client timeout - this shouldn't happen");
}); });
client.addListener("end", function () { client.addListener('end', function() {
console.log("client end"); console.log('client end');
client.end(); client.end();
}); });
client.addListener("close", function () { client.addListener('close', function() {
console.log("client disconnect"); console.log('client disconnect');
echo_server.close(); echo_server.close();
}); });
}); });
process.addListener("exit", function () { process.addListener('exit', function() {
assert.ok(starttime != null); assert.ok(starttime != null);
assert.ok(timeouttime != null); assert.ok(timeouttime != null);
diff = timeouttime - starttime; diff = timeouttime - starttime;
console.log("diff = " + diff); console.log('diff = ' + diff);
assert.ok(timeout < diff); assert.ok(timeout < diff);

38
test/pummel/test-timers.js

@ -1,4 +1,4 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert
assert = require('assert'); assert = require('assert');
@ -14,28 +14,28 @@ clearInterval(null);
assert.equal(true, setTimeout instanceof Function); assert.equal(true, setTimeout instanceof Function);
var starttime = new Date; var starttime = new Date;
setTimeout(function () { setTimeout(function() {
var endtime = new Date; var endtime = new Date;
var diff = endtime - starttime; var diff = endtime - starttime;
assert.ok(diff > 0); assert.ok(diff > 0);
console.log("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;
}, 1000); }, 1000);
// this timer shouldn't execute // this timer shouldn't execute
var id = setTimeout(function () { assert.equal(true, false); }, 500); var id = setTimeout(function() { assert.equal(true, false); }, 500);
clearTimeout(id); clearTimeout(id);
setInterval(function () { setInterval(function() {
interval_count += 1; interval_count += 1;
var endtime = new Date; var endtime = new Date;
var diff = endtime - starttime; var diff = endtime - starttime;
assert.ok(diff > 0); assert.ok(diff > 0);
console.log("diff: " + diff); console.log('diff: ' + diff);
var t = interval_count * 1000; var t = interval_count * 1000;
@ -49,38 +49,38 @@ setInterval(function () {
// Single param: // Single param:
setTimeout(function(param){ setTimeout(function(param){
assert.equal("test param", param); assert.equal('test param', param);
}, 1000, "test param"); }, 1000, 'test param');
var interval_count2 = 0; var interval_count2 = 0;
setInterval(function(param){ setInterval(function(param){
++interval_count2; ++interval_count2;
assert.equal("test param", param); assert.equal('test param', param);
if(interval_count2 == 3) if(interval_count2 == 3)
clearInterval(this); clearInterval(this);
}, 1000, "test param"); }, 1000, 'test param');
// Multiple param // Multiple param
setTimeout(function(param1, param2){ setTimeout(function(param1, param2){
assert.equal("param1", param1); assert.equal('param1', param1);
assert.equal("param2", param2); assert.equal('param2', param2);
}, 1000, "param1", "param2"); }, 1000, 'param1', 'param2');
var interval_count3 = 0; var interval_count3 = 0;
setInterval(function(param1, param2){ setInterval(function(param1, param2){
++interval_count3; ++interval_count3;
assert.equal("param1", param1); assert.equal('param1', param1);
assert.equal("param2", param2); assert.equal('param2', param2);
if(interval_count3 == 3) if(interval_count3 == 3)
clearInterval(this); clearInterval(this);
}, 1000, "param1", "param2"); }, 1000, 'param1', 'param2');
// setInterval(cb, 0) should be called multiple times. // setInterval(cb, 0) should be called multiple times.
count4 = 0; count4 = 0;
interval4 = setInterval(function () { interval4 = setInterval(function() {
if (++count4 > 10) clearInterval(interval4); if (++count4 > 10) clearInterval(interval4);
}, 0); }, 0);
@ -101,9 +101,9 @@ z = setTimeout(t, 200);
clearTimeout(y); clearTimeout(y);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.equal(true, setTimeout_called); assert.equal(true, setTimeout_called);
assert.equal(3, interval_count); assert.equal(3, interval_count);
assert.equal(11, count4); assert.equal(11, count4);
assert.equal(0, expectedTimeouts, "clearTimeout cleared too many timeouts"); assert.equal(0, expectedTimeouts, 'clearTimeout cleared too many timeouts');
}); });

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

@ -1,18 +1,18 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert
var fs = require("fs"); var fs = require('fs');
var path = require("path"); var path = require('path');
var f = path.join(common.fixturesDir, "x.txt"); var f = path.join(common.fixturesDir, 'x.txt');
var f2 = path.join(common.fixturesDir, "x2.txt"); var f2 = path.join(common.fixturesDir, 'x2.txt');
console.log("watching for changes of " + f); console.log('watching for changes of ' + f);
var changes = 0; var changes = 0;
function watchFile () { function watchFile () {
fs.watchFile(f, function (curr, prev) { fs.watchFile(f, function(curr, prev) {
console.log(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);
@ -24,10 +24,10 @@ function watchFile () {
watchFile(); watchFile();
var fd = fs.openSync(f, "w+"); var fd = fs.openSync(f, 'w+');
fs.writeSync(fd, 'xyz\n'); fs.writeSync(fd, 'xyz\n');
fs.closeSync(fd); fs.closeSync(fd);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.ok(changes > 0); assert.ok(changes > 0);
}); });

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

@ -1,32 +1,32 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var i; var i;
var N = 30; var N = 30;
var done = []; var done = [];
function get_printer(timeout) { function get_printer(timeout) {
return function () { return function() {
console.log("Running from setTimeout " + timeout); console.log('Running from setTimeout ' + timeout);
done.push(timeout); done.push(timeout);
}; };
} }
process.nextTick(function () { process.nextTick(function() {
console.log("Running from nextTick"); console.log('Running from nextTick');
done.push('nextTick'); done.push('nextTick');
}) });
for (i = 0; i < N; i += 1) { for (i = 0; i < N; i += 1) {
setTimeout(get_printer(i), i); setTimeout(get_printer(i), i);
} }
console.log("Running from main."); console.log('Running from main.');
process.addListener('exit', function () { process.addListener('exit', function() {
assert.equal('nextTick', done[0]); assert.equal('nextTick', done[0]);
for (i = 0; i < N; i += 1) { for (i = 0; i < N; i += 1) {
assert.equal(i, done[i+1]); assert.equal(i, done[i + 1]);
} }
}); });

8
test/simple/test-next-tick-ordering2.js

@ -1,8 +1,8 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var order = []; var order = [];
process.nextTick(function () { process.nextTick(function() {
setTimeout(function() { setTimeout(function() {
order.push('setTimeout'); order.push('setTimeout');
}, 0); }, 0);
@ -12,6 +12,6 @@ process.nextTick(function () {
}); });
}) })
process.addListener('exit', function () { process.addListener('exit', function() {
assert.deepEqual(order, ['nextTick', 'setTimeout']); assert.deepEqual(order, ['nextTick', 'setTimeout']);
}); });

4
test/simple/test-script-context.js

@ -1,5 +1,5 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var Script = require('vm').Script; var Script = require('vm').Script;
var script = new Script('"passed";'); var script = new Script('"passed";');

4
test/simple/test-script-static-context.js

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

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

@ -1,32 +1,32 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var childKilled = false, done = false, var childKilled = false, done = false,
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
util = require("util"), util = require('util'),
child; child;
var join = require('path').join; var join = require('path').join;
child = spawn(process.argv[0], [join(common.fixturesDir, 'should_exit.js')]); child = spawn(process.argv[0], [join(common.fixturesDir, 'should_exit.js')]);
child.addListener('exit', function () { child.addListener('exit', function() {
if (!done) childKilled = true; if (!done) childKilled = true;
}); });
setTimeout(function () { setTimeout(function() {
console.log("Sending SIGINT"); console.log('Sending SIGINT');
child.kill("SIGINT"); child.kill('SIGINT');
setTimeout(function () { setTimeout(function() {
console.log("Chance has been given to die"); console.log('Chance has been given to die');
done = true; done = true;
if (!childKilled) { if (!childKilled) {
// Cleanup // Cleanup
console.log("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);
}, 200); }, 200);
process.addListener("exit", function () { process.addListener('exit', function() {
assert.ok(childKilled); assert.ok(childKilled);
}); });

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

@ -1,5 +1,5 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
Buffer = require('buffer').Buffer; Buffer = require('buffer').Buffer;
StringDecoder = require('string_decoder').StringDecoder; StringDecoder = require('string_decoder').StringDecoder;
@ -34,8 +34,9 @@ assert.ok(s.length > 0);
// U+12E4 -> E1 8B A4 // U+12E4 -> E1 8B A4
// U+0030 -> 30 // U+0030 -> 30
// U+3045 -> E3 81 85 // U+3045 -> E3 81 85
expected = "\u02e4\u0064\u12e4\u0030\u3045"; expected = '\u02e4\u0064\u12e4\u0030\u3045';
buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, 0xE3, 0x81, 0x85]); buffer = new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4,
0x30, 0xE3, 0x81, 0x85]);
charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5]; charLengths = [0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5];
// Split the buffer into 3 segments // Split the buffer into 3 segments
@ -57,8 +58,8 @@ for (var j = 2; j < buffer.length; j++) {
sum += decoder.write(buffer.slice(i, j)); sum += decoder.write(buffer.slice(i, j));
sum += decoder.write(buffer.slice(j, buffer.length)); sum += decoder.write(buffer.slice(j, buffer.length));
assert.equal(expected, sum); assert.equal(expected, sum);
common.print("."); common.print('.');
} }
} }
console.log(" crayon!"); console.log(' crayon!');

8
test/simple/test-sync-fileread.js

@ -1,8 +1,8 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var fixture = path.join(__dirname, "../fixtures/x.txt"); var fixture = path.join(__dirname, '../fixtures/x.txt');
assert.equal("xyz\n", fs.readFileSync(fixture)); assert.equal('xyz\n', fs.readFileSync(fixture));

108
test/simple/test-sys.js

@ -1,19 +1,19 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
assert.equal("0", common.inspect(0)); assert.equal('0', common.inspect(0));
assert.equal("1", common.inspect(1)); assert.equal('1', common.inspect(1));
assert.equal("false", common.inspect(false)); assert.equal('false', common.inspect(false));
assert.equal("''", common.inspect("")); assert.equal("''", common.inspect(''));
assert.equal("'hello'", common.inspect("hello")); assert.equal("'hello'", common.inspect('hello'));
assert.equal("[Function]", common.inspect(function() {})); assert.equal('[Function]', common.inspect(function() {}));
assert.equal('undefined', common.inspect(undefined)); assert.equal('undefined', common.inspect(undefined));
assert.equal('null', common.inspect(null)); assert.equal('null', common.inspect(null));
assert.equal('/foo(bar\\n)?/gi', common.inspect(/foo(bar\n)?/gi)); assert.equal('/foo(bar\\n)?/gi', common.inspect(/foo(bar\n)?/gi));
assert.equal('Sun, 14 Feb 2010 11:48:40 GMT', assert.equal('Sun, 14 Feb 2010 11:48:40 GMT',
common.inspect(new Date("Sun, 14 Feb 2010 11:48:40 GMT"))); common.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')));
assert.equal("'\\n\\u0001'", common.inspect("\n\u0001")); assert.equal("'\\n\\u0001'", common.inspect('\n\u0001'));
assert.equal('[]', common.inspect([])); assert.equal('[]', common.inspect([]));
assert.equal('[]', common.inspect(Object.create([]))); assert.equal('[]', common.inspect(Object.create([])));
@ -26,78 +26,74 @@ assert.equal('{ a: [Function] }', common.inspect({a: function() {}}));
assert.equal('{ a: 1, b: 2 }', common.inspect({a: 1, b: 2})); assert.equal('{ a: 1, b: 2 }', common.inspect({a: 1, b: 2}));
assert.equal('{ a: {} }', common.inspect({'a': {}})); assert.equal('{ a: {} }', common.inspect({'a': {}}));
assert.equal('{ a: { b: 2 } }', common.inspect({'a': {'b': 2}})); assert.equal('{ a: { b: 2 } }', common.inspect({'a': {'b': 2}}));
assert.equal('{ a: { b: { c: [Object] } } }', common.inspect({'a': {'b': { 'c': { 'd': 2 }}}})); assert.equal('{ a: { b: { c: [Object] } } }',
assert.equal('{ a: { b: { c: { d: 2 } } } }', common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null)); common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
assert.equal('[ 1, 2, 3, [length]: 3 ]', common.inspect([1,2,3], true)); assert.equal('{ a: { b: { c: { d: 2 } } } }',
assert.equal('{ a: [Object] }', common.inspect({'a': {'b': { 'c': 2}}},false,0)); common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
assert.equal('{ a: { b: [Object] } }', common.inspect({'a': {'b': { 'c': 2}}},false,1)); assert.equal('[ 1, 2, 3, [length]: 3 ]', common.inspect([1, 2, 3], true));
assert.equal("{ visible: 1 }", assert.equal('{ a: [Object] }',
common.inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}})) common.inspect({'a': {'b': { 'c': 2}}}, false, 0));
assert.equal('{ a: { b: [Object] } }',
common.inspect({'a': {'b': { 'c': 2}}}, false, 1));
assert.equal('{ visible: 1 }',
common.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}))
); );
assert.equal("{ [hidden]: 2, visible: 1 }", assert.equal('{ [hidden]: 2, visible: 1 }',
common.inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}}), true) common.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true)
); );
// Objects without prototype // Objects without prototype
assert.equal( assert.equal('{ [hidden]: \'secret\', name: \'Tim\' }',
"{ [hidden]: 'secret', name: 'Tim' }", common.inspect(Object.create(null,
common.inspect(Object.create(null, {name: {value: "Tim", enumerable: true}, hidden: {value: "secret"}}), true) {name: {value: 'Tim', enumerable: true},
hidden: {value: 'secret'}}), true)
); );
assert.equal( assert.equal('{ name: \'Tim\' }',
"{ name: 'Tim' }", common.inspect(Object.create(null,
common.inspect(Object.create(null, {name: {value: "Tim", enumerable: true}, hidden: {value: "secret"}})) {name: {value: 'Tim', enumerable: true},
hidden: {value: 'secret'}}))
); );
// Dynamic properties // Dynamic properties
assert.equal( assert.equal('{ readonly: [Getter] }',
"{ readonly: [Getter] }", common.inspect({get readonly() {}}));
common.inspect({get readonly(){}})
); assert.equal('{ readwrite: [Getter/Setter] }',
assert.equal( common.inspect({get readwrite() {},set readwrite(val) {}}));
"{ readwrite: [Getter/Setter] }",
common.inspect({get readwrite(){},set readwrite(val){}}) assert.equal('{ writeonly: [Setter] }',
); common.inspect({set writeonly(val) {}}));
assert.equal(
"{ writeonly: [Setter] }",
common.inspect({set writeonly(val){}})
);
var value = {}; var value = {};
value['a'] = value; value['a'] = value;
assert.equal('{ a: [Circular] }', common.inspect(value)); assert.equal('{ a: [Circular] }', common.inspect(value));
value = Object.create([]); value = Object.create([]);
value.push(1); value.push(1);
assert.equal("[ 1, length: 1 ]", common.inspect(value)); assert.equal('[ 1, length: 1 ]', common.inspect(value));
// Array with dynamic properties // Array with dynamic properties
value = [1,2,3]; value = [1, 2, 3];
value.__defineGetter__('growingLength', function () { this.push(true); return this.length; }); value.__defineGetter__('growingLength', function() {
assert.equal( this.push(true); return this.length;
"[ 1, 2, 3, growingLength: [Getter] ]", });
common.inspect(value) assert.equal('[ 1, 2, 3, growingLength: [Getter] ]', common.inspect(value));
);
// Function with properties // Function with properties
value = function () {}; value = function() {};
value.aprop = 42; value.aprop = 42;
assert.equal( assert.equal('{ [Function] aprop: 42 }', common.inspect(value));
"{ [Function] aprop: 42 }",
common.inspect(value)
);
// Regular expressions with properties // Regular expressions with properties
value = /123/ig; value = /123/ig;
value.aprop = 42; value.aprop = 42;
assert.equal( assert.equal('{ /123/gi aprop: 42 }', common.inspect(value));
"{ /123/gi aprop: 42 }",
common.inspect(value)
);
// Dates with properties // Dates with properties
value = new Date("Sun, 14 Feb 2010 11:48:40 GMT"); value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
value.aprop = 42; value.aprop = 42;
assert.equal( assert.equal('{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }',
"{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }",
common.inspect(value) common.inspect(value)
); );

4
test/simple/test-umask.js

@ -1,5 +1,5 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var mask = 0664; var mask = 0664;
var old = process.umask(mask); var old = process.umask(mask);

8
test/simple/test-url.js

@ -1,8 +1,8 @@
common = require("../common"); common = require('../common');
assert = common.assert assert = common.assert;
var url = require("url"), var url = require('url'),
util = require("util"); util = require('util');
// URLs to parse, and expected data // URLs to parse, and expected data
// { url : parsed } // { url : parsed }

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

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

15
test/simple/test-zerolengthbufferbug.js

@ -1,11 +1,12 @@
// Serving up a zero-length buffer should work. // Serving up a zero-length buffer should work.
var common = require("../common"); var common = require('../common');
var assert = common.assert; var assert = common.assert;
var http = require('http'); var http = require('http');
var server = http.createServer(function (req, res) { var server = http.createServer(function(req, res) {
var buffer = new Buffer(0); var buffer = new Buffer(0);
// FIXME: WTF gjslint want this?
res.writeHead(200, {'Content-Type': 'text/html', res.writeHead(200, {'Content-Type': 'text/html',
'Content-Length': buffer.length}); 'Content-Length': buffer.length});
res.end(buffer); res.end(buffer);
@ -14,26 +15,26 @@ var server = http.createServer(function (req, res) {
var gotResponse = false; var gotResponse = false;
var resBodySize = 0; var resBodySize = 0;
server.listen(common.PORT, function () { server.listen(common.PORT, function() {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);
var req = client.request('GET', '/'); var req = client.request('GET', '/');
req.end(); req.end();
req.on('response', function (res) { req.on('response', function(res) {
gotResponse = true; gotResponse = true;
res.on('data', function (d) { res.on('data', function(d) {
resBodySize += d.length; resBodySize += d.length;
}); });
res.on('end', function (d) { res.on('end', function(d) {
server.close(); server.close();
}); });
}); });
}); });
process.on('exit', function () { process.on('exit', function() {
assert.ok(gotResponse); assert.ok(gotResponse);
assert.equal(0, resBodySize); assert.equal(0, resBodySize);
}); });

Loading…
Cancel
Save