Browse Source

GJSLint all simple tests exclude http-*, url, path

v0.7.4-release
Oleg Efimov 14 years ago
committed by Ryan Dahl
parent
commit
0665f0271e
  1. 22
      test/common.js
  2. 4
      test/simple/path.js
  3. 113
      test/simple/test-assert.js
  4. 190
      test/simple/test-buffer.js
  5. 42
      test/simple/test-c-ares.js
  6. 20
      test/simple/test-child-process-buffering.js
  7. 63
      test/simple/test-child-process-custom-fds.js
  8. 33
      test/simple/test-child-process-cwd.js
  9. 50
      test/simple/test-child-process-deprecated-api.js
  10. 27
      test/simple/test-child-process-double-pipe.js
  11. 14
      test/simple/test-child-process-env.js
  12. 6
      test/simple/test-child-process-exec-cwd.js
  13. 33
      test/simple/test-child-process-exec-env.js
  14. 7
      test/simple/test-child-process-exit-code.js
  15. 14
      test/simple/test-child-process-ipc.js
  16. 14
      test/simple/test-child-process-kill.js
  17. 30
      test/simple/test-child-process-stdin.js
  18. 10
      test/simple/test-child-process-stdout-flush.js
  19. 24
      test/simple/test-cli-eval.js
  20. 4
      test/simple/test-console.js
  21. 102
      test/simple/test-crypto.js
  22. 12
      test/simple/test-delayed-require.js
  23. 51
      test/simple/test-dgram-multicast.js
  24. 58
      test/simple/test-dgram-pingpong.js
  25. 64
      test/simple/test-dgram-udp4.js
  26. 48
      test/simple/test-dgram-unix-anon.js
  27. 47
      test/simple/test-dgram-unix.js
  28. 21
      test/simple/test-eio-race.js
  29. 12
      test/simple/test-eio-race2.js
  30. 8
      test/simple/test-eio-race4.js
  31. 12
      test/simple/test-error-reporting.js
  32. 22
      test/simple/test-event-emitter-add-listeners.js
  33. 66
      test/simple/test-event-emitter-modify-in-emit.js
  34. 22
      test/simple/test-event-emitter-num-args.js
  35. 12
      test/simple/test-event-emitter-once.js
  36. 20
      test/simple/test-event-emitter-remove-listeners.js
  37. 12
      test/simple/test-exception-handler.js
  38. 4
      test/simple/test-exception-handler2.js
  39. 49
      test/simple/test-exec.js
  40. 10
      test/simple/test-executable-path.js
  41. 12
      test/simple/test-file-read-noexist.js
  42. 71
      test/simple/test-file-write-stream.js
  43. 6
      test/simple/test-fs-chmod.js
  44. 9
      test/simple/test-fs-error-messages.js
  45. 20
      test/simple/test-fs-fsync.js
  46. 2
      test/simple/test-fs-read-file-sync-hostname.js
  47. 2
      test/simple/test-fs-read-file-sync.js
  48. 14
      test/simple/test-fs-read-stream.js
  49. 7
      test/simple/test-fs-readfile-empty.js
  50. 20
      test/simple/test-fs-sir-writes-alot.js
  51. 30
      test/simple/test-fs-stat.js
  52. 14
      test/simple/test-fs-symlink.js
  53. 4
      test/simple/test-fs-write-buffer.js
  54. 34
      test/simple/test-fs-write-file-buffer.js
  55. 18
      test/simple/test-fs-write-file.js
  56. 15
      test/simple/test-fs-write-stream.js
  57. 4
      test/simple/test-fs-write-sync.js
  58. 52
      test/simple/test-fs-write.js
  59. 16
      test/simple/test-global.js
  60. 18
      test/simple/test-mkdir-rmdir.js
  61. 2
      test/simple/test-net-connect-handle-econnrefused.js
  62. 10
      test/simple/test-net-keepalive.js
  63. 4
      test/simple/test-net-pingpong.js
  64. 4
      test/simple/test-net-reconnect.js
  65. 8
      test/simple/test-net-server-bind.js
  66. 20
      test/simple/test-net-server-max-connections.js
  67. 2
      test/simple/test-next-tick-ordering.js
  68. 2
      test/simple/test-next-tick-ordering2.js
  69. 38
      test/simple/test-repl.js
  70. 2
      test/simple/test-require-resolve.js
  71. 2
      test/simple/test-script-context.js
  72. 2
      test/simple/test-script-static-context.js
  73. 2
      test/simple/test-securepair-server.js
  74. 3
      test/simple/test-sigint-infinite-loop.js
  75. 2
      test/simple/test-signal-unregister.js
  76. 2
      test/simple/test-sync-fileread.js
  77. 2
      test/simple/test-sys.js
  78. 2
      test/simple/test-umask.js
  79. 2
      test/simple/test-utf8-scripts.js
  80. 2
      test/simple/test-zerolengthbufferbug.js

22
test/common.js

@ -12,7 +12,7 @@ var util = require('util');
for (var i in util) exports[i] = util[i];
//for (var i in exports) global[i] = exports[i];
function protoCtrChain (o) {
function protoCtrChain(o) {
var result = [];
for (; o; o = o.__proto__) { result.push(o.constructor); }
return result.join();
@ -29,16 +29,16 @@ exports.indirectInstanceOf = function(obj, cls) {
// Turn this off if the test should not check for global leaks.
exports.globalCheck = true;
process.on('exit', function () {
process.on('exit', function() {
if (!exports.globalCheck) return;
var knownGlobals = [ setTimeout,
setInterval,
clearTimeout,
clearInterval,
console,
Buffer,
process,
global ];
var knownGlobals = [setTimeout,
setInterval,
clearTimeout,
clearInterval,
console,
Buffer,
process,
global];
for (var x in global) {
var found = false;
@ -51,7 +51,7 @@ process.on('exit', function () {
}
if (!found) {
console.error("Unknown global: %s", x);
console.error('Unknown global: %s', x);
exports.assert.ok(false);
}
}

4
test/simple/path.js

@ -2,4 +2,6 @@
// sure that require('./path') and require('path') do different things.
// It has to be in the same directory as the test 'test-module-loading.js'
// and it has to have the same name as an internal module.
exports.path_func = function() { return "path_func"}
exports.path_func = function() {
return 'path_func';
};

113
test/simple/test-assert.js

@ -1,24 +1,24 @@
var common = require("../common");
var common = require('../common');
var assert = require('assert');
var a = require('assert');
function makeBlock (f) {
var args = Array.prototype.slice.call(arguments,1);
return function () {
return f.apply(this,args);
function makeBlock(f) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return f.apply(this, args);
};
}
assert.ok(common.indirectInstanceOf(a.AssertionError.prototype, Error),
"a.AssertionError instanceof Error");
'a.AssertionError instanceof Error');
assert.throws(makeBlock(a.ok, false),
a.AssertionError, "ok(false)");
a.AssertionError, 'ok(false)');
assert.doesNotThrow(makeBlock(a.ok, true),
a.AssertionError, "ok(true)");
a.AssertionError, 'ok(true)');
assert.doesNotThrow(makeBlock(a.ok, "test"), "ok('test')");
assert.doesNotThrow(makeBlock(a.ok, 'test'), 'ok(\'test\')');
assert.throws(makeBlock(a.equal, true, false), a.AssertionError, 'equal');
@ -30,68 +30,70 @@ assert.doesNotThrow(makeBlock(a.equal, null, undefined), 'equal');
assert.doesNotThrow(makeBlock(a.equal, true, true), 'equal');
assert.doesNotThrow(makeBlock(a.equal, 2, "2"), 'equal');
assert.doesNotThrow(makeBlock(a.equal, 2, '2'), 'equal');
assert.doesNotThrow(makeBlock(a.notEqual, true, false), 'notEqual');
assert.throws(makeBlock(a.notEqual, true, true), a.AssertionError, 'notEqual');
assert.throws(makeBlock(a.notEqual, true, true),
a.AssertionError, 'notEqual');
assert.throws(makeBlock(a.strictEqual, 2, "2"), a.AssertionError, 'strictEqual');
assert.throws(makeBlock(a.strictEqual, 2, '2'),
a.AssertionError, 'strictEqual');
assert.throws(makeBlock(a.strictEqual, null, undefined), a.AssertionError, 'strictEqual');
assert.throws(makeBlock(a.strictEqual, null, undefined),
a.AssertionError, 'strictEqual');
assert.doesNotThrow(makeBlock(a.notStrictEqual, 2, "2"), 'notStrictEqual');
assert.doesNotThrow(makeBlock(a.notStrictEqual, 2, '2'), 'notStrictEqual');
// deepEquals joy!
// 7.2
assert.doesNotThrow(makeBlock(a.deepEqual, new Date(2000,3,14), new Date(2000,3,14)),
'deepEqual date');
assert.doesNotThrow(makeBlock(a.deepEqual, new Date(2000, 3, 14),
new Date(2000, 3, 14)), 'deepEqual date');
assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000,3,14)),
assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000, 3, 14)),
a.AssertionError,
'deepEqual date');
// 7.3
assert.doesNotThrow(makeBlock(a.deepEqual, 4, "4"), 'deepEqual == check');
assert.doesNotThrow(makeBlock(a.deepEqual, 4, '4'), 'deepEqual == check');
assert.doesNotThrow(makeBlock(a.deepEqual, true, 1), 'deepEqual == check');
assert.throws(makeBlock(a.deepEqual, 4, "5"),
assert.throws(makeBlock(a.deepEqual, 4, '5'),
a.AssertionError,
'deepEqual == check');
// 7.4
// having the same number of owned properties && the same set of keys
assert.doesNotThrow(makeBlock(a.deepEqual, {a:4}, {a:4}));
assert.doesNotThrow(makeBlock(a.deepEqual, {a:4,b:"2"}, {a:4,b:"2"}));
assert.doesNotThrow(makeBlock(a.deepEqual, [4], ["4"]));
assert.throws(makeBlock(a.deepEqual, {a:4}, {a:4,b:true}), a.AssertionError);
assert.doesNotThrow(makeBlock(a.deepEqual, ["a"], {0:"a"}));
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4}, {a: 4}));
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '2'}, {a: 4, b: '2'}));
assert.doesNotThrow(makeBlock(a.deepEqual, [4], ['4']));
assert.throws(makeBlock(a.deepEqual, {a: 4}, {a: 4, b: true}),
a.AssertionError);
assert.doesNotThrow(makeBlock(a.deepEqual, ['a'], {0: 'a'}));
//(although not necessarily the same order),
assert.doesNotThrow(makeBlock(a.deepEqual, {a:4,b:"1"}, {b:"1",a:4}));
var a1 = [1,2,3];
var a2 = [1,2,3];
a1.a = "test";
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '1'}, {b: '1', a: 4}));
var a1 = [1, 2, 3];
var a2 = [1, 2, 3];
a1.a = 'test';
a1.b = true;
a2.b = true;
a2.a = "test";
assert.throws(makeBlock(a.deepEqual,
Object.keys(a1),
Object.keys(a2)),
a2.a = 'test';
assert.throws(makeBlock(a.deepEqual, Object.keys(a1), Object.keys(a2)),
a.AssertionError);
assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2));
// having an identical prototype property
var nbRoot = {
toString: function () { return this.first+' '+this.last; }
toString: function() { return this.first + ' ' + this.last; }
};
function nameBuilder (first,last) {
function nameBuilder(first, last) {
this.first = first;
this.last = last;
return this;
}
nameBuilder.prototype = nbRoot;
function nameBuilder2 (first,last) {
function nameBuilder2(first, last) {
this.first = first;
this.last = last;
return this;
@ -99,26 +101,27 @@ function nameBuilder2 (first,last) {
nameBuilder2.prototype = nbRoot;
var nb1 = new nameBuilder('Ryan', 'Dahl');
var nb2 = new nameBuilder2('Ryan','Dahl');
var nb2 = new nameBuilder2('Ryan', 'Dahl');
assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2));
nameBuilder2.prototype = Object;
nb2 = new nameBuilder2('Ryan','Dahl');
nb2 = new nameBuilder2('Ryan', 'Dahl');
assert.throws(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError);
// String literal + object blew up my implementation...
assert.throws(makeBlock(a.deepEqual, 'a', {}), a.AssertionError);
// Testing the throwing
function thrower (errorConstructor){
function thrower(errorConstructor) {
throw new errorConstructor('test');
}
var aethrow = makeBlock(thrower, a.AssertionError);
aethrow = makeBlock(thrower, a.AssertionError);
// the basic calls work
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError, 'message');
assert.throws(makeBlock(thrower, a.AssertionError),
a.AssertionError, 'message');
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError);
assert.throws(makeBlock(thrower, a.AssertionError));
@ -133,37 +136,41 @@ try {
threw = true;
assert.ok(e instanceof TypeError, 'type');
}
assert.equal(true,threw,'a.throws with an explicit error is eating extra errors', a.AssertionError);
assert.equal(true, threw,
'a.throws with an explicit error is eating extra errors',
a.AssertionError);
threw = false;
// doesNotThrow should pass through all errors
try {
a.doesNotThrow(makeBlock(thrower, TypeError), a.AssertionError);
} catch(e) {
threw = true
} catch (e) {
threw = true;
assert.ok(e instanceof TypeError);
}
assert.equal(true,threw,'a.doesNotThrow with an explicit error is eating extra errors');
assert.equal(true, threw,
'a.doesNotThrow with an explicit error is eating extra errors');
// key difference is that throwing our correct error makes an assertion error
try {
a.doesNotThrow(makeBlock(thrower, TypeError), TypeError);
} catch(e) {
threw = true
} catch (e) {
threw = true;
assert.ok(e instanceof a.AssertionError);
}
assert.equal(true,threw,'a.doesNotThrow is not catching type matching errors');
assert.equal(true, threw,
'a.doesNotThrow is not catching type matching errors');
assert.throws(function () {assert.ifError(new Error('test error'))});
assert.doesNotThrow(function(){assert.ifError(null)});
assert.doesNotThrow(function(){assert.ifError()});
assert.throws(function() {assert.ifError(new Error('test error'))});
assert.doesNotThrow(function() {assert.ifError(null)});
assert.doesNotThrow(function() {assert.ifError()});
// use a RegExp to validate error message
a.throws(makeBlock(thrower, TypeError), /test/ );
a.throws(makeBlock(thrower, TypeError), /test/);
// use a fn to validate error object
a.throws(makeBlock(thrower, TypeError), function(err) {
if (!(err instanceof TypeError) || !/test/.test(err)) {
return false;
}
if (!(err instanceof TypeError) || !/test/.test(err)) {
return false;
}
});

190
test/simple/test-buffer.js

@ -1,11 +1,11 @@
var common = require("../common");
var assert = require("assert");
var common = require('../common');
var assert = require('assert');
var Buffer = require('buffer').Buffer;
var b = Buffer(1024); // safe constructor
console.log("b.length == " + b.length);
console.log('b.length == ' + b.length);
assert.strictEqual(1024, b.length);
for (var i = 0; i < 1024; i++) {
@ -18,22 +18,22 @@ for (var i = 0; i < 1024; i++) {
}
var c = new Buffer(512);
console.log("c.length == %d", c.length);
console.log('c.length == %d', c.length);
assert.strictEqual(512, c.length);
// copy 512 bytes, from 0 to 512.
var copied = b.copy(c, 0, 0, 512);
console.log("copied " + copied + " bytes from b into c");
console.log('copied ' + copied + ' bytes from b into c');
assert.equal(512, copied);
for (var i = 0; i < c.length; i++) {
common.print('.');
assert.equal(i % 256, c[i]);
}
console.log("");
console.log('');
// try to copy 513 bytes, and hope we don't overrun c, which is only 512 long
var copied = b.copy(c, 0, 0, 513);
console.log("copied " + copied + " bytes from b into c");
console.log('copied ' + copied + ' bytes from b into c');
assert.strictEqual(512, copied);
for (var i = 0; i < c.length; i++) {
assert.equal(i % 256, c[i]);
@ -41,7 +41,7 @@ for (var i = 0; i < c.length; i++) {
// copy all of c back into b, without specifying sourceEnd
var copied = c.copy(b, 0, 0);
console.log("copied " + copied + " bytes from c back into b");
console.log('copied ' + copied + ' bytes from c back into b');
assert.strictEqual(512, copied);
for (var i = 0; i < b.length; i++) {
assert.equal(i % 256, b[i]);
@ -49,7 +49,7 @@ for (var i = 0; i < b.length; i++) {
// copy 768 bytes from b into b
var copied = b.copy(b, 0, 256, 1024);
console.log("copied " + copied + " bytes from b into c");
console.log('copied ' + copied + ' bytes from b into c');
assert.strictEqual(768, copied);
for (var i = 0; i < c.length; i++) {
assert.equal(i % 256, c[i]);
@ -60,45 +60,45 @@ var caught_error = null;
// try to copy from before the beginning of b
caught_error = null;
try {
var copied = b.copy(c, 0, 100, 10);
var copied = b.copy(c, 0, 100, 10);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('sourceEnd < sourceStart', caught_error.message);
// try to copy to before the beginning of c
caught_error = null;
try {
var copied = b.copy(c, -1, 0, 10);
var copied = b.copy(c, -1, 0, 10);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('targetStart out of bounds', caught_error.message);
// try to copy to after the end of c
caught_error = null;
try {
var copied = b.copy(c, 512, 0, 10);
var copied = b.copy(c, 512, 0, 10);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('targetStart out of bounds', caught_error.message);
// try to copy starting before the beginning of b
caught_error = null;
try {
var copied = b.copy(c, 0, -1, 1);
var copied = b.copy(c, 0, -1, 1);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('sourceStart out of bounds', caught_error.message);
// try to copy starting after the end of b
caught_error = null;
try {
var copied = b.copy(c, 0, 1024, 1025);
var copied = b.copy(c, 0, 1024, 1025);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('sourceStart out of bounds', caught_error.message);
@ -106,9 +106,9 @@ assert.strictEqual('sourceStart out of bounds', caught_error.message);
// try to copy ending after the end of b
try {
var copied = b.copy(c, 0, 1023, 1025);
var copied = b.copy(c, 0, 1023, 1025);
} catch (err) {
caught_error = err;
caught_error = err;
}
assert.strictEqual('sourceEnd out of bounds', caught_error.message);
@ -139,7 +139,9 @@ assert.equal(new Buffer('abc').toString('ascii', -100, -100), '');
assert.equal(new Buffer('abc').toString('ascii', 100, 100), '');
// try toString() with a object as a encoding
assert.equal(new Buffer('abc').toString({toString: function () {return 'ascii';}}), 'abc');
assert.equal(new Buffer('abc').toString({toString: function() {
return 'ascii';
}}), 'abc');
// testing for smart defaults and ability to pass string values as offset
var writeTest = new Buffer('abcdes');
@ -150,7 +152,7 @@ writeTest.write('e', 3, 'ascii');
writeTest.write('j', 'ascii', 4);
assert.equal(writeTest.toString(), 'nodejs');
var asciiString = "hello world";
var asciiString = 'hello world';
var offset = 100;
for (var j = 0; j < 500; j++) {
@ -162,11 +164,11 @@ for (var j = 0; j < 500; j++) {
var written = b.write(asciiString, offset, 'ascii');
assert.equal(asciiString.length, written);
var asciiSlice = b.toString('ascii', offset, offset+asciiString.length);
var asciiSlice = b.toString('ascii', offset, offset + asciiString.length);
assert.equal(asciiString, asciiSlice);
var sliceA = b.slice(offset, offset+asciiString.length);
var sliceB = b.slice(offset, offset+asciiString.length);
var sliceA = b.slice(offset, offset + asciiString.length);
var sliceB = b.slice(offset, offset + asciiString.length);
for (var i = 0; i < asciiString.length; i++) {
assert.equal(sliceA[i], sliceB[i]);
}
@ -179,7 +181,7 @@ for (var j = 0; j < 100; j++) {
var slice = b.slice(100, 150);
assert.equal(50, slice.length);
for (var i = 0; i < 50; i++) {
assert.equal(b[100+i], slice[i]);
assert.equal(b[100 + i], slice[i]);
}
}
@ -197,12 +199,12 @@ assert.equal(slice, testValue);
// Test triple slice
var a = new Buffer(8);
for (var i = 0; i < 8; i++) a[i] = i;
var b = a.slice(4,8);
var b = a.slice(4, 8);
assert.equal(4, b[0]);
assert.equal(5, b[1]);
assert.equal(6, b[2]);
assert.equal(7, b[3]);
var c = b.slice(2 , 4);
var c = b.slice(2, 4);
assert.equal(6, c[0]);
assert.equal(7, c[1]);
@ -214,11 +216,11 @@ assert.equal(d[1], 42);
assert.equal(d[2], 255);
var e = new Buffer('über');
console.error("uber: '%s'", e.toString());
console.error('uber: \'%s\'', e.toString());
assert.deepEqual(e, new Buffer([195, 188, 98, 101, 114]));
var f = new Buffer('über', 'ascii');
console.error("f.length: %d (should be 4)", f.length);
console.error('f.length: %d (should be 4)', f.length);
assert.deepEqual(f, new Buffer([252, 98, 101, 114]));
@ -227,8 +229,17 @@ assert.deepEqual(f, new Buffer([252, 98, 101, 114]));
//
assert.equal('TWFu', (new Buffer('Man')).toString('base64'));
// big example
var quote = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
var expected = "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
var quote = 'Man is distinguished, not only by his reason, but by this ' +
'singular passion from other animals, which is a lust ' +
'of the mind, that by a perseverance of delight in the continued ' +
'and indefatigable generation of knowledge, exceeds the short ' +
'vehemence of any carnal pleasure.';
var expected = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24s' +
'IGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltY' +
'WxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZX' +
'JzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmR' +
'lZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo' +
'ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=';
assert.equal(expected, (new Buffer(quote)).toString('base64'));
@ -238,12 +249,12 @@ assert.equal(quote.length, bytesWritten);
assert.equal(quote, b.toString('ascii', 0, quote.length));
// check that the base64 decoder ignores whitespace
var expectedWhite = expected.slice(0, 60) + " \n" +
expected.slice(60, 120) + " \n" +
expected.slice(120, 180) + " \n" +
expected.slice(180, 240) + " \n" +
expected.slice(240, 300) + "\n" +
expected.slice(300, 360) + "\n";
var expectedWhite = expected.slice(0, 60) + ' \n' +
expected.slice(60, 120) + ' \n' +
expected.slice(120, 180) + ' \n' +
expected.slice(180, 240) + ' \n' +
expected.slice(240, 300) + '\n' +
expected.slice(300, 360) + '\n';
b = new Buffer(1024);
bytesWritten = b.write(expectedWhite, 0, 'base64');
assert.equal(quote.length, bytesWritten);
@ -256,12 +267,12 @@ assert.equal(quote.length, b.length);
assert.equal(quote, b.toString('ascii', 0, quote.length));
// check that the base64 decoder ignores illegal chars
var expectedIllegal = expected.slice(0, 60) + " \x80" +
expected.slice(60, 120) + " \xff" +
expected.slice(120, 180) + " \x00" +
expected.slice(180, 240) + " \x98" +
expected.slice(240, 300) + "\x03" +
expected.slice(300, 360)
var expectedIllegal = expected.slice(0, 60) + ' \x80' +
expected.slice(60, 120) + ' \xff' +
expected.slice(120, 180) + ' \x00' +
expected.slice(180, 240) + ' \x98' +
expected.slice(240, 300) + '\x03' +
expected.slice(300, 360);
b = new Buffer(expectedIllegal, 'base64');
assert.equal(quote.length, b.length);
assert.equal(quote, b.toString('ascii', 0, quote.length));
@ -280,17 +291,28 @@ assert.equal(new Buffer('KioqKioq', 'base64').toString(), '******');
assert.equal(new Buffer('KioqKioqKg==', 'base64').toString(), '*******');
assert.equal(new Buffer('KioqKioqKio=', 'base64').toString(), '********');
assert.equal(new Buffer('KioqKioqKioq', 'base64').toString(), '*********');
assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(), '**********');
assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(), '***********');
assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(), '************');
assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(), '*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(), '**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(), '***************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKg==', 'base64').toString(), '****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKio=', 'base64').toString(), '*****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioq', 'base64').toString(), '******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg==', 'base64').toString(), '*******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio=', 'base64').toString(), '********************');
assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(),
'**********');
assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(),
'***********');
assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(),
'************');
assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(),
'*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(),
'**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(),
'***************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKg==', 'base64').toString(),
'****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKio=', 'base64').toString(),
'*****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioq', 'base64').toString(),
'******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg==', 'base64').toString(),
'*******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio=', 'base64').toString(),
'********************');
// no padding, not a multiple of 4
assert.equal(new Buffer('Kg', 'base64').toString(), '*');
@ -301,20 +323,32 @@ assert.equal(new Buffer('KioqKioqKg', 'base64').toString(), '*******');
assert.equal(new Buffer('KioqKioqKio', 'base64').toString(), '********');
assert.equal(new Buffer('KioqKioqKioqKg', 'base64').toString(), '**********');
assert.equal(new Buffer('KioqKioqKioqKio', 'base64').toString(), '***********');
assert.equal(new Buffer('KioqKioqKioqKioqKg', 'base64').toString(), '*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio', 'base64').toString(), '**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKg', 'base64').toString(), '****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKio', 'base64').toString(), '*****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg', 'base64').toString(), '*******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(), '********************');
assert.equal(new Buffer('KioqKioqKioqKioqKg', 'base64').toString(),
'*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio', 'base64').toString(),
'**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKg', 'base64').toString(),
'****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKio', 'base64').toString(),
'*****************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg', 'base64').toString(),
'*******************');
assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(),
'********************');
// handle padding graciously, multiple-of-4 or not
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', 'base64').length, 32);
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', 'base64').length, 32);
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', 'base64').length, 32);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', 'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', 'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', 'base64').length, 31);
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==',
'base64').length, 32);
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=',
'base64').length, 32);
assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw',
'base64').length, 32);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==',
'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=',
'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg',
'base64').length, 31);
// This string encodes single '.' character in UTF-16
var dot = new Buffer('//4uAA==', 'base64');
@ -327,15 +361,15 @@ assert.equal(dot.toString('base64'), '//4uAA==');
// Creating buffers larger than pool size.
var l = Buffer.poolSize + 5;
var s = ""
var s = '';
for (i = 0; i < l; i++) {
s += "h";
s += 'h';
}
var b = new Buffer(s);
for (i = 0; i < l; i++) {
assert.equal("h".charCodeAt(0), b[i]);
assert.equal('h'.charCodeAt(0), b[i]);
}
var sb = b.toString();
@ -344,15 +378,15 @@ assert.equal(sb, s);
// Single argument slice
b = new Buffer("abcde");
assert.equal("bcde", b.slice(1).toString());
b = new Buffer('abcde');
assert.equal('bcde', b.slice(1).toString());
// byte length
assert.equal(14, Buffer.byteLength("Il était tué"));
assert.equal(14, Buffer.byteLength("Il était tué", "utf8"));
assert.equal(12, Buffer.byteLength("Il était tué", "ascii"));
assert.equal(12, Buffer.byteLength("Il était tué", "binary"));
assert.equal(14, Buffer.byteLength('Il était tué'));
assert.equal(14, Buffer.byteLength('Il était tué', 'utf8'));
assert.equal(12, Buffer.byteLength('Il était tué', 'ascii'));
assert.equal(12, Buffer.byteLength('Il était tué', 'binary'));
// slice(0,0).length === 0
assert.equal(0, Buffer('hello').slice(0, 0).length)
assert.equal(0, Buffer('hello').slice(0, 0).length);

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

@ -1,39 +1,39 @@
var common = require('../common');
var assert = require('assert');
var dns = require("dns");
var dns = require('dns');
// Try resolution without callback
dns.getHostByName('localhost', function (error, result) {
console.dir(result);
assert.deepEqual(['127.0.0.1'], result);
dns.getHostByName('localhost', function(error, result) {
console.dir(result);
assert.deepEqual(['127.0.0.1'], result);
});
dns.getHostByName('127.0.0.1', function (error, result) {
console.dir(result);
assert.deepEqual(['127.0.0.1'], result);
dns.getHostByName('127.0.0.1', function(error, result) {
console.dir(result);
assert.deepEqual(['127.0.0.1'], result);
});
dns.lookup(null, function (error, result, addressType) {
assert.equal(null, result);
assert.equal(4, addressType);
dns.lookup(null, function(error, result, addressType) {
assert.equal(null, result);
assert.equal(4, addressType);
});
dns.lookup('127.0.0.1', function (error, result, addressType) {
assert.equal('127.0.0.1', result);
assert.equal(4, addressType);
dns.lookup('127.0.0.1', function(error, result, addressType) {
assert.equal('127.0.0.1', result);
assert.equal(4, addressType);
});
dns.lookup('::1', function (error, result, addressType) {
assert.equal('::1', result);
assert.equal(6, addressType);
dns.lookup('::1', function(error, result, addressType) {
assert.equal('::1', result);
assert.equal(6, addressType);
});
dns.lookup('ipv6.google.com', function (error, result, addressType) {
if (error) throw error;
console.dir(arguments);
//assert.equal('string', typeof result);
assert.equal(6, addressType);
dns.lookup('ipv6.google.com', function(error, result, addressType) {
if (error) throw error;
console.dir(arguments);
//assert.equal('string', typeof result);
assert.equal(6, addressType);
});

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

@ -5,18 +5,18 @@ var spawn = require('child_process').spawn;
var pwd_called = false;
function pwd (callback) {
var output = "";
var child = spawn("pwd");
function pwd(callback) {
var output = '';
var child = spawn('pwd');
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (s) {
console.log("stdout: " + JSON.stringify(s));
child.stdout.addListener('data', function(s) {
console.log('stdout: ' + JSON.stringify(s));
output += s;
});
child.addListener("exit", function (c) {
console.log("exit: " + c);
child.addListener('exit', function(c) {
console.log('exit: ' + c);
assert.equal(0, c);
callback(output);
pwd_called = true;
@ -24,12 +24,12 @@ function pwd (callback) {
}
pwd(function (result) {
pwd(function(result) {
console.dir(result);
assert.equal(true, result.length > 1);
assert.equal("\n", result[result.length-1]);
assert.equal('\n', result[result.length - 1]);
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(true, pwd_called);
});

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

@ -1,24 +1,24 @@
var common = require("../common");
var common = require('../common');
var assert = require('assert');
var assert = require('assert');
var spawn = require('child_process').spawn;
var path = require('path');
var fs = require('fs');
var spawn = require('child_process').spawn;
var path = require('path');
var fs = require('fs');
function fixtPath(p) {
return path.join(common.fixturesDir, p);
}
var expected = "hello world";
var expected = 'hello world';
// Test the equivalent of:
// $ /bin/echo "hello world" > hello.txt
var helloPath = fixtPath("hello.txt");
// $ /bin/echo 'hello world' > hello.txt
var helloPath = fixtPath('hello.txt');
function test1(next) {
console.log("Test 1...");
fs.open(helloPath, 'w', 400, function (err, fd) {
console.log('Test 1...');
fs.open(helloPath, 'w', 400, function(err, fd) {
if (err) throw err;
var child = spawn('/bin/echo', [expected], {customFds: [-1, fd]});
@ -26,14 +26,14 @@ function test1(next) {
assert.equal(child.stdout, null);
assert.notEqual(child.stderr, null);
child.addListener('exit', function (err) {
child.addListener('exit', function(err) {
if (err) throw err;
fs.close(fd, function (error) {
fs.close(fd, function(error) {
if (error) throw error;
fs.readFile(helloPath, function (err, data) {
fs.readFile(helloPath, function(err, data) {
if (err) throw err;
assert.equal(data.toString(), expected + "\n");
assert.equal(data.toString(), expected + '\n');
console.log(' File was written.');
next(test3);
});
@ -45,22 +45,22 @@ function test1(next) {
// Test the equivalent of:
// $ node ../fixture/stdio-filter.js < hello.txt
function test2(next) {
console.log("Test 2...");
fs.open(helloPath, 'r', undefined, function (err, fd) {
var child = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a']
, {customFds: [fd, -1, -1]});
console.log('Test 2...');
fs.open(helloPath, 'r', undefined, function(err, fd) {
var child = spawn(process.argv[0],
[fixtPath('stdio-filter.js'), 'o', 'a'],
{customFds: [fd, -1, -1]});
assert.equal(child.stdin, null);
var actualData = '';
child.stdout.addListener('data', function (data) {
child.stdout.addListener('data', function(data) {
actualData += data.toString();
});
child.addListener('exit', function (code) {
child.addListener('exit', function(code) {
if (err) throw err;
assert.equal(actualData, "hella warld\n");
console.log(" File was filtered successfully");
fs.close(fd, function () {
assert.equal(actualData, 'hella warld\n');
console.log(' File was filtered successfully');
fs.close(fd, function() {
next(test3);
});
});
@ -68,24 +68,23 @@ function test2(next) {
}
// 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) {
console.log("Test 3...");
var filter = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a']);
console.log('Test 3...');
var filter = spawn(process.argv[0], [fixtPath('stdio-filter.js'), 'o', 'a']);
var echo = spawn('/bin/echo', [expected], {customFds: [-1, filter.fds[0]]});
var actualData = '';
filter.stdout.addListener('data', function(data) {
console.log(" Got data --> " + data);
console.log(' Got data --> ' + data);
actualData += data;
});
filter.addListener('exit', function(code) {
if (code) throw "Return code was " + code;
assert.equal(actualData, "hella warld\n");
console.log(" Talked to another process successfully");
if (code) throw 'Return code was ' + code;
assert.equal(actualData, 'hella warld\n');
console.log(' Talked to another process successfully');
});
echo.addListener('exit', function(code) {
if (code) throw "Return code was " + code;
if (code) throw 'Return code was ' + code;
filter.stdin.end();
fs.unlinkSync(helloPath);
});

33
test/simple/test-child-process-cwd.js

@ -6,45 +6,46 @@ var path = require('path');
var returns = 0;
/*
Spawns 'pwd' with given options, then test
Spawns 'pwd' with given options, then test
- whether the exit code equals forCode,
- optionally whether the stdout result (after removing traling whitespace) matches forData
- optionally whether the stdout result matches forData
(after removing traling whitespace)
*/
function testCwd(options, forCode, forData) {
var data = "";
var data = '';
var child = spawn('pwd', [], options);
child.stdout.setEncoding('utf8');
child.stdout.addListener('data', function(chunk) {
data += chunk;
});
child.addListener('exit', function(code, signal) {
forData && assert.strictEqual(forData, data.replace(/[\s\r\n]+$/, ''))
forData && assert.strictEqual(forData, data.replace(/[\s\r\n]+$/, ''));
assert.strictEqual(forCode, code);
returns--;
});
returns++;
}
// Assume these exist, and 'pwd' gives us the right directory back
testCwd( { cwd: '/dev' }, 0, '/dev' );
testCwd( { cwd: '/' }, 0, '/' );
testCwd({cwd: '/dev'}, 0, '/dev');
testCwd({cwd: '/'}, 0, '/');
// Assume this doesn't exist, we expect exitcode=127
testCwd( { cwd: 'does-not-exist' }, 127 );
testCwd({cwd: 'does-not-exist'}, 127);
// Spawn() shouldn't try to chdir() so this should just work
testCwd( undefined, 0 );
testCwd( { }, 0 );
testCwd( { cwd: '' }, 0 );
testCwd( { cwd: undefined }, 0 );
testCwd( { cwd: null }, 0 );
testCwd(undefined, 0);
testCwd({}, 0);
testCwd({cwd: ''}, 0);
testCwd({cwd: undefined}, 0);
testCwd({cwd: null}, 0);
// Check whether all tests actually returned
assert.notEqual(0, returns);
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(0, returns);
});

50
test/simple/test-child-process-deprecated-api.js

@ -1,33 +1,35 @@
var common = require("../common");
var assert = common.assert;
var spawn = require('child_process').spawn;
var path = require('path');
var fs = require('fs');
var exits = 0;
// Test `env` parameter for child_process.spawn(path, args, env, customFds) deprecated api
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var path = require('path');
var fs = require('fs');
var exits = 0;
// Test `env` parameter
// for child_process.spawn(path, args, env, customFds) deprecated api
(function() {
var response = "";
var child = spawn('/usr/bin/env', [], {'HELLO' : 'WORLD'});
var response = '';
var child = spawn('/usr/bin/env', [], {'HELLO': 'WORLD'});
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (chunk) {
child.stdout.addListener('data', function(chunk) {
response += chunk;
});
process.addListener('exit', function () {
assert.ok(response.indexOf('HELLO=WORLD') >= 0);
exits++;
process.addListener('exit', function() {
assert.ok(response.indexOf('HELLO=WORLD') >= 0);
exits++;
});
})();
// Test `customFds` parameter for child_process.spawn(path, args, env, customFds) deprecated api
// Test `customFds` parameter
// for child_process.spawn(path, args, env, customFds) deprecated api
(function() {
var expected = "hello world";
var helloPath = path.join(common.fixturesDir, "hello.txt");
var expected = 'hello world';
var helloPath = path.join(common.fixturesDir, 'hello.txt');
fs.open(helloPath, 'w', 400, function (err, fd) {
fs.open(helloPath, 'w', 400, function(err, fd) {
if (err) throw err;
var child = spawn('/bin/echo', [expected], undefined, [-1, fd]);
@ -36,16 +38,16 @@ var exits = 0;
assert.equal(child.stdout, null);
assert.notEqual(child.stderr, null);
child.addListener('exit', function (err) {
child.addListener('exit', function(err) {
if (err) throw err;
fs.close(fd, function (error) {
if (error) throw error;
fs.close(fd, function(err) {
if (err) throw err;
fs.readFile(helloPath, function (err, data) {
fs.readFile(helloPath, function(err, data) {
if (err) throw err;
assert.equal(data.toString(), expected + "\n");
assert.equal(data.toString(), expected + '\n');
exits++;
});
});
@ -54,6 +56,6 @@ var exits = 0;
})();
// Check if all child processes exited
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(2, exits);
});

27
test/simple/test-child-process-double-pipe.js

@ -1,14 +1,13 @@
var assert = require('assert'),
util = require('util'),
var assert = require('assert'),
util = require('util'),
spawn = require('child_process').spawn;
// We're trying to reproduce:
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/
var
echo = spawn('echo', ['hello\nnode\nand\nworld\n']),
grep = spawn('grep', ['o']),
sed = spawn('sed', ['s/o/O/']);
var echo = spawn('echo', ['hello\nnode\nand\nworld\n']),
grep = spawn('grep', ['o']),
sed = spawn('sed', ['s/o/O/']);
/*
* grep and sed hang if the spawn function leaks file descriptors to child
@ -23,36 +22,36 @@ var
// pipe echo | grep
echo.stdout.on('data', function (data) {
echo.stdout.on('data', function(data) {
if (!grep.stdin.write(data)) {
echo.stdout.pause();
}
});
grep.stdin.on('drain', function (data) {
grep.stdin.on('drain', function(data) {
echo.stdout.resume();
});
// propagate end from echo to grep
echo.stdout.on('end', function (code) {
echo.stdout.on('end', function(code) {
grep.stdin.end();
});
// pipe grep | sed
grep.stdout.on('data', function (data) {
grep.stdout.on('data', function(data) {
if (!sed.stdin.write(data)) {
grep.stdout.pause();
}
});
sed.stdin.on('drain', function (data) {
sed.stdin.on('drain', function(data) {
grep.stdout.resume();
});
// propagate end from grep to sed
grep.stdout.on('end', function (code) {
grep.stdout.on('end', function(code) {
sed.stdin.end();
});
@ -61,11 +60,11 @@ grep.stdout.on('end', function (code) {
var result = '';
// print sed's output
sed.stdout.on('data', function (data) {
sed.stdout.on('data', function(data) {
result += data.toString('utf8', 0, data.length);
util.print(data);
});
sed.stdout.on('end', function (code) {
sed.stdout.on('end', function(code) {
assert.equal(result, 'hellO\nnOde\nwOrld\n');
});

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

@ -1,18 +1,18 @@
var common = require("../common");
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var child = spawn('/usr/bin/env', [], {env: {'HELLO' : 'WORLD'}});
var child = spawn('/usr/bin/env', [], {env: {'HELLO': 'WORLD'}});
var response = "";
var response = '';
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (chunk) {
console.log("stdout: " + chunk);
child.stdout.addListener('data', function(chunk) {
console.log('stdout: ' + chunk);
response += chunk;
});
process.addListener('exit', function () {
assert.ok(response.indexOf('HELLO=WORLD') >= 0);
process.addListener('exit', function() {
assert.ok(response.indexOf('HELLO=WORLD') >= 0);
});

6
test/simple/test-child-process-exec-cwd.js

@ -1,11 +1,11 @@
require('../common');
var assert = require('assert');
var exec = require('child_process').exec;
var exec = require('child_process').exec;
var success_count = 0;
var error_count = 0;
var child = exec('pwd', {cwd: "/dev"}, function (err, stdout, stderr) {
var child = exec('pwd', {cwd: '/dev'}, function(err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
@ -18,7 +18,7 @@ var child = exec('pwd', {cwd: "/dev"}, function (err, stdout, stderr) {
}
});
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(1, success_count);
assert.equal(0, error_count);
});

33
test/simple/test-child-process-exec-env.js

@ -1,30 +1,31 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var exec = require('child_process').exec;
var success_count = 0;
var error_count = 0;
var response = "";
var response = '';
var child = exec('/usr/bin/env', { env: {'HELLO' : 'WORLD'}}, function (err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
assert.equal(true, stdout != "");
}
});
var child = exec('/usr/bin/env', {env: {'HELLO': 'WORLD'}},
function(err, stdout, stderr) {
if (err) {
error_count++;
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
assert.equal(true, stdout != '');
}
});
child.stdout.setEncoding('utf8');
child.stdout.addListener('data', function (chunk) {
child.stdout.addListener('data', function(chunk) {
response += chunk;
});
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(1, success_count);
assert.equal(0, error_count);
assert.ok(response.indexOf('HELLO=WORLD') >= 0);

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

@ -5,7 +5,7 @@ var path = require('path');
var exits = 0;
var exitScript = path.join(common.fixturesDir, 'exit.js')
var exitScript = path.join(common.fixturesDir, 'exit.js');
var exitChild = spawn(process.argv[0], [exitScript, 23]);
exitChild.addListener('exit', function(code, signal) {
assert.strictEqual(code, 23);
@ -16,7 +16,8 @@ exitChild.addListener('exit', function(code, signal) {
var errorScript = path.join(common.fixturesDir, 'child_process_should_emit_error.js')
var errorScript = path.join(common.fixturesDir,
'child_process_should_emit_error.js');
var errorChild = spawn(process.argv[0], [errorScript]);
errorChild.addListener('exit', function(code, signal) {
assert.ok(code !== 0);
@ -26,6 +27,6 @@ errorChild.addListener('exit', function(code, signal) {
});
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(2, exits);
});

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

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

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

@ -8,33 +8,33 @@ var termSignal;
var gotStdoutEOF = false;
var gotStderrEOF = false;
var cat = spawn("cat");
var cat = spawn('cat');
cat.stdout.addListener("data", function (chunk) {
cat.stdout.addListener('data', function(chunk) {
assert.ok(false);
});
cat.stdout.addListener("end", function () {
cat.stdout.addListener('end', function() {
gotStdoutEOF = true;
});
cat.stderr.addListener("data", function (chunk) {
cat.stderr.addListener('data', function(chunk) {
assert.ok(false);
});
cat.stderr.addListener("end", function () {
cat.stderr.addListener('end', function() {
gotStderrEOF = true;
});
cat.addListener("exit", function (code, signal) {
cat.addListener('exit', function(code, signal) {
exitCode = code;
termSignal = signal;
});
cat.kill();
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.strictEqual(exitCode, null);
assert.strictEqual(termSignal, 'SIGTERM');
assert.ok(gotStdoutEOF);

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

@ -3,47 +3,47 @@ var assert = require('assert');
var spawn = require('child_process').spawn;
var cat = spawn("cat");
cat.stdin.write("hello");
cat.stdin.write(" ");
cat.stdin.write("world");
var cat = spawn('cat');
cat.stdin.write('hello');
cat.stdin.write(' ');
cat.stdin.write('world');
cat.stdin.end();
var response = "";
var response = '';
var exitStatus = -1;
var gotStdoutEOF = false;
cat.stdout.setEncoding('utf8');
cat.stdout.addListener("data", function (chunk) {
console.log("stdout: " + chunk);
cat.stdout.addListener('data', function(chunk) {
console.log('stdout: ' + chunk);
response += chunk;
});
cat.stdout.addListener('end', function () {
cat.stdout.addListener('end', function() {
gotStdoutEOF = true;
});
var gotStderrEOF = false;
cat.stderr.addListener("data", function (chunk) {
cat.stderr.addListener('data', function(chunk) {
// shouldn't get any stderr output
assert.ok(false);
});
cat.stderr.addListener("end", function (chunk) {
cat.stderr.addListener('end', function(chunk) {
gotStderrEOF = true;
});
cat.addListener("exit", function (status) {
console.log("exit event");
cat.addListener('exit', function(status) {
console.log('exit event');
exitStatus = status;
assert.equal("hello world", response);
assert.equal('hello world', response);
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(0, exitStatus);
assert.equal("hello world", response);
assert.equal('hello world', response);
});

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

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

24
test/simple/test-cli-eval.js

@ -10,19 +10,19 @@ if (module.parent) {
}
// assert that the result of the final expression is written to stdout
child.exec(nodejs + ' --eval \'1337; 42\'',
function(err, stdout, stderr) {
assert.equal(parseInt(stdout), 42);
});
child.exec(nodejs + ' --eval "1337; 42"',
function(err, stdout, stderr) {
assert.equal(parseInt(stdout), 42);
});
// assert that module loading works
child.exec(nodejs + ' --eval \'require("' + __filename + '")\'',
function(status, stdout, stderr) {
assert.equal(status.code, 42);
});
child.exec(nodejs + ' --eval "require(\'' + __filename + '\')"',
function(status, stdout, stderr) {
assert.equal(status.code, 42);
});
// module path resolve bug, regression test
child.exec(nodejs + ' --eval \'require("./test/simple/test-cli-eval.js")\'',
function(status, stdout, stderr) {
assert.equal(status.code, 42);
});
child.exec(nodejs + ' --eval "require(\'./test/simple/test-cli-eval.js\')"',
function(status, stdout, stderr) {
assert.equal(status.code, 42);
});

4
test/simple/test-console.js

@ -1,10 +1,10 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var stdout_write = global.process.stdout.write;
var strings = [];
global.process.stdout.write = function(string) {
strings.push(string);
strings.push(string);
};
console.log('foo');

102
test/simple/test-crypto.js

@ -4,7 +4,7 @@ var assert = require('assert');
try {
var crypto = require('crypto');
} catch (e) {
console.log("Not compiled with OPENSSL support.");
console.log('Not compiled with OPENSSL support.');
process.exit();
}
@ -12,84 +12,110 @@ var fs = require('fs');
var path = require('path');
// Test Certificates
var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem", 'ascii');
var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem", 'ascii');
var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem", 'ascii');
var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem', 'ascii');
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii');
try{
var credentials = crypto.createCredentials({key:keyPem, cert:certPem, ca:caPem});
try {
var credentials = crypto.createCredentials(
{key: keyPem,
cert: certPem,
ca: caPem});
} catch (e) {
console.log("Not compiled with OPENSSL support.");
console.log('Not compiled with OPENSSL support.');
process.exit();
}
// Test HMAC
//var h1 = (new crypto.Hmac).init("sha1", "Node").update("some data").update("to hmac").digest("hex");
var h1 = crypto.createHmac("sha1", "Node").update("some data").update("to hmac").digest("hex");
assert.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', "test HMAC");
var h1 = crypto.createHmac('sha1', 'Node')
.update('some data')
.update('to hmac')
.digest('hex');
assert.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC');
// Test hashing
var a0 = crypto.createHash("sha1").update("Test123").digest("hex");
var a1 = crypto.createHash("md5").update("Test123").digest("binary");
var a2 = crypto.createHash("sha256").update("Test123").digest("base64");
var a3 = crypto.createHash("sha512").update("Test123").digest(); // binary
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');
var a1 = crypto.createHash('md5').update('Test123').digest('binary');
var a2 = crypto.createHash('sha256').update('Test123').digest('base64');
var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary
assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', 'Test MD5 as binary');
assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', 'Test SHA256 as base64');
assert.equal(a3, '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4\u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', 'Test SHA512 as assumed binary');
assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' +
'\u00bd\u008c', 'Test MD5 as binary');
assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=',
'Test SHA256 as base64');
assert.equal(a3, '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4' +
'\u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2' +
'\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' +
'\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' +
'\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'',
'Test SHA512 as assumed binary');
// Test multiple updates to same hash
var h1 = crypto.createHash("sha1").update("Test123").digest("hex");
var h2 = crypto.createHash("sha1").update("Test").update("123").digest("hex");
assert.equal(h1, h2, "multipled updates");
var h1 = crypto.createHash('sha1').update('Test123').digest('hex');
var h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex');
assert.equal(h1, h2, 'multipled updates');
// Test hashing for binary files
var fn = path.join(common.fixturesDir, 'sample.png');
var sha1Hash = crypto.createHash('sha1');
var fileStream = fs.createReadStream(fn);
fileStream.addListener('data', function(data){
fileStream.addListener('data', function(data) {
sha1Hash.update(data);
});
fileStream.addListener('close', function(){
assert.equal(sha1Hash.digest('hex'), '22723e553129a336ad96e10f6aecdf0f45e4149e', 'Test SHA1 of sample.png');
fileStream.addListener('close', function() {
assert.equal(sha1Hash.digest('hex'),
'22723e553129a336ad96e10f6aecdf0f45e4149e',
'Test SHA1 of sample.png');
});
// Test signing and verifying
var s1 = crypto.createSign("RSA-SHA1").update("Test123").sign(keyPem, "base64");
var verified = crypto.createVerify("RSA-SHA1").update("Test").update("123").verify(certPem, s1, "base64");
assert.ok(verified, "sign and verify (base 64)");
var s2 = crypto.createSign("RSA-SHA256").update("Test123").sign(keyPem); // binary
var verified = crypto.createVerify("RSA-SHA256").update("Test").update("123").verify(certPem, s2); // binary
assert.ok(verified, "sign and verify (binary)");
var s1 = crypto.createSign('RSA-SHA1')
.update('Test123')
.sign(keyPem, 'base64');
var verified = crypto.createVerify('RSA-SHA1')
.update('Test')
.update('123')
.verify(certPem, s1, 'base64');
assert.ok(verified, 'sign and verify (base 64)');
var s2 = crypto.createSign('RSA-SHA256')
.update('Test123')
.sign(keyPem); // binary
var verified = crypto.createVerify('RSA-SHA256')
.update('Test')
.update('123')
.verify(certPem, s2); // binary
assert.ok(verified, 'sign and verify (binary)');
// Test encryption and decryption
var plaintext = "Keep this a secret? No! Tell everyone about node.js!";
var cipher = crypto.createCipher("aes192", "MySecretKey123");
var plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
var cipher = crypto.createCipher('aes192', 'MySecretKey123');
// encrypt plaintext which is in utf8 format to a ciphertext which will be in hex
// encrypt plaintext which is in utf8 format
// to a ciphertext which will be in hex
var ciph = cipher.update(plaintext, 'utf8', 'hex');
// Only use binary or hex, not base64.
ciph += cipher.final('hex');
var decipher = crypto.createDecipher("aes192", "MySecretKey123");
var decipher = crypto.createDecipher('aes192', 'MySecretKey123');
var txt = decipher.update(ciph, 'hex', 'utf8');
txt += decipher.final('utf8');
assert.equal(txt, plaintext, "encryption and decryption");
assert.equal(txt, plaintext, 'encryption and decryption');
// Test encyrption and decryption with explicit key and iv
var encryption_key = '0123456789abcd0123456789';
var iv = '12345678';
var cipher = crypto.createCipheriv("des-ede3-cbc", encryption_key, iv);
var cipher = crypto.createCipheriv('des-ede3-cbc', encryption_key, iv);
var ciph = cipher.update(plaintext, 'utf8', 'hex');
ciph += cipher.final('hex');
var decipher = crypto.createDecipheriv("des-ede3-cbc",encryption_key,iv);
var decipher = crypto.createDecipheriv('des-ede3-cbc', encryption_key, iv);
var txt = decipher.update(ciph, 'hex', 'utf8');
txt += decipher.final('utf8');
assert.equal(txt, plaintext, "encryption and decryption with key and iv");
assert.equal(txt, plaintext, 'encryption and decryption with key and iv');

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

@ -2,12 +2,12 @@ var common = require('../common');
var assert = require('assert');
var a;
setTimeout(function () {
a = require("../fixtures/a");
setTimeout(function() {
a = require('../fixtures/a');
}, 50);
process.addListener("exit", function () {
assert.equal(true, "A" in a);
assert.equal("A", a.A());
assert.equal("D", a.D());
process.addListener('exit', function() {
assert.equal(true, 'A' in a);
assert.equal('A', a.A());
assert.equal('D', a.D());
});

51
test/simple/test-dgram-multicast.js

@ -1,51 +1,52 @@
var common = require('../common');
var assert = require('assert');
var dgram = require("dgram"),
var dgram = require('dgram'),
util = require('util'),
assert = require('assert'),
Buffer = require("buffer").Buffer;
Buffer = require('buffer').Buffer;
var LOCAL_BROADCAST_HOST = '224.0.0.1';
var sendMessages = [
new Buffer("First message to send"),
new Buffer("Second message to send"),
new Buffer("Third message to send"),
new Buffer("Fourth message to send")
new Buffer('First message to send'),
new Buffer('Second message to send'),
new Buffer('Third message to send'),
new Buffer('Fourth message to send')
];
var listenSockets = [];
var sendSocket = dgram.createSocket('udp4')
var sendSocket = dgram.createSocket('udp4');
sendSocket.on('close', function () {
sendSocket.on('close', function() {
console.error('sendSocket closed');
})
});
sendSocket.setBroadcast(true);
var i = 0;
sendSocket.sendNext = function () {
sendSocket.sendNext = function() {
var buf = sendMessages[i++];
if (!buf) {
try { sendSocket.close(); }catch(e){}
try { sendSocket.close(); } catch (e) {}
return;
}
sendSocket.send(buf, 0, buf.length, common.PORT, LOCAL_BROADCAST_HOST, function (err) {
if (err) throw err;
console.error('sent %s to %s', util.inspect(buf.toString()),
LOCAL_BROADCAST_HOST+common.PORT);
process.nextTick(sendSocket.sendNext);
});
sendSocket.send(buf, 0, buf.length,
common.PORT, LOCAL_BROADCAST_HOST, function(err) {
if (err) throw err;
console.error('sent %s to %s', util.inspect(buf.toString()),
LOCAL_BROADCAST_HOST + common.PORT);
process.nextTick(sendSocket.sendNext);
});
};
var listener_count = 0;
function mkListener() {
var receivedMessages = [];
var listenSocket = dgram.createSocket('udp4')
var listenSocket = dgram.createSocket('udp4');
listenSocket.on('message', function(buf, rinfo) {
console.error('received %s from %j', util.inspect(buf.toString()), rinfo);
@ -54,29 +55,29 @@ function mkListener() {
if (receivedMessages.length == sendMessages.length) {
listenSocket.close();
}
})
});
listenSocket.on('close', function () {
listenSocket.on('close', function() {
console.error('listenSocket closed -- checking received messages');
var count = 0;
receivedMessages.forEach(function(buf){
for (var i=0; i<sendMessages.length; ++i) {
receivedMessages.forEach(function(buf) {
for (var i = 0; i < sendMessages.length; ++i) {
if (buf.toString() === sendMessages[i].toString()) {
count++;
break;
}
}
});
console.error("count %d", count);
console.error('count %d', count);
//assert.strictEqual(count, sendMessages.length);
})
});
listenSocket.on('listening', function() {
listenSockets.push(listenSocket);
if (listenSockets.length == 3) {
sendSocket.sendNext();
}
})
});
listenSocket.bind(common.PORT);
}

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

@ -1,73 +1,77 @@
var common = require('../common');
var assert = require('assert');
var Buffer = require('buffer').Buffer;
var dgram = require("dgram");
var dgram = require('dgram');
var tests_run = 0;
function pingPongTest (port, host) {
function pingPongTest(port, host) {
var callbacks = 0;
var N = 500;
var count = 0;
var sent_final_ping = false;
var server = dgram.createSocket("udp4", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
var server = dgram.createSocket('udp4', function(msg, rinfo) {
console.log('server got: ' + msg +
' from ' + rinfo.address + ':' + rinfo.port);
if (/PING/.exec(msg)) {
var buf = new Buffer(4);
buf.write('PONG');
server.send(buf, 0, buf.length, rinfo.port, rinfo.address, function (err, sent) {
callbacks++;
});
server.send(buf, 0, buf.length,
rinfo.port, rinfo.address,
function(err, sent) {
callbacks++;
});
}
});
server.on("error", function (e) {
server.on('error', function(e) {
throw e;
});
server.on("listening", function () {
console.log("server listening on " + port + " " + host);
server.on('listening', function() {
console.log('server listening on ' + port + ' ' + host);
var buf = new Buffer('PING'),
client = dgram.createSocket("udp4");
var buf = new Buffer('PING'),
client = dgram.createSocket('udp4');
client.addListener("message", function (msg, rinfo) {
console.log("client got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
assert.equal("PONG", msg.toString('ascii'));
client.addListener('message', function(msg, rinfo) {
console.log('client got: ' + msg +
' from ' + rinfo.address + ':' + rinfo.port);
assert.equal('PONG', msg.toString('ascii'));
count += 1;
if (count < N) {
client.send(buf, 0, buf.length, port, "localhost");
client.send(buf, 0, buf.length, port, 'localhost');
} else {
sent_final_ping = true;
client.send(buf, 0, buf.length, port, "localhost");
client.send(buf, 0, buf.length, port, 'localhost');
process.nextTick(function() {
client.close();
});
}
});
client.on("close", function () {
client.on('close', function() {
console.log('client has closed, closing server');
assert.equal(N, count);
tests_run += 1;
server.close();
assert.equal(N-1, callbacks);
assert.equal(N - 1, callbacks);
});
client.on("error", function (e) {
client.on('error', function(e) {
throw e;
});
console.log("Client sending to " + port + ", localhost " + buf);
client.send(buf, 0, buf.length, port, "localhost", function (err, bytes) {
console.log('Client sending to ' + port + ', localhost ' + buf);
client.send(buf, 0, buf.length, port, 'localhost', function(err, bytes) {
if (err) {
throw err;
}
console.log("Client sent " + bytes + " bytes");
console.log('Client sent ' + bytes + ' bytes');
});
count += 1;
});
@ -75,12 +79,12 @@ function pingPongTest (port, host) {
}
// All are run at once, so run on different ports
pingPongTest(20989, "localhost");
pingPongTest(20990, "localhost");
pingPongTest(20989, 'localhost');
pingPongTest(20990, 'localhost');
pingPongTest(20988);
//pingPongTest("/tmp/pingpong.sock");
//pingPongTest('/tmp/pingpong.sock');
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(3, tests_run);
console.log('done');
});

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

@ -1,53 +1,57 @@
var common = require('../common');
var assert = require('assert');
var Buffer = require("buffer").Buffer,
fs = require("fs"),
dgram = require("dgram"), server, client,
var Buffer = require('buffer').Buffer,
fs = require('fs'),
dgram = require('dgram'), server, client,
server_port = 20989,
message_to_send = new Buffer("A message to send"),
message_to_send = new Buffer('A message to send'),
timer;
server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
assert.strictEqual(rinfo.address, "127.0.0.1");
server = dgram.createSocket('udp4');
server.on('message', function(msg, rinfo) {
console.log('server got: ' + msg +
' from ' + rinfo.address + ':' + rinfo.port);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(msg.toString(), message_to_send.toString());
server.send(msg, 0, msg.length, rinfo.port, rinfo.address);
});
server.on("listening", function () {
server.on('listening', function() {
var address = server.address();
console.log("server is listening on " + address.address + ":" + address.port);
client = dgram.createSocket("udp4");
client.on("message", function (msg, rinfo) {
console.log("client got: " + msg + " from " + rinfo.address + ":" + address.port);
assert.strictEqual(rinfo.address, "127.0.0.1");
console.log('server is listening on ' + address.address + ':' + address.port);
client = dgram.createSocket('udp4');
client.on('message', function(msg, rinfo) {
console.log('client got: ' + msg +
' from ' + rinfo.address + ':' + address.port);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(rinfo.port, server_port);
assert.strictEqual(msg.toString(), message_to_send.toString());
client.close();
server.close();
});
client.send(message_to_send, 0, message_to_send.length, server_port, "localhost", function (err, bytes) {
if (err) {
console.log("Caught error in client send.");
throw err;
}
console.log("client wrote " + bytes + " bytes.");
assert.strictEqual(bytes, message_to_send.length);
});
client.on("close", function () {
if (server.fd === null) {
clearTimeout(timer);
}
});
client.send(message_to_send, 0, message_to_send.length,
server_port, 'localhost', function(err, bytes) {
if (err) {
console.log('Caught error in client send.');
throw err;
}
console.log('client wrote ' + bytes + ' bytes.');
assert.strictEqual(bytes, message_to_send.length);
});
client.on('close',
function() {
if (server.fd === null) {
clearTimeout(timer);
}
});
});
server.on("close", function () {
server.on('close', function() {
if (client.fd === null) {
clearTimeout(timer);
}
});
server.bind(server_port);
timer = setTimeout(function () {
throw new Error("Timeout");
timer = setTimeout(function() {
throw new Error('Timeout');
}, 200);

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

@ -1,57 +1,57 @@
var common = require('../common');
var assert = require('assert');
var Buffer = require("buffer").Buffer,
fs = require("fs"),
dgram = require("dgram"), server, client,
server_path = "/tmp/dgram_server_sock",
var Buffer = require('buffer').Buffer,
fs = require('fs'),
dgram = require('dgram'), server, client,
server_path = '/tmp/dgram_server_sock',
messages_to_send = [
new Buffer("First message to send"),
new Buffer("Second message to send"),
new Buffer("Third message to send"),
new Buffer("Fourth message to send")
new Buffer('First message to send'),
new Buffer('Second message to send'),
new Buffer('Third message to send'),
new Buffer('Fourth message to send')
],
timer;
server = dgram.createSocket("unix_dgram");
server = dgram.createSocket('unix_dgram');
server.bind(server_path);
server.messages = [];
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg);
assert.strictEqual(rinfo.address, ""); // anon client sending
server.on('message', function(msg, rinfo) {
console.log('server got: ' + msg);
assert.strictEqual(rinfo.address, ''); // anon client sending
server.messages.push(msg.toString());
if (server.messages.length === messages_to_send.length) {
server.messages.forEach(function (m, i) {
server.messages.forEach(function(m, i) {
assert.strictEqual(m, messages_to_send[i].toString());
});
server.close();
client.close();
}
});
server.on("listening", function () {
console.log("server is listening");
client = dgram.createSocket("unix_dgram");
messages_to_send.forEach(function (m) {
client.send(m, 0, m.length, server_path, function (err, bytes) {
server.on('listening', function() {
console.log('server is listening');
client = dgram.createSocket('unix_dgram');
messages_to_send.forEach(function(m) {
client.send(m, 0, m.length, server_path, function(err, bytes) {
if (err) {
console.log("Caught error in client send.");
console.log('Caught error in client send.');
throw err;
}
console.log("client wrote " + bytes + " bytes.");
console.log('client wrote ' + bytes + ' bytes.');
});
});
client.on("close", function () {
client.on('close', function() {
if (server.fd === null) {
clearTimeout(timer);
}
});
});
server.on("close", function () {
server.on('close', function() {
if (client.fd === null) {
clearTimeout(timer);
}
});
timer = setTimeout(function () {
throw new Error("Timeout");
timer = setTimeout(function() {
throw new Error('Timeout');
}, 500);

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

@ -1,46 +1,47 @@
var common = require('../common');
var assert = require('assert');
var fs = require("fs");
var dgram = require("dgram");
var fs = require('fs');
var dgram = require('dgram');
// TODO use common.tmpDir here
var serverPath = "/tmp/dgram_server_sock";
var clientPath = "/tmp/dgram_client_sock";
var serverPath = '/tmp/dgram_server_sock';
var clientPath = '/tmp/dgram_client_sock';
var msgToSend = new Buffer("A message to send");
var msgToSend = new Buffer('A message to send');
var server = dgram.createSocket("unix_dgram");
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address);
var server = dgram.createSocket('unix_dgram');
server.on('message', function(msg, rinfo) {
console.log('server got: ' + msg + ' from ' + rinfo.address);
assert.strictEqual(rinfo.address, clientPath);
assert.strictEqual(msg.toString(), msgToSend.toString());
server.send(msg, 0, msg.length, rinfo.address);
});
server.on("listening", function () {
console.log("server is listening");
server.on('listening', function() {
console.log('server is listening');
var client = dgram.createSocket("unix_dgram");
var client = dgram.createSocket('unix_dgram');
client.on("message", function (msg, rinfo) {
console.log("client got: " + msg + " from " + rinfo.address);
client.on('message', function(msg, rinfo) {
console.log('client got: ' + msg + ' from ' + rinfo.address);
assert.strictEqual(rinfo.address, serverPath);
assert.strictEqual(msg.toString(), msgToSend.toString());
client.close();
server.close();
});
client.on("listening", function () {
console.log("client is listening");
client.send(msgToSend, 0, msgToSend.length, serverPath, function (err, bytes) {
if (err) {
console.log("Caught error in client send.");
throw err;
}
console.log("client wrote " + bytes + " bytes.");
assert.strictEqual(bytes, msgToSend.length);
});
client.on('listening', function() {
console.log('client is listening');
client.send(msgToSend, 0, msgToSend.length, serverPath,
function(err, bytes) {
if (err) {
console.log('Caught error in client send.');
throw err;
}
console.log('client wrote ' + bytes + ' bytes.');
assert.strictEqual(bytes, msgToSend.length);
});
});

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

@ -7,19 +7,19 @@ var fs = require('fs');
function tryToKillEventLoop() {
console.log('trying to kill event loop ...');
fs.stat(__filename, function (err) {
fs.stat(__filename, function(err) {
if (err) {
throw new Exception('first fs.stat failed')
throw new Exception('first fs.stat failed');
} else {
console.log('first fs.stat succeeded ...');
fs.stat(__filename, function (err) {
fs.stat(__filename, function(err) {
if (err) {
throw new Exception('second fs.stat failed')
throw new Exception('second fs.stat failed');
} else {
console.log('second fs.stat succeeded ...');
console.log('could not kill event loop, retrying...');
setTimeout(function () {
setTimeout(function() {
if (--count) {
tryToKillEventLoop();
} else {
@ -34,11 +34,11 @@ function tryToKillEventLoop() {
// Generate a lot of thread pool events
var pos = 0;
fs.open('/dev/zero', "r", 0666, function (err, fd) {
fs.open('/dev/zero', 'r', 0666, function(err, fd) {
if (err) throw err;
function readChunk () {
fs.read(fd, 1024, pos, 'binary', function (err, chunk, bytesRead) {
function readChunk() {
fs.read(fd, 1024, pos, 'binary', function(err, chunk, bytesRead) {
if (err) throw err;
if (chunk) {
pos += bytesRead;
@ -46,7 +46,8 @@ fs.open('/dev/zero', "r", 0666, function (err, fd) {
readChunk();
} else {
fs.closeSync(fd);
throw new Exception('/dev/zero should not end before the issue shows up');
throw new Exception('/dev/zero shouldn\'t end ' +
'before the issue shows up');
}
});
}
@ -55,6 +56,6 @@ fs.open('/dev/zero', "r", 0666, function (err, fd) {
tryToKillEventLoop();
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.ok(pos > 10000);
});

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

@ -1,21 +1,21 @@
var common = require('../common');
var assert = require('assert');
var path = require('path');
var testTxt = path.join(common.fixturesDir, "x.txt");
var testTxt = path.join(common.fixturesDir, 'x.txt');
var fs = require('fs');
setTimeout(function () {
setTimeout(function() {
// put this in a timeout, just so it doesn't get bunched up with the
// require() calls..
var N = 30;
for (var i=0; i < N; i++) {
console.log("start " + i);
for (var i = 0; i < N; i++) {
console.log('start ' + i);
fs.readFile(testTxt, function(err, data) {
if (err) {
console.log("error! " + e);
console.log('error! ' + e);
process.exit(1);
} else {
console.log("finish");
console.log('finish');
}
});
}

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

@ -6,16 +6,16 @@ var j = 0;
for (var i = 0; i < N; i++) {
// these files don't exist
fs.stat("does-not-exist-" + i, function (err) {
fs.stat('does-not-exist-' + i, function(err) {
if (err) {
j++; // only makes it to about 17
console.log("finish " + j);
console.log('finish ' + j);
} else {
throw new Error("this shouldn't be called");
throw new Error('this shouldn\'t be called');
}
});
}
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(N, j);
});

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

@ -5,9 +5,9 @@ var path = require('path');
var exits = 0;
function errExec (script, callback) {
function errExec(script, callback) {
var cmd = process.argv[0] + ' ' + path.join(common.fixturesDir, script);
return exec(cmd, function (err, stdout, stderr) {
return exec(cmd, function(err, stdout, stderr) {
// There was some error
assert.ok(err);
@ -29,23 +29,23 @@ function errExec (script, callback) {
// Simple throw error
errExec('throws_error.js', function (err, stdout, stderr) {
errExec('throws_error.js', function(err, stdout, stderr) {
assert.ok(/blah/.test(stderr));
});
// Trying to JSON.parse(undefined)
errExec('throws_error2.js', function (err, stdout, stderr) {
errExec('throws_error2.js', function(err, stdout, stderr) {
assert.ok(/SyntaxError/.test(stderr));
});
// Trying to JSON.parse(undefined) in nextTick
errExec('throws_error3.js', function (err, stdout, stderr) {
errExec('throws_error3.js', function(err, stdout, stderr) {
assert.ok(/SyntaxError/.test(stderr));
});
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(3, exits);
});

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

@ -7,24 +7,24 @@ var e = new events.EventEmitter();
var events_new_listener_emited = [];
var times_hello_emited = 0;
e.addListener("newListener", function (event, listener) {
console.log("newListener: " + event);
e.addListener('newListener', function(event, listener) {
console.log('newListener: ' + event);
events_new_listener_emited.push(event);
});
e.on("hello", function (a, b) {
console.log("hello");
times_hello_emited += 1
assert.equal("a", a);
assert.equal("b", b);
e.on('hello', function(a, b) {
console.log('hello');
times_hello_emited += 1;
assert.equal('a', a);
assert.equal('b', b);
});
console.log("start");
console.log('start');
e.emit("hello", "a", "b");
e.emit('hello', 'a', 'b');
process.addListener("exit", function () {
assert.deepEqual(["hello"], events_new_listener_emited);
process.addListener('exit', function() {
assert.deepEqual(['hello'], events_new_listener_emited);
assert.equal(1, times_hello_emited);
});

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

@ -2,55 +2,55 @@ var common = require('../common');
var assert = require('assert');
var events = require('events');
var callbacks_called = [ ];
var callbacks_called = [];
var e = new events.EventEmitter();
function callback1() {
callbacks_called.push("callback1");
e.addListener("foo", callback2);
e.addListener("foo", callback3);
e.removeListener("foo", callback1);
callbacks_called.push('callback1');
e.addListener('foo', callback2);
e.addListener('foo', callback3);
e.removeListener('foo', callback1);
}
function callback2() {
callbacks_called.push("callback2");
e.removeListener("foo", callback2);
callbacks_called.push('callback2');
e.removeListener('foo', callback2);
}
function callback3() {
callbacks_called.push("callback3");
e.removeListener("foo", callback3);
callbacks_called.push('callback3');
e.removeListener('foo', callback3);
}
e.addListener("foo", callback1);
assert.equal(1, e.listeners("foo").length);
e.addListener('foo', callback1);
assert.equal(1, e.listeners('foo').length);
e.emit("foo");
assert.equal(2, e.listeners("foo").length);
assert.deepEqual(["callback1"], callbacks_called);
e.emit('foo');
assert.equal(2, e.listeners('foo').length);
assert.deepEqual(['callback1'], callbacks_called);
e.emit("foo");
assert.equal(0, e.listeners("foo").length);
assert.deepEqual(["callback1", "callback2", "callback3"], callbacks_called);
e.emit('foo');
assert.equal(0, e.listeners('foo').length);
assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
e.emit("foo");
assert.equal(0, e.listeners("foo").length);
assert.deepEqual(["callback1", "callback2", "callback3"], callbacks_called);
e.emit('foo');
assert.equal(0, e.listeners('foo').length);
assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called);
e.addListener("foo", callback1);
e.addListener("foo", callback2);
assert.equal(2, e.listeners("foo").length)
e.removeAllListeners("foo")
assert.equal(0, e.listeners("foo").length)
e.addListener('foo', callback1);
e.addListener('foo', callback2);
assert.equal(2, e.listeners('foo').length);
e.removeAllListeners('foo');
assert.equal(0, e.listeners('foo').length);
// Verify that removing callbacks while in emit allows emits to propagate to
// all listeners
callbacks_called = [ ];
e.addListener("foo", callback2);
e.addListener("foo", callback3);
assert.equal(2, e.listeners("foo").length)
e.emit("foo");
assert.deepEqual(["callback2", "callback3"], callbacks_called);
assert.equal(0, e.listeners("foo").length)
callbacks_called = [];
e.addListener('foo', callback2);
e.addListener('foo', callback3);
assert.equal(2, e.listeners('foo').length);
e.emit('foo');
assert.deepEqual(['callback2', 'callback3'], callbacks_called);
assert.equal(0, e.listeners('foo').length);

22
test/simple/test-event-emitter-num-args.js

@ -3,24 +3,24 @@ var assert = require('assert');
var events = require('events');
var e = new events.EventEmitter(),
num_args_emited = [];
num_args_emited = [];
e.on("numArgs", function() {
e.on('numArgs', function() {
var numArgs = arguments.length;
console.log("numArgs: " + numArgs);
console.log('numArgs: ' + numArgs);
num_args_emited.push(numArgs);
});
console.log("start");
console.log('start');
e.emit("numArgs");
e.emit("numArgs", null);
e.emit("numArgs", null, null);
e.emit("numArgs", null, null, null);
e.emit("numArgs", null, null, null, null);
e.emit("numArgs", null, null, null, null, null);
e.emit('numArgs');
e.emit('numArgs', null);
e.emit('numArgs', null, null);
e.emit('numArgs', null, null, null);
e.emit('numArgs', null, null, null, null);
e.emit('numArgs', null, null, null, null, null);
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.deepEqual([0, 1, 2, 3, 4, 5], num_args_emited);
});

12
test/simple/test-event-emitter-once.js

@ -5,16 +5,16 @@ var events = require('events');
var e = new events.EventEmitter();
var times_hello_emited = 0;
e.once("hello", function (a, b) {
e.once('hello', function(a, b) {
times_hello_emited++;
});
e.emit("hello", "a", "b");
e.emit("hello", "a", "b");
e.emit("hello", "a", "b");
e.emit("hello", "a", "b");
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(1, times_hello_emited);
});

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

@ -5,35 +5,35 @@ var events = require('events');
var count = 0;
function listener1 () {
function listener1() {
console.log('listener1');
count++;
}
function listener2 () {
function listener2() {
console.log('listener2');
count++;
}
function listener3 () {
function listener3() {
console.log('listener3');
count++;
}
var e1 = new events.EventEmitter();
e1.addListener("hello", listener1);
e1.removeListener("hello", listener1);
e1.addListener('hello', listener1);
e1.removeListener('hello', listener1);
assert.deepEqual([], e1.listeners('hello'));
var e2 = new events.EventEmitter();
e2.addListener("hello", listener1);
e2.removeListener("hello", listener2);
e2.addListener('hello', listener1);
e2.removeListener('hello', listener2);
assert.deepEqual([listener1], e2.listeners('hello'));
var e3 = new events.EventEmitter();
e3.addListener("hello", listener1);
e3.addListener("hello", listener2);
e3.removeListener("hello", listener1);
e3.addListener('hello', listener1);
e3.addListener('hello', listener2);
e3.removeListener('hello', listener1);
assert.deepEqual([listener2], e3.listeners('hello'));

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

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

4
test/simple/test-exception-handler2.js

@ -1,12 +1,12 @@
var common = require('../common');
var assert = require('assert');
process.on('uncaughtException', function (err) {
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
});
var timeoutFired = false;
setTimeout(function () {
setTimeout(function() {
console.log('This will still run.');
timeoutFired = true;
}, 500);

49
test/simple/test-exec.js

@ -4,12 +4,12 @@ var exec = require('child_process').exec;
var success_count = 0;
var error_count = 0;
exec("ls /", function (err, stdout, stderr) {
exec('ls /', function(err, stdout, stderr) {
if (err) {
error_count++;
console.log("error!: " + err.code);
console.log("stdout: " + JSON.stringify(stdout));
console.log("stderr: " + JSON.stringify(stderr));
console.log('error!: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
@ -18,29 +18,29 @@ exec("ls /", function (err, stdout, stderr) {
});
exec("ls /DOES_NOT_EXIST", function (err, stdout, stderr) {
exec('ls /DOES_NOT_EXIST', function(err, stdout, stderr) {
if (err) {
error_count++;
assert.equal("", stdout);
assert.equal('', stdout);
assert.equal(true, err.code != 0);
assert.equal(false, err.killed);
assert.strictEqual(null, err.signal);
console.log("error code: " + err.code);
console.log("stdout: " + JSON.stringify(stdout));
console.log("stderr: " + JSON.stringify(stderr));
console.log('error code: ' + err.code);
console.log('stdout: ' + JSON.stringify(stdout));
console.log('stderr: ' + JSON.stringify(stderr));
} else {
success_count++;
console.dir(stdout);
assert.equal(true, stdout != "");
assert.equal(true, stdout != '');
}
});
var sleeperStart = new Date();
exec("sleep 3", { timeout: 50 }, function (err, stdout, stderr) {
exec('sleep 3', { timeout: 50 }, function(err, stdout, stderr) {
var diff = (new Date()) - sleeperStart;
console.log("sleep 3 with timeout 50 took %d ms", diff);
console.log('\'sleep 3\' with timeout 50 took %d ms', diff);
assert.ok(diff < 500);
assert.ok(err);
assert.ok(err.killed);
@ -51,19 +51,19 @@ exec("sleep 3", { timeout: 50 }, function (err, stdout, stderr) {
var startSleep3 = new Date();
var killMeTwice = exec("sleep 3", { timeout: 1000 }, killMeTwiceCallback);
var killMeTwice = exec('sleep 3', {timeout: 1000}, killMeTwiceCallback);
process.nextTick(function(){
console.log("kill pid %d", killMeTwice.pid);
process.nextTick(function() {
console.log('kill pid %d', killMeTwice.pid);
// make sure there is no race condition in starting the process
// the PID SHOULD exist directly following the exec() call.
assert.equal('number', typeof killMeTwice._internal.pid);
// Kill the process
// Kill the process
killMeTwice.kill();
});
function killMeTwiceCallback(err, stdout, stderr) {
var diff = (new Date()) - startSleep3;
var diff = (new Date()) - startSleep3;
// We should have already killed this process. Assert that
// the timeout still works and that we are getting the proper callback
// parameters.
@ -72,19 +72,20 @@ function killMeTwiceCallback(err, stdout, stderr) {
assert.equal(err.signal, 'SIGTERM');
// the timeout should still be in effect
console.log("'sleep 3' was already killed. Took %d ms", diff);
console.log('\'sleep 3\' was already killed. Took %d ms', diff);
assert.ok(diff < 1500);
}
exec('python -c "print 200000*\'C\'"', { maxBuffer: 1000 }, function (err, stdout, stderr) {
assert.ok(err);
assert.ok(err.killed);
assert.equal(err.signal, 'SIGTERM');
});
exec('python -c "print 200000*\'C\'"', {maxBuffer: 1000},
function(err, stdout, stderr) {
assert.ok(err);
assert.ok(err.killed);
assert.equal(err.signal, 'SIGTERM');
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(1, success_count);
assert.equal(1, error_count);
});

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

@ -1,11 +1,13 @@
var common = require('../common');
var assert = require('assert');;
var path = require("path");
var assert = require('assert');
var path = require('path');
var isDebug = (process.version.indexOf('debug') >= 0);
var debugPath = path.normalize(path.join(__dirname, '..', '..', 'build', 'debug', 'node_g'));
var defaultPath = path.normalize(path.join(__dirname, '..', '..', 'build', 'default', 'node'));
var debugPath = path.normalize(path.join(__dirname, '..', '..',
'build', 'debug', 'node_g'));
var defaultPath = path.normalize(path.join(__dirname, '..', '..',
'build', 'default', 'node'));
console.log('debugPath: ' + debugPath);
console.log('defaultPath: ' + defaultPath);

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

@ -4,18 +4,18 @@ var path = require('path');
var fs = require('fs');
var got_error = false;
var filename = path.join(common.fixturesDir, "does_not_exist.txt");
fs.readFile(filename, "raw", function (err, content) {
var filename = path.join(common.fixturesDir, 'does_not_exist.txt');
fs.readFile(filename, 'raw', function(err, content) {
if (err) {
got_error = true;
} else {
common.debug("cat returned some content: " + content);
common.debug("this shouldn't happen as the file doesn't exist...");
common.debug('cat returned some content: ' + content);
common.debug('this shouldn\'t happen as the file doesn\'t exist...');
assert.equal(true, false);
}
});
process.addListener("exit", function () {
console.log("done");
process.addListener('exit', function() {
console.log('done');
assert.equal(true, got_error);
});

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

@ -1,50 +1,49 @@
var common = require('../common');
var assert = require('assert');
var
path = require('path'),
fs = require('fs'),
fn = path.join(common.tmpDir, "write.txt"),
file = fs.createWriteStream(fn),
var path = require('path'),
fs = require('fs'),
fn = path.join(common.tmpDir, 'write.txt'),
file = fs.createWriteStream(fn),
EXPECTED = '012345678910',
EXPECTED = '012345678910',
callbacks = {
open: -1,
drain: -2,
close: -1,
endCb: -1,
};
callbacks = {
open: -1,
drain: -2,
close: -1,
endCb: -1
};
file
.addListener('open', function(fd) {
callbacks.open++;
assert.equal('number', typeof fd);
})
callbacks.open++;
assert.equal('number', typeof fd);
})
.addListener('error', function(err) {
throw err;
})
throw err;
})
.addListener('drain', function() {
callbacks.drain++;
if (callbacks.drain == -1) {
assert.equal(EXPECTED, fs.readFileSync(fn));
file.write(EXPECTED);
} else if (callbacks.drain == 0) {
assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn));
file.end(function(err) {
assert.ok(!err);
callbacks.endCb++;
});
}
})
callbacks.drain++;
if (callbacks.drain == -1) {
assert.equal(EXPECTED, fs.readFileSync(fn));
file.write(EXPECTED);
} else if (callbacks.drain == 0) {
assert.equal(EXPECTED + EXPECTED, fs.readFileSync(fn));
file.end(function(err) {
assert.ok(!err);
callbacks.endCb++;
});
}
})
.addListener('close', function() {
callbacks.close++;
assert.throws(function() {
file.write('should not work anymore');
});
callbacks.close++;
assert.throws(function() {
file.write('should not work anymore');
});
fs.unlinkSync(fn);
});
fs.unlinkSync(fn);
});
for (var i = 0; i < 11; i++) {
(function(i) {
@ -54,6 +53,6 @@ for (var i = 0; i < 11; i++) {
process.addListener('exit', function() {
for (var k in callbacks) {
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
assert.equal(0, callbacks[k], k + ' count off by ' + callbacks[k]);
}
});

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

@ -5,9 +5,9 @@ var fs = require('fs');
var got_error = false;
var success_count = 0;
var file = path.join(common.fixturesDir, "a.js");
var file = path.join(common.fixturesDir, 'a.js');
fs.chmod(file, 0777, function (err) {
fs.chmod(file, 0777, function(err) {
if (err) {
got_error = true;
} else {
@ -20,7 +20,7 @@ fs.chmod(file, 0777, function (err) {
}
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(1, success_count);
assert.equal(false, got_error);
});

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

@ -9,7 +9,7 @@ var path = require('path'),
// ASYNC_CALL
fs.stat(fn, function(err) {
assert.equal(fn, err.path)
assert.equal(fn, err.path);
assert.ok(0 <= err.message.indexOf(fn));
});
@ -60,7 +60,7 @@ fs.readFile(fn, function(err) {
// Sync
var errors = [],
expected = 0;
expected = 0;
try {
++expected;
@ -158,7 +158,8 @@ try {
assert.ok(0 <= err.message.indexOf(fn));
}
process.addListener('exit', function () {
process.addListener('exit', function() {
assert.equal(expected, errors.length,
'Test fs sync exceptions raised, got ' + errors.length + ' expected ' + expected);
'Test fs sync exceptions raised, got ' + errors.length +
' expected ' + expected);
});

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

@ -5,34 +5,34 @@ var path = require('path');
var fs = require('fs');
var successes = 0;
var file = path.join(common.fixturesDir, "a.js");
var file = path.join(common.fixturesDir, 'a.js');
common.error("open " + file);
common.error('open ' + file);
fs.open(file, "a", 0777, function (err, fd) {
common.error("fd " + fd);
fs.open(file, 'a', 0777, function(err, fd) {
common.error('fd ' + fd);
if (err) throw err;
fs.fdatasyncSync(fd);
common.error("fdatasync SYNC: ok");
common.error('fdatasync SYNC: ok');
successes++;
fs.fsyncSync(fd);
common.error("fsync SYNC: ok");
common.error('fsync SYNC: ok');
successes++;
fs.fdatasync(fd, function (err) {
fs.fdatasync(fd, function(err) {
if (err) throw err;
common.error("fdatasync ASYNC: ok");
common.error('fdatasync ASYNC: ok');
successes++;
fs.fsync(fd, function(err) {
if (err) throw err;
common.error("fsync ASYNC: ok");
common.error('fsync ASYNC: ok');
successes++;
});
});
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(4, successes);
});

2
test/simple/test-fs-read-file-sync-hostname.js

@ -3,7 +3,7 @@ var assert = require('assert');
var fs = require('fs');
// test reading from hostname
if (process.platform === "linux2") {
if (process.platform === 'linux2') {
var hostname = fs.readFileSync('/proc/sys/kernel/hostname');
assert.ok(hostname.length > 0);
}

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

@ -7,6 +7,6 @@ var fn = path.join(common.fixturesDir, 'elipses.txt');
var s = fs.readFileSync(fn, 'utf8');
for (var i = 0; i < s.length; i++) {
assert.equal("\u2026", s[i]);
assert.equal('\u2026', s[i]);
}
assert.equal(10000, s.length);

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

@ -62,16 +62,16 @@ file2.destroy(function(err) {
var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
file3.length = 0;
file3.addListener('data', function(data) {
assert.equal("string", typeof(data));
assert.equal('string', typeof(data));
file3.length += data.length;
for (var i = 0; i < data.length; i++) {
// http://www.fileformat.info/info/unicode/char/2026/index.htm
assert.equal("\u2026", data[i]);
assert.equal('\u2026', data[i]);
}
});
file3.addListener('close', function () {
file3.addListener('close', function() {
callbacks.close++;
});
@ -98,24 +98,24 @@ file4.addListener('end', function(data) {
try {
fs.createReadStream(rangeFile, {start: 10, end: 2});
assert.fail('Creating a ReadStream with incorrect range limits must throw.');
} catch(e) {
} catch (e) {
assert.equal(e.message, 'start must be <= end');
}
try {
fs.createReadStream(rangeFile, {start: 2});
assert.fail('Creating a ReadStream with a only one range limits must throw.');
} catch(e) {
} catch (e) {
assert.equal(e.message, 'Both start and end are needed for range streaming.');
}
var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 });
stream.data = '';
stream.on('data', function(chunk){
stream.on('data', function(chunk) {
stream.data += chunk;
});
stream.on('end', function(){
stream.on('end', function() {
assert.equal('x', stream.data);
});

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

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

20
test/simple/test-fs-sir-writes-alot.js

@ -1,6 +1,6 @@
var common = require('../common');
var fs = require("fs");
var assert = require("assert");
var fs = require('fs');
var assert = require('assert');
var join = require('path').join;
var filename = join(common.tmpDir, 'out.txt');
@ -11,37 +11,37 @@ try {
// might not exist, that's okay.
}
var fd = fs.openSync(filename, "w");
var fd = fs.openSync(filename, 'w');
var line = "aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n";
var line = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n';
var N = 10240, complete = 0;
for (var i = 0; i < N; i ++) {
for (var i = 0; i < N; i++) {
// Create a new buffer for each write. Before the write is actually
// executed by the thread pool, the buffer will be collected.
var buffer = new Buffer(line);
fs.write(fd, buffer, 0, buffer.length, null, function (er, written) {
fs.write(fd, buffer, 0, buffer.length, null, function(er, written) {
complete++;
if (complete === N) {
fs.closeSync(fd);
var s = fs.createReadStream(filename);
s.on("data", testBuffer);
s.on('data', testBuffer);
}
});
}
var bytesChecked = 0;
function testBuffer (b) {
function testBuffer(b) {
for (var i = 0; i < b.length; i++) {
bytesChecked++;
if (b[i] !== 'a'.charCodeAt(0) && b[i] !== '\n'.charCodeAt(0)) {
throw new Error("invalid char "+i+","+b[i]);
throw new Error('invalid char ' + i + ',' + b[i]);
}
}
}
process.on('exit', function () {
process.on('exit', function() {
// Probably some of the writes are going to overlap, so we can't assume
// that we get (N * line.length). Let's just make sure we've checked a
// few...

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

@ -4,7 +4,7 @@ var fs = require('fs');
var got_error = false;
var success_count = 0;
fs.stat(".", function (err, stats) {
fs.stat('.', function(err, stats) {
if (err) {
got_error = true;
} else {
@ -14,7 +14,7 @@ fs.stat(".", function (err, stats) {
}
});
fs.lstat(".", function (err, stats) {
fs.lstat('.', function(err, stats) {
if (err) {
got_error = true;
} else {
@ -25,11 +25,11 @@ fs.lstat(".", function (err, stats) {
});
// fstat
fs.open(".", "r", undefined, function(err, fd) {
fs.open('.', 'r', undefined, function(err, fd) {
assert.ok(!err);
assert.ok(fd);
fs.fstat(fd, function (err, stats) {
fs.fstat(fd, function(err, stats) {
if (err) {
got_error = true;
} else {
@ -42,7 +42,7 @@ fs.open(".", "r", undefined, function(err, fd) {
});
// fstatSync
fs.open(".", "r", undefined, function(err, fd) {
fs.open('.', 'r', undefined, function(err, fd) {
var stats;
try {
stats = fs.fstatSync(fd);
@ -57,40 +57,40 @@ fs.open(".", "r", undefined, function(err, fd) {
fs.close(fd);
});
console.log("stating: " + __filename);
fs.stat(__filename, function (err, s) {
console.log('stating: ' + __filename);
fs.stat(__filename, function(err, s) {
if (err) {
got_error = true;
} else {
console.dir(s);
success_count++;
console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) );
console.log('isDirectory: ' + JSON.stringify(s.isDirectory()));
assert.equal(false, s.isDirectory());
console.log("isFile: " + JSON.stringify( s.isFile() ) );
console.log('isFile: ' + JSON.stringify(s.isFile()));
assert.equal(true, s.isFile());
console.log("isSocket: " + JSON.stringify( s.isSocket() ) );
console.log('isSocket: ' + JSON.stringify(s.isSocket()));
assert.equal(false, s.isSocket());
console.log("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) );
console.log('isBlockDevice: ' + JSON.stringify(s.isBlockDevice()));
assert.equal(false, s.isBlockDevice());
console.log("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) );
console.log('isCharacterDevice: ' + JSON.stringify(s.isCharacterDevice()));
assert.equal(false, s.isCharacterDevice());
console.log("isFIFO: " + JSON.stringify( s.isFIFO() ) );
console.log('isFIFO: ' + JSON.stringify(s.isFIFO()));
assert.equal(false, s.isFIFO());
console.log("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) );
console.log('isSymbolicLink: ' + JSON.stringify(s.isSymbolicLink()));
assert.equal(false, s.isSymbolicLink());
assert.ok(s.mtime instanceof Date);
}
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(5, success_count);
assert.equal(false, got_error);
});

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

@ -1,13 +1,13 @@
var common = require('../common');
var assert = common.assert;
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var completed = 0;
// test creating and reading symbolic link
var linkData = path.join(common.fixturesDir, "/cycles/root.js");
var linkData = path.join(common.fixturesDir, '/cycles/root.js');
var linkPath = path.join(common.tmpDir, 'symlink1.js');
fs.symlink(linkData, linkPath, function(err){
fs.symlink(linkData, linkPath, function(err) {
if (err) throw err;
console.log('symlink done');
// todo: fs.lstat?
@ -15,13 +15,13 @@ fs.symlink(linkData, linkPath, function(err){
if (err) throw err;
assert.equal(destination, linkData);
completed++;
})
});
});
// test creating and reading hard link
var srcPath = path.join(common.fixturesDir, "cycles", 'root.js');
var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js');
var dstPath = path.join(common.tmpDir, 'link1.js');
fs.link(srcPath, dstPath, function(err){
fs.link(srcPath, dstPath, function(err) {
if (err) throw err;
console.log('hard link done');
var srcContent = fs.readFileSync(srcPath, 'utf8');
@ -30,7 +30,7 @@ fs.link(srcPath, dstPath, function(err){
completed++;
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(completed, 2);
});

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

@ -9,7 +9,7 @@ var path = require('path'),
writeCalled = 0;
fs.open(filename, 'w', 0644, function (err, fd) {
fs.open(filename, 'w', 0644, function(err, fd) {
openCalled++;
if (err) throw err;
@ -26,7 +26,7 @@ fs.open(filename, 'w', 0644, function (err, fd) {
});
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(1, openCalled);
assert.equal(1, writeCalled);
});

34
test/simple/test-fs-write-file-buffer.js

@ -4,23 +4,23 @@ var util = require('util');
var fs = require('fs');
var data = [
'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH',
'Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/',
'2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e',
'Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAQABADASIAAhEBAxEB/8QA',
'HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF',
'BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK',
'FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1',
'dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG',
'x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEB',
'AQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC',
'AxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRom',
'JygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE',
'hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU',
'1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDhfBUFl/wk',
'OmPqKJJZw3aiZFBw4z93jnkkc9u9dj8XLfSI/EBt7DTo7ea2Ox5YXVo5FC7g',
'Tjq24nJPXNVtO0KATRvNHCIg3zoWJWQHqp+o4pun+EtJ0zxBq8mnLJa2d1L5',
'0NvnKRjJBUE5PAx3NYxxUY0pRtvYHSc5Ka2X9d7H/9k='];
'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH',
'Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/',
'2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e',
'Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAQABADASIAAhEBAxEB/8QA',
'HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF',
'BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK',
'FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1',
'dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG',
'x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEB',
'AQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC',
'AxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRom',
'JygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE',
'hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU',
'1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDhfBUFl/wk',
'OmPqKJJZw3aiZFBw4z93jnkkc9u9dj8XLfSI/EBt7DTo7ea2Ox5YXVo5FC7g',
'Tjq24nJPXNVtO0KATRvNHCIg3zoWJWQHqp+o4pun+EtJ0zxBq8mnLJa2d1L5',
'0NvnKRjJBUE5PAx3NYxxUY0pRtvYHSc5Ka2X9d7H/9k='];
data = data.join('\n');

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

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

15
test/simple/test-fs-write-stream.js

@ -3,15 +3,15 @@ var assert = require('assert');
var path = require('path'),
fs = require('fs');
var file = path.join(common.tmpDir, "write.txt");
var file = path.join(common.tmpDir, 'write.txt');
(function() {
var stream = fs.WriteStream(file),
_fs_close = fs.close;
fs.close = function(fd) {
assert.ok(fd, "fs.close must not be called without an undefined fd.")
assert.ok(fd, 'fs.close must not be called without an undefined fd.');
fs.close = _fs_close;
}
stream.destroy();
@ -19,9 +19,10 @@ var file = path.join(common.tmpDir, "write.txt");
(function() {
var stream = fs.createWriteStream(file);
stream.addListener('drain', function () {
assert.fail('"drain" event must not be emitted before stream.write() has been called at least once.')
stream.addListener('drain', function() {
assert.fail('\'drain\' event must not be emitted before ' +
'stream.write() has been called at least once.');
});
stream.destroy();
})();

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

@ -5,7 +5,7 @@ var fs = require('fs');
var fn = path.join(common.tmpDir, 'write.txt');
var foo = 'foo'
var foo = 'foo';
var fd = fs.openSync(fn, 'w');
var written = fs.writeSync(fd, '');
@ -13,7 +13,7 @@ assert.strictEqual(0, written);
fs.writeSync(fd, foo);
var bar = 'bár'
var bar = 'bár';
written = fs.writeSync(fd, new Buffer(bar), 0, Buffer.byteLength(bar));
assert.ok(written > 3);
fs.closeSync(fd);

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

@ -1,21 +1,21 @@
var common = require("../common");
var assert = common.assert
var common = require('../common');
var assert = require('assert');
var path = require('path');
var Buffer = require('buffer').Buffer;
var fs = require('fs');
var fn = path.join(common.tmpDir, "write.txt");
var fn2 = path.join(common.tmpDir, "write2.txt");
var expected = "ümlaut.";
var fn = path.join(common.tmpDir, 'write.txt');
var fn2 = path.join(common.tmpDir, 'write2.txt');
var expected = 'ümlaut.';
var constants = require('constants');
var found, found2;
fs.open(fn, 'w', 0644, function (err, fd) {
fs.open(fn, 'w', 0644, function(err, fd) {
if (err) throw err;
console.log('open done');
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, "utf8", function (err, written) {
fs.write(fd, expected, 0, 'utf8', function(err, written) {
console.log('write done');
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
@ -28,27 +28,27 @@ fs.open(fn, 'w', 0644, function (err, fd) {
});
fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC,
0644, function (err, fd) {
if (err) throw err;
console.log('open done');
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, "utf8", function (err, written) {
console.log('write done');
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.closeSync(fd);
found2 = fs.readFileSync(fn2, 'utf8');
console.log('expected: ' + expected.toJSON());
console.log('found: ' + found2.toJSON());
fs.unlinkSync(fn2);
});
});
fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 0644,
function(err, fd) {
if (err) throw err;
console.log('open done');
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, 'utf8', function(err, written) {
console.log('write done');
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.closeSync(fd);
found2 = fs.readFileSync(fn2, 'utf8');
console.log('expected: ' + expected.toJSON());
console.log('found: ' + found2.toJSON());
fs.unlinkSync(fn2);
});
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(expected, found);
assert.equal(expected, found2);
});

16
test/simple/test-global.js

@ -3,16 +3,16 @@ var assert = require('assert');
common.globalCheck = false;
baseFoo = "foo";
global.baseBar = "bar";
baseFoo = 'foo';
global.baseBar = 'bar';
assert.equal("foo", global.baseFoo, "x -> global.x in base level not working");
assert.equal('foo', global.baseFoo, 'x -> global.x in base level not working');
assert.equal("bar", baseBar, "global.x -> x in base level not working");
assert.equal('bar', baseBar, 'global.x -> x in base level not working');
var module = require("../fixtures/global/plain"),
fooBar = module.fooBar;
var module = require('../fixtures/global/plain'),
fooBar = module.fooBar;
assert.equal("foo", fooBar.foo, "x -> global.x in sub level not working");
assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working');
assert.equal("bar", fooBar.bar, "global.x -> x in sub level not working");
assert.equal('bar', fooBar.bar, 'global.x -> x in sub level not working');

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

@ -4,30 +4,30 @@ var path = require('path');
var fs = require('fs');
var dirname = path.dirname(__filename);
var d = path.join(common.tmpDir, "dir");
var d = path.join(common.tmpDir, 'dir');
var mkdir_error = false;
var rmdir_error = false;
fs.mkdir(d, 0666, function (err) {
fs.mkdir(d, 0666, function(err) {
if (err) {
console.log("mkdir error: " + err.message);
console.log('mkdir error: ' + err.message);
mkdir_error = true;
} else {
console.log("mkdir okay!");
fs.rmdir(d, function (err) {
console.log('mkdir okay!');
fs.rmdir(d, function(err) {
if (err) {
console.log("rmdir error: " + err.message);
console.log('rmdir error: ' + err.message);
rmdir_error = true;
} else {
console.log("rmdir okay!");
console.log('rmdir okay!');
}
});
}
});
process.addListener("exit", function () {
process.addListener('exit', function() {
assert.equal(false, mkdir_error);
assert.equal(false, rmdir_error);
console.log("exit");
console.log('exit');
});

2
test/simple/test-net-connect-handle-econnrefused.js

@ -9,7 +9,7 @@ var c = net.createConnection(common.PORT);
c.on('connect', function() {
console.error('connected?!');
assert.ok(false);
})
});
var gotError = false;
c.on('error', function(e) {

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

@ -6,9 +6,9 @@ var serverConnection;
var echoServer = net.createServer(function(connection) {
serverConnection = connection;
connection.setTimeout(0);
assert.notEqual(connection.setKeepAlive,undefined);
assert.notEqual(connection.setKeepAlive, undefined);
// send a keepalive packet after 1000 ms
connection.setKeepAlive(true,1000);
connection.setKeepAlive(true, 1000);
connection.addListener('end', function() {
connection.end();
});
@ -19,10 +19,10 @@ echoServer.addListener('listening', function() {
var clientConnection = net.createConnection(common.PORT);
clientConnection.setTimeout(0);
setTimeout( function() {
setTimeout(function() {
// make sure both connections are still open
assert.equal(serverConnection.readyState,'open');
assert.equal(clientConnection.readyState,'open');
assert.equal(serverConnection.readyState, 'open');
assert.equal(clientConnection.readyState, 'open');
serverConnection.end();
clientConnection.end();
echoServer.close();

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

@ -5,7 +5,7 @@ var net = require('net');
var tests_run = 0;
function pingPongTest (port, host) {
function pingPongTest(port, host) {
var N = 1000;
var count = 0;
var sent_final_ping = false;
@ -86,7 +86,7 @@ function pingPongTest (port, host) {
client.addListener('close', function() {
console.log('client.endd');
assert.equal(N+1, count);
assert.equal(N + 1, count);
assert.equal(true, sent_final_ping);
tests_run += 1;
});

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

@ -51,7 +51,7 @@ server.listen(common.PORT, function() {
});
process.addListener('exit', function() {
assert.equal(N+1, disconnect_count);
assert.equal(N+1, client_recv_count);
assert.equal(N + 1, disconnect_count);
assert.equal(N + 1, client_recv_count);
});

8
test/simple/test-net-server-bind.js

@ -23,7 +23,7 @@ var server1 = net.createServer(function(socket) { });
server1.listen(common.PORT);
setTimeout(function() {
address1 = server1.address()
address1 = server1.address();
console.log('address1 %j', address1);
server1.close();
}, 100);
@ -34,8 +34,8 @@ setTimeout(function() {
var address2;
var server2 = net.createServer(function(socket) { });
server2.listen(common.PORT+1, function() {
address2 = server2.address()
server2.listen(common.PORT + 1, function() {
address2 = server2.address();
console.log('address2 %j', address2);
server2.close();
});
@ -45,5 +45,5 @@ server2.listen(common.PORT+1, function() {
process.on('exit', function() {
assert.ok(address0.port > 100);
assert.equal(common.PORT, address1.port);
assert.equal(common.PORT+1, address2.port);
assert.equal(common.PORT + 1, address2.port);
});

20
test/simple/test-net-server-max-connections.js

@ -26,12 +26,12 @@ server.listen(common.PORT, function() {
}
});
server.maxConnections = N/2;
server.maxConnections = N / 2;
console.error('server.maxConnections = %d', server.maxConnections);
function makeConnection (index) {
function makeConnection(index) {
setTimeout(function() {
var c = net.createConnection(common.PORT);
var gotData = false;
@ -51,12 +51,14 @@ function makeConnection (index) {
console.error('closed %d', index);
closes++;
if (closes < N/2) {
assert.ok(server.maxConnections <= index,
index + ' was one of the first closed connections but shouldnt have been');
if (closes < N / 2) {
assert.ok(server.maxConnections <= index,
index +
' was one of the first closed connections ' +
'but shouldnt have been');
}
if (closes === N/2) {
if (closes === N / 2) {
var cb;
console.error('calling wait callback.');
while (cb = waits.shift()) {
@ -66,9 +68,11 @@ function makeConnection (index) {
}
if (index < server.maxConnections) {
assert.equal(true, gotData, index + ' didn\'t get data, but should have');
assert.equal(true, gotData,
index + ' didn\'t get data, but should have');
} else {
assert.equal(false, gotData, index + ' got data, but shouldn\'t have');
assert.equal(false, gotData,
index + ' got data, but shouldn\'t have');
}
});
}, index);

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

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var i;
var N = 30;

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

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var order = [];
process.nextTick(function() {

38
test/simple/test-repl.js

@ -123,16 +123,16 @@ function tcp_test() {
assert.equal(true, client_tcp.writable);
send_expect([
{ client: client_tcp, send: '',
expect: prompt_tcp },
{ client: client_tcp, send: 'invoke_me(333)\n',
expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) },
{ client: client_tcp, send: 'a += 1\n',
expect: ('12346' + '\n' + prompt_tcp) },
{ client: client_tcp,
send: 'require(\'' + moduleFilename + '\').number\n',
expect: ('42' + '\n' + prompt_tcp) }
]);
{ client: client_tcp, send: '',
expect: prompt_tcp },
{ client: client_tcp, send: 'invoke_me(333)\n',
expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) },
{ client: client_tcp, send: 'a += 1\n',
expect: ('12346' + '\n' + prompt_tcp) },
{ client: client_tcp,
send: 'require(\'' + moduleFilename + '\').number\n',
expect: ('42' + '\n' + prompt_tcp) }
]);
});
client_tcp.addListener('data', function(data) {
@ -187,15 +187,15 @@ function unix_test() {
assert.equal(true, client_unix.writable);
send_expect([
{ client: client_unix, send: '',
expect: prompt_unix },
{ client: client_unix, send: 'message\n',
expect: ('\'' + message + '\'\n' + prompt_unix) },
{ client: client_unix, send: 'invoke_me(987)\n',
expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) },
{ client: client_unix, send: 'a = 12345\n',
expect: ('12345' + '\n' + prompt_unix) }
]);
{ client: client_unix, send: '',
expect: prompt_unix },
{ client: client_unix, send: 'message\n',
expect: ('\'' + message + '\'\n' + prompt_unix) },
{ client: client_unix, send: 'invoke_me(987)\n',
expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) },
{ client: client_unix, send: 'a = 12345\n',
expect: ('12345' + '\n' + prompt_unix) }
]);
});
client_unix.addListener('data', function(data) {

2
test/simple/test-require-resolve.js

@ -1,6 +1,6 @@
var common = require('../common');
var fixturesDir = common.fixturesDir;
var assert = common.assert;
var assert = require('assert');
var path = require('path');
assert.equal(path.join(__dirname, '../fixtures/a.js'),

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

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

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

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

2
test/simple/test-securepair-server.js

@ -1,8 +1,8 @@
var common = require('../common');
var assert = require('assert');
var join = require('path').join;
var net = require('net');
var assert = require('assert');
var fs = require('fs');
var crypto = require('crypto');
var spawn = require('child_process').spawn;

3
test/simple/test-sigint-infinite-loop.js

@ -1,5 +1,6 @@
// This test is to assert that we can SIGINT a script which loops forever.
// ref: http://groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
// Ref(http):
// groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;

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

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var childKilled = false, done = false,
spawn = require('child_process').spawn,

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

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
var path = require('path');
var fs = require('fs');

2
test/simple/test-sys.js

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
assert.equal('0', common.inspect(0));
assert.equal('1', common.inspect(1));

2
test/simple/test-umask.js

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

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

@ -1,5 +1,5 @@
var common = require('../common');
var assert = require('assert');;
var assert = require('assert');
// üäö

2
test/simple/test-zerolengthbufferbug.js

@ -1,7 +1,7 @@
// Serving up a zero-length buffer should work.
var common = require('../common');
var assert = common.assert;
var assert = require('assert');
var http = require('http');
var server = http.createServer(function(req, res) {

Loading…
Cancel
Save