From 530328f12b4a00dfbc8ea57bafb1f9344912f0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 28 Nov 2009 18:26:59 +0100 Subject: [PATCH] CommonJS testing for node.js Refactored test suite to use the assert module for testing rather than mjsunit. --- lib/assert.js | 176 +++ lib/util.js | 1033 +++++++++++++++++ test/mjsunit/common.js | 5 +- test/mjsunit/disabled/test-cat.js | 8 +- test/mjsunit/disabled/test-http-stress.js | 6 +- test/mjsunit/fixtures/b/c.js | 4 +- test/mjsunit/test-buffered-file.js | 6 +- test/mjsunit/test-byte-length.js | 16 +- test/mjsunit/test-chdir.js | 4 +- test/mjsunit/test-delayed-require.js | 6 +- .../test-event-emitter-add-listeners.js | 8 +- test/mjsunit/test-exception-handler.js | 6 +- test/mjsunit/test-exec.js | 10 +- test/mjsunit/test-file-cat-noexist.js | 4 +- test/mjsunit/test-fs-sendfile.js | 4 +- test/mjsunit/test-fs-stat.js | 20 +- test/mjsunit/test-fs-write.js | 2 +- test/mjsunit/test-http-cat.js | 6 +- test/mjsunit/test-http-chunked.js | 4 +- test/mjsunit/test-http-client-race.js | 4 +- test/mjsunit/test-http-client-upload.js | 8 +- test/mjsunit/test-http-malformed-request.js | 2 +- test/mjsunit/test-http-proxy.js | 4 +- test/mjsunit/test-http-server.js | 30 +- test/mjsunit/test-http-tls.js | 42 +- test/mjsunit/test-http.js | 30 +- test/mjsunit/test-keep-alive.js | 10 +- test/mjsunit/test-memory-usage.js | 4 +- test/mjsunit/test-mkdir-rmdir.js | 4 +- test/mjsunit/test-module-loading.js | 50 +- test/mjsunit/test-multipart.js | 14 +- test/mjsunit/test-process-buffering.js | 8 +- test/mjsunit/test-process-kill.js | 6 +- test/mjsunit/test-process-simple.js | 6 +- test/mjsunit/test-process-spawn-loop.js | 2 +- test/mjsunit/test-promise-cancel.js | 2 +- test/mjsunit/test-promise-timeout.js | 26 +- test/mjsunit/test-promise-wait.js | 48 +- test/mjsunit/test-readdir.js | 4 +- test/mjsunit/test-remote-module-loading.js | 4 +- test/mjsunit/test-signal-handler.js | 4 +- test/mjsunit/test-stat-handler.js | 4 +- test/mjsunit/test-tcp-binary.js | 4 +- test/mjsunit/test-tcp-many-clients.js | 6 +- test/mjsunit/test-tcp-pingpong-delay.js | 32 +- test/mjsunit/test-tcp-pingpong.js | 32 +- test/mjsunit/test-tcp-reconnect.js | 10 +- .../test-tcp-throttle-kernel-buffer.js | 6 +- test/mjsunit/test-tcp-throttle.js | 8 +- test/mjsunit/test-tcp-timeout.js | 14 +- test/mjsunit/test-tcp-tls.js | 40 +- test/mjsunit/test-timers.js | 14 +- test/mjsunit/test-umask.js | 2 +- test/mjsunit/test-utf8-scripts.js | 2 +- test/mjsunit/test-wait-ordering.js | 4 +- 55 files changed, 1516 insertions(+), 302 deletions(-) create mode 100644 lib/assert.js create mode 100644 lib/util.js diff --git a/lib/assert.js b/lib/assert.js new file mode 100644 index 0000000000..6f6f73df40 --- /dev/null +++ b/lib/assert.js @@ -0,0 +1,176 @@ +var sys = require('sys'); +var util = require('util'); +var assert = exports; + +assert.AssertionError = function (options) { + this.name = "AssertionError"; + this.message = options.message; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + + Error.captureStackTrace(this, fail); +}; +sys.inherits(assert.AssertionError, Error); + +// assert.AssertionError instanceof Error + +// assert.AssertionError.prototype = Object.create(Error.prototype); + +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. + +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. + +function fail(actual, expected, message, operator) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator + }); +} + +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. + +assert.ok = function (value, message) { + if (!!!value) + fail(value, true, message, "=="); +}; + +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); + +assert.equal = function (actual, expected, message) { + if (actual != expected) + fail(actual, expected, message, "=="); +}; + + +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); + +assert.notEqual = function (actual, expected, message) { + if (actual == expected) + fail(actual, expected, message, "!="); +}; + +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); + +exports.deepEqual = function (actual, expected, message) { + if (!deepEqual(actual, expected)) + fail(actual, expected, message, "deepEqual"); +}; + +function deepEqual(actual, expected) { + + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (actual instanceof Date + && expected instanceof Date) { + return actual.toValue() === expected.toValue(); + + // 7.3. Other pairs that do not both pass typeof value == "object", + // equivalence is determined by ==. + } else if (typeof actual != 'object' + && typeof expected != 'object') { + return actual == expected; + + // 7.4. For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical "prototype" property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return actual.prototype === expected.prototype && objEquiv(actual, expected); + } +} + +function objEquiv(a, b, stack) { + return ( + !util.no(a) && !util.no(b) && + arrayEquiv( + util.sort(util.object.keys(a)), + util.sort(util.object.keys(b)) + ) && + util.object.keys(a).every(function (key) { + return deepEqual(a[key], b[key], stack); + }) + ); +} + +function arrayEquiv(a, b, stack) { + return util.isArrayLike(b) && + a.length == b.length && + util.zip(a, b).every(util.apply(function (a, b) { + return deepEqual(a, b, stack); + })); +} + +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); + +exports.notDeepEqual = function (actual, expected, message) { + if (deepEqual(actual, expected)) + fail(actual, expected, message, "notDeepEqual"); +}; + +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); + +assert.strictEqual = function (actual, expected, message) { + if (actual !== expected) + fail(actual, expected, message, "==="); +}; + +// 10. The strict non-equality assertion tests for strict inequality, as determined by !==. +// assert.notStrictEqual(actual, expected, message_opt); + +assert.notStrictEqual = function (actual, expected, message) { + if (actual === expected) + fail(actual, expected, message, "!=="); +}; + +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); + +assert["throws"] = function (block, Error, message) { + var threw = false, + exception = null; + + if (typeof Error == "string") { + message = Error; + Error = undefined; + } else { + Error = message; + message = ""; + } + + try { + block(); + } catch (e) { + threw = true; + exception = e; + } + + if (!threw) + fail("Expected exception" + (message ? ": " + message : "")); +}; diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000000..18fe85087e --- /dev/null +++ b/lib/util.js @@ -0,0 +1,1033 @@ + +// a decorator for functions that curry "polymorphically", +// that is, that return a function that can be tested +// against various objects if they're only "partially +// completed", or fewer arguments than needed are used. +// +// this enables the idioms: +// [1, 2, 3].every(lt(4)) eq true +// [1, 2, 3].map(add(1)) eq [2, 3, 4] +// [{}, {}, {}].forEach(set('a', 10)) +// +exports.operator = function (name, length, block) { + var operator = function () { + var args = exports.array(arguments); + var completion = function (object) { + if ( + typeof object == "object" && + object !== null && // seriously? typeof null == "object" + name in object && // would throw if object === null + // not interested in literal objects: + !Object.prototype.hasOwnProperty.call(object, name) + ) + return object[name].apply(object, args); + return block.apply( + this, + [object].concat(args) + ); + }; + if (arguments.length < length) { + // polymoprhic curry, delayed completion + return completion; + } else { + // immediate completion + return completion.call(this, args.shift()); + } + }; + operator.name = name; + operator.displayName = name; + operator.length = length; + operator.operator = block; + return operator; +}; + +exports.no = function (value) { + return value === null || value === undefined; +}; + +// object + +exports.object = exports.operator('toObject', 1, function (object) { + var items = object; + if (!items.length) + items = exports.items(object); + var copy = {}; + for (var i = 0; i < items.length; i++) { + var item = items[i]; + var key = item[0]; + var value = item[1]; + copy[key] = value; + } + return copy; +}); + +exports.object.copy = function (object) { + var copy = {}; + exports.object.keys(object).forEach(function (key) { + copy[key] = object[key]; + }); + return copy; +}; + +exports.object.deepCopy = function (object) { + var copy = {}; + exports.object.keys(object).forEach(function (key) { + copy[key] = exports.deepCopy(object[key]); + }); + return copy; +}; + +exports.object.eq = function (a, b, stack) { + return ( + !exports.no(a) && !exports.no(b) && + exports.array.eq( + exports.sort(exports.object.keys(a)), + exports.sort(exports.object.keys(b)) + ) && + exports.object.keys(a).every(function (key) { + return exports.eq(a[key], b[key], stack); + }) + ); +}; + +exports.object.len = function (object) { + return exports.object.keys(object).length; +}; + +exports.object.has = function (object, key) { + return Object.prototype.hasOwnProperty.call(object, key); +}; + +exports.object.keys = function (object) { + var keys = []; + for (var key in object) { + if (exports.object.has(object, key)) + keys.push(key); + } + return keys; +}; + +exports.object.values = function (object) { + var values = []; + exports.object.keys(object).forEach(function (key) { + values.push(object[key]); + }); + return values; +}; + +exports.object.items = function (object) { + var items = []; + exports.object.keys(object).forEach(function (key) { + items.push([key, object[key]]); + }); + return items; +}; + +/** + * Updates an object with the properties from another object. + * This function is variadic requiring a minimum of two arguments. + * The first argument is the object to update. Remaining arguments + * are considered the sources for the update. If multiple sources + * contain values for the same property, the last one with that + * property in the arguments list wins. + * + * example usage: + * util.update({}, { hello: "world" }); // -> { hello: "world" } + * util.update({}, { hello: "world" }, { hello: "le monde" }); // -> { hello: "le monde" } + * + * @returns Updated object + * @type Object + * + */ +exports.object.update = function () { + return variadicHelper(arguments, function(target, source) { + var key; + for (key in source) { + if (exports.object.has(source, key)) { + target[key] = source[key]; + } + } + }); +}; + +exports.object.complete = function () { + return variadicHelper(arguments, function(target, source) { + var key; + for (key in source) { + if ( + exports.object.has(source, key) && + !exports.object.has(target, key) + ) { + target[key] = source[key]; + } + } + }); +}; + +exports.object.repr = function (object) { + return "{" + + exports.object.keys(object) + .map(function (key) { + return exports.enquote(key) + ": " + + exports.repr(object[key]); + }).join(", ") + + "}"; +}; + +/** + * @param args Arguments list of the calling function + * First argument should be a callback that takes target and source parameters. + * Second argument should be target. + * Remaining arguments are treated a sources. + * + * @returns Target + * @type Object + */ +var variadicHelper = function (args, callback) { + var sources = Array.prototype.slice.call(args); + var target = sources.shift(); + + sources.forEach(function(source) { + callback(target, source); + }); + + return target; +}; + +// array + +exports.array = function (array) { + if (exports.no(array)) + return []; + if (!exports.isArrayLike(array)) { + if ( + array.toArray && + !Object.prototype.hasOwnProperty.call(array, 'toArray') + ) { + return array.toArray(); + } else if ( + array.forEach && + !Object.prototype.hasOwnProperty.call(array, 'forEach') + ) { + var results = []; + array.forEach(function (value) { + results.push(value); + }); + return results; + } else { + return exports.items(array); + } + } + return Array.prototype.slice.call(array); +}; + +exports.array.coerce = function (array) { + if (!Array.isArray(array)) + return exports.array(array); + return array; +}; + +exports.isArrayLike = function(object) { + return Array.isArray(object) || exports.isArguments(object); +}; + +// from http://code.google.com/p/google-caja/wiki/NiceNeighbor +// by "kangax" +// +// Mark Miller posted a solution that will work in ES5 compliant +// implementations, that may provide future insight: +// (http://groups.google.com/group/narwhaljs/msg/116097568bae41c6) +exports.isArguments = function (object) { + // ES5 reliable positive + if (Object.prototype.toString.call(object) == "[object Arguments]") + return true; + // for ES5, we will still need a way to distinguish false negatives + // from the following code (in ES5, it is possible to create + // an object that satisfies all of these constraints but is + // not an Arguments object). + // callee should exist + if ( + !typeof object == "object" || + !Object.prototype.hasOwnProperty.call(object, 'callee') || + !object.callee || + // It should be a Function object ([[Class]] === 'Function') + Object.prototype.toString.call(object.callee) !== '[object Function]' || + typeof object.length != 'number' + ) + return false; + for (var name in object) { + // both "callee" and "length" should be { DontEnum } + if (name === 'callee' || name === 'length') return false; + } + return true; +}; + +exports.array.copy = exports.array; + +exports.array.deepCopy = function (array) { + return array.map(exports.deepCopy); +}; + +exports.array.len = function (array) { + return array.length; +}; + +exports.array.has = function (array, value) { + return Array.prototype.indexOf.call(array, value) >= 0; +}; + +exports.array.put = function (array, key, value) { + array.splice(key, 0, value); + return array; +}; + +exports.array.del = function (array, begin, end) { + array.splice(begin, end === undefined ? 1 : (end - begin)); + return array; +}; + +exports.array.eq = function (a, b, stack) { + return exports.isArrayLike(b) && + a.length == b.length && + exports.zip(a, b).every(exports.apply(function (a, b) { + return exports.eq(a, b, stack); + })); +}; + +exports.array.lt = function (a, b) { + var length = Math.max(a.length, b.length); + for (var i = 0; i < length; i++) + if (!exports.eq(a[i], b[i])) + return exports.lt(a[i], b[i]); + return false; +}; + +exports.array.repr = function (array) { + return "[" + exports.map(array, exports.repr).join(', ') + "]"; +}; + +exports.array.first = function (array) { + return array[0]; +}; + +exports.array.last = function (array) { + return array[array.length - 1]; +}; + +exports.apply = exports.operator('apply', 2, function (args, block) { + return block.apply(this, args); +}); + +exports.copy = exports.operator('copy', 1, function (object) { + if (exports.no(object)) + return object; + if (exports.isArrayLike(object)) + return exports.array.copy(object); + if (typeof object == 'object') + return exports.object.copy(object); + return object; +}); + +exports.deepCopy = exports.operator('deepCopy', 1, function (object) { + if (exports.no(object)) + return object; + if (exports.isArrayLike(object)) + return exports.array.deepCopy(object); + if (typeof object == 'object') + return exports.object.deepCopy(object); + return object; +}); + +exports.repr = exports.operator('repr', 1, function (object) { + if (exports.no(object)) + return String(object); + if (exports.isArrayLike(object)) + return exports.array.repr(object); + if (typeof object == 'object') + return exports.object.repr(object); + if (typeof object == 'string') + return exports.enquote(object); + return object.toString(); +}); + +exports.keys = exports.operator('keys', 1, function (object) { + if (exports.isArrayLike(object)) + return exports.range(object.length); + else if (typeof object == 'object') + return exports.object.keys(object); + return []; +}); + +exports.values = exports.operator('values', 1, function (object) { + if (exports.isArrayLike(object)) + return exports.array(object); + else if (typeof object == 'object') + return exports.object.values(object); + return []; +}); + +exports.items = exports.operator('items', 1, function (object) { + if (exports.isArrayLike(object) || typeof object == "string") + return exports.enumerate(object); + else if (typeof object == 'object') + return exports.object.items(object); + return []; +}); + +exports.len = exports.operator('len', 1, function (object) { + if (exports.isArrayLike(object)) + return exports.array.len(object); + else if (typeof object == 'object') + return exports.object.len(object); +}); + +exports.has = exports.operator('has', 2, function (object, value) { + if (exports.isArrayLike(object)) + return exports.array.has(object, value); + else if (typeof object == 'object') + return exports.object.has(object, value); + return false; +}); + +exports.get = exports.operator('get', 2, function (object, key, value) { + if (typeof object == "string") { + if (!typeof key == "number") + throw new Error("TypeError: String keys must be numbers"); + if (!exports.has(exports.range(object.length), key)) { + if (arguments.length == 3) + return value; + throw new Error("KeyError: " + exports.repr(key)); + } + return object.charAt(key); + } + if (typeof object == "object") { + if (!exports.object.has(object, key)) { + if (arguments.length == 3) + return value; + throw new Error("KeyError: " + exports.repr(key)); + } + return object[key]; + } + throw new Error("Object does not have keys: " + exports.repr(object)); +}); + +exports.set = exports.operator('set', 3, function (object, key, value) { + object[key] = value; + return object; +}); + +exports.getset = exports.operator('getset', 3, function (object, key, value) { + if (!exports.has(object, key)) + exports.set(object, key, value); + return exports.get(object, key); +}); + +exports.del = exports.operator('del', 2, function (object, begin, end) { + if (exports.isArrayLike(object)) + return exports.array.del(object, begin, end); + delete object[begin]; + return object; +}); + +exports.cut = exports.operator('cut', 2, function (object, key) { + var result = exports.get(object, key); + exports.del(object, key); + return result; +}); + +exports.put = exports.operator('put', 2, function (object, key, value) { + if (exports.isArrayLike(object)) + return exports.array.put(object, key, value); + return exports.set(object, key, value); +}); + +exports.first = exports.operator('first', 1, function (object) { + return object[0]; +}); + +exports.last = exports.operator('last', 1, function (object) { + return object[object.length - 1]; +}); + +exports.update = exports.operator('update', 2, function () { + var args = Array.prototype.slice.call(arguments); + return exports.object.update.apply(this, args); +}); + +exports.complete = exports.operator('complete', 2, function (target, source) { + var args = Array.prototype.slice.call(arguments); + return exports.object.complete.apply(this, args); +}); + +// TODO insert +// TODO remove +// TODO discard + +exports.range = function () { + var start = 0, stop = 0, step = 1; + if (arguments.length == 1) { + stop = arguments[0]; + } else { + start = arguments[0]; + stop = arguments[1]; + step = arguments[2] || 1; + } + var range = []; + for (var i = start; i < stop; i += step) + range.push(i); + return range; +}; + +exports.forEach = function (array, block) { + Array.prototype.forEach.call( + exports.array.coerce(array), + block + ); +}; + +exports.forEachApply = function (array, block) { + Array.prototype.forEach.call( + exports.array.coerce(array), + exports.apply(block) + ); +}; + +exports.map = function (array, block, context) { + return Array.prototype.map.call( + exports.array.coerce(array), + block, + context + ); +}; + +exports.mapApply = function (array, block) { + return Array.prototype.map.call( + exports.array.coerce(array), + exports.apply(block) + ); +}; + +exports.every = exports.operator('every', 2, function (array, block, context) { + return exports.all(exports.map(array, block, context)); +}); + +exports.some = exports.operator('some', 2, function (array, block, context) { + return exports.any(exports.map(array, block, context)); +}); + +exports.all = exports.operator('all', 1, function (array) { + array = exports.array.coerce(array); + for (var i = 0; i < array.length; i++) + if (!array[i]) + return false; + return true; +}); + +exports.any = exports.operator('all', 1, function (array) { + array = exports.array.coerce(array); + for (var i = 0; i < array.length; i++) + if (array[i]) + return true; + return false; +}); + +exports.reduce = exports.operator('reduce', 2, function (array, block, basis) { + array = exports.array.coerce(array); + return array.reduce.apply(array, arguments); +}); + +exports.reduceRight = exports.operator('reduceRight', 2, function (array, block, basis) { + array = exports.array.coerce(array); + return array.reduceRight.apply(array, arguments); +}); + +exports.zip = function () { + return exports.transpose(arguments); +}; + +exports.transpose = function (array) { + array = exports.array.coerce(array); + var transpose = []; + var length = Math.min.apply(this, exports.map(array, function (row) { + return row.length; + })); + for (var i = 0; i < array.length; i++) { + var row = array[i]; + for (var j = 0; j < length; j++) { + var cell = row[j]; + if (!transpose[j]) + transpose[j] = []; + transpose[j][i] = cell; + } + } + return transpose; +}; + +exports.enumerate = function (array, start) { + array = exports.array.coerce(array); + if (exports.no(start)) + start = 0; + return exports.zip( + exports.range(start, start + array.length), + array + ); +}; + +// arithmetic, transitive, and logical operators + +exports.is = function (a, b) { + return a === b; +}; + +exports.eq = exports.operator('eq', 2, function (a, b, stack) { + if (!stack) + stack = []; + if (a === b) + return true; + if (typeof a !== typeof b) + return false; + if (exports.no(a)) + return exports.no(b); + if (typeof a == "date") + return a.valueOf() == b.valueOf(); + if (typeof a == "regexp") + return a.source == b.source && + a.global == b.global && + a.ignoreCase == b.ignoreCase && + a.multiline == b.multiline; + if (typeof a == "function") { + var caller = stack[stack.length - 1]; + return caller !== Object && + typeof caller != "undefined"; + } + if (exports.isArrayLike(a)) + return exports.array.eq( + a, b, + stack.concat([a.constructor]) + ); + if (typeof a == 'object') + return exports.object.eq( + a, b, + stack.concat([a.constructor]) + ); + return a == b; +}); + +exports.ne = exports.operator('ne', 2, function (a, b) { + return !exports.eq(a, b); +}); + +exports.lt = exports.operator('lt', 2, function (a, b) { + if (exports.no(a) != exports.no(b)) + return exports.no(a) > exports.no(b); + if (exports.isArrayLike(a) && exports.isArrayLike(b)) + return exports.array.lt(a, b); + return a < b; +}); + +exports.gt = exports.operator('gt', 2, function (a, b) { + return !(exports.lt(a, b) || exports.eq(a, b)); +}); + +exports.le = exports.operator(2, 'le', function (a, b) { + return exports.lt(a, b) || exports.eq(a, b); +}); + +exports.ge = exports.operator(2, 'ge', function (a, b) { + return !exports.lt(a, b); +}); + +exports.mul = exports.operator(2, 'mul', function (a, b) { + if (typeof a == "string") + return exports.string.mul(a, b); + return a * b; +}); + +/*** by + returns a `comparator` that compares + values based on the values resultant from + a given `relation`. + accepts a `relation` and an optional comparator. + + To sort a list of objects based on their + "a" key:: + + objects.sort(by(get("a"))) + + To get those in descending order:: + + objects.sort(by(get("a")), desc) + + `by` returns a comparison function that also tracks + the arguments you used to construct it. This permits + `sort` and `sorted` to perform a Schwartzian transform + which can increase the performance of the sort + by a factor of 2. +*/ +exports.by = function (relation) { + var compare = arguments[1]; + if (exports.no(compare)) + compare = exports.compare; + var comparator = function (a, b) { + a = relation(a); + b = relation(b); + return compare(a, b); + }; + comparator.by = relation; + comparator.compare = compare; + return comparator; +}; + +exports.compare = exports.operator(2, 'compare', function (a, b) { + if (exports.no(a) != exports.no(b)) + return exports.no(b) - exports.no(a); + if (typeof a == "number" && typeof b == "number") + return a - b; + return exports.eq(a, b) ? 0 : exports.lt(a, b) ? -1 : 1; +}); + +/*** sort + an in-place array sorter that uses a deep comparison + function by default (compare), and improves performance if + you provide a comparator returned by "by", using a + Schwartzian transform. +*/ +exports.sort = function (array, compare) { + if (exports.no(compare)) + compare = exports.compare; + if (compare.by) { + /* schwartzian transform */ + array.splice.apply( + array, + [0, array.length].concat( + array.map(function (value) { + return [compare.by(value), value]; + }).sort(function (a, b) { + return compare.compare(a[0], b[0]); + }).map(function (pair) { + return pair[1]; + }) + ) + ); + } else { + array.sort(compare); + } + return array; +}; + +/*** sorted + returns a sorted copy of an array using a deep + comparison function by default (compare), and + improves performance if you provide a comparator + returned by "by", using a Schwartzian transform. +*/ +exports.sorted = function (array, compare) { + return exports.sort(exports.array.copy(array), compare); +}; + +exports.hash = exports.operator(1, 'hash', function (object) { + return '' + object; +}); + +exports.unique = exports.operator(1, 'unique', function (array, eq, hash) { + var visited = {}; + if (!eq) eq = exports.eq; + if (!hash) hash = exports.hash; + return array.filter(function (value) { + var bucket = exports.getset(visited, hash(value), []); + var finds = bucket.filter(function (other) { + return eq(value, other); + }); + if (!finds.length) + bucket.push(value); + return !finds.length; + }); +}); + +// string + +exports.string = exports.operator(1, 'toString', function (object) { + return '' + object; +}); + +exports.string.mul = function (string, n) { + return exports.range(n).map(function () { + return string; + }).join(''); +}; + +/*** escape + escapes all characters of a string that are + special to JavaScript and many other languages. + Recognizes all of the relevant + control characters and formats all other + non-printable characters as Hex byte escape + sequences or Unicode escape sequences depending + on their size. + + Pass ``true`` as an optional second argument and + ``escape`` produces valid contents for escaped + JSON strings, wherein non-printable-characters are + all escaped with the Unicode ``\u`` notation. +*/ +/* more Steve Levithan flagrence */ +var escapeExpression = /[^ !#-[\]-~]/g; +/* from Doug Crockford's JSON library */ +var escapePatterns = { + '\b': '\\b', '\t': '\\t', + '\n': '\\n', '\f': '\\f', '\r': '\\r', + '"' : '\\"', '\\': '\\\\' +}; +exports.escape = function (value, strictJson) { + if (typeof value != "string") + throw new Error( + module.path + + "#escape: requires a string. got " + + exports.repr(value) + ); + return value.replace( + escapeExpression, + function (match) { + if (escapePatterns[match]) + return escapePatterns[match]; + match = match.charCodeAt(); + if (!strictJson && match < 256) + return "\\x" + exports.padBegin(match.toString(16), 2); + return '\\u' + exports.padBegin(match.toString(16), 4); + } + ); +}; + +/*** enquote + transforms a string into a string literal, escaping + all characters of a string that are special to + JavaScript and and some other languages. + + ``enquote`` uses double quotes to be JSON compatible. + + Pass ``true`` as an optional second argument to + be strictly JSON compliant, wherein all + non-printable-characters are represented with + Unicode escape sequences. +*/ +exports.enquote = function (value, strictJson) { + return '"' + exports.escape(value, strictJson) + '"'; +}; + +/*** expand + transforms tabs to an equivalent number of spaces. +*/ +// TODO special case for \r if it ever matters +exports.expand = function (str, tabLength) { + str = String(str); + tabLength = tabLength || 4; + var output = [], + tabLf = /[\t\n]/g, + lastLastIndex = 0, + lastLfIndex = 0, + charsAddedThisLine = 0, + tabOffset, match; + while (match = tabLf.exec(str)) { + if (match[0] == "\t") { + tabOffset = ( + tabLength - 1 - + ( + (match.index - lastLfIndex) + + charsAddedThisLine + ) % tabLength + ); + charsAddedThisLine += tabOffset; + output.push( + str.slice(lastLastIndex, match.index) + + exports.mul(" ", tabOffset + 1) + ); + } else if (match[0] === "\n") { + output.push(str.slice(lastLastIndex, tabLf.lastIndex)); + lastLfIndex = tabLf.lastIndex; + charsAddedThisLine = 0; + } + lastLastIndex = tabLf.lastIndex; + } + return output.join("") + str.slice(lastLastIndex); +}; + +var trimBeginExpression = /^\s\s*/g; +exports.trimBegin = function (value) { + return String(value).replace(trimBeginExpression, ""); +}; + +var trimEndExpression = /\s\s*$/g; +exports.trimEnd = function (value) { + return String(value).replace(trimEndExpression, ""); +}; + +exports.trim = function (value) { + return String(value).replace(trimBeginExpression, "").replace(trimEndExpression, ""); +}; + +/* generates padBegin and padEnd */ +var augmentor = function (augment) { + return function (value, length, pad) { + if (exports.no(pad)) pad = '0'; + if (exports.no(length)) length = 2; + value = String(value); + while (value.length < length) { + value = augment(value, pad); + } + return value; + }; +}; + +/*** padBegin + + accepts: + - a `String` or `Number` value + - a minimum length of the resultant `String`: + by default, 2 + - a pad string: by default, ``'0'``. + + returns a `String` of the value padded up to at least + the minimum length. adds the padding to the begining + side of the `String`. + +*/ +exports.padBegin = augmentor(function (value, pad) { + return pad + value; +}); + +/*** padEnd + + accepts: + - a `String` or `Number` value + - a minimum length of the resultant `String`: + by default, 2 + - a pad string: by default, ``'0'``. + + returns a `String` of the value padded up to at least + the minimum length. adds the padding to the end + side of the `String`. + +*/ +exports.padEnd = augmentor(function (value, pad) { + return value + pad; +}); + +/*** splitName + splits a string into an array of words from an original + string. +*/ +// thanks go to Steve Levithan for this regular expression +// that, in addition to splitting any normal-form identifier +// in any case convention, splits XMLHttpRequest into +// "XML", "Http", and "Request" +var splitNameExpression = /[a-z]+|[A-Z](?:[a-z]+|[A-Z]*(?![a-z]))|[.\d]+/g; +exports.splitName = function (value) { + return String(value).match(splitNameExpression); +}; + +/*** joinName + joins a list of words with a given delimiter + between alphanumeric words. +*/ +exports.joinName = function (delimiter, parts) { + if (exports.no(delimiter)) delimiter = '_'; + parts.unshift([]); + return parts.reduce(function (parts, part) { + if ( + part.match(/\d/) && + exports.len(parts) && parts[parts.length-1].match(/\d/) + ) { + return parts.concat([delimiter + part]); + } else { + return parts.concat([part]); + } + }).join(''); +}; + +/*** upper + converts a name to ``UPPER CASE`` using + a given delimiter between numeric words. + + see: + - `lower` + - `camel` + - `title` + +*/ +exports.upper = function (value, delimiter) { + if (exports.no(delimiter)) + return value.toUpperCase(); + return exports.splitName(value).map(function (part) { + return part.toUpperCase(); + }).join(delimiter); +}; + +/*** lower + converts a name to a ``lower case`` using + a given delimiter between numeric words. + + see: + - `upper` + - `camel` + - `title` + +*/ +exports.lower = function (value, delimiter) { + if (exports.no(delimiter)) + return String(value).toLowerCase(); + return exports.splitName(value).map(function (part) { + return part.toLowerCase(); + }).join(delimiter); +}; + +/*** camel + converts a name to ``camel Case`` using + a given delimiter between numeric words. + + see: + - `lower` + - `upper` + - `title` + +*/ +exports.camel = function (value, delimiter) { + return exports.joinName( + delimiter, + exports.mapApply( + exports.enumerate(exports.splitName(value)), + function (n, part) { + if (n) { + return ( + part.substring(0, 1).toUpperCase() + + part.substring(1).toLowerCase() + ); + } else { + return part.toLowerCase(); + } + } + ) + ); +}; + +/*** title + converts a name to ``Title Case`` using + a given delimiter between numeric words. + + see: + - `lower` + - `upper` + - `camel` + +*/ +exports.title = function (value, delimiter) { + return exports.joinName( + delimiter, + exports.splitName(value).map(function (part) { + return ( + part.substring(0, 1).toUpperCase() + + part.substring(1).toLowerCase() + ); + }) + ); +}; + diff --git a/test/mjsunit/common.js b/test/mjsunit/common.js index 2874f3c9bd..29fe8f5d9d 100644 --- a/test/mjsunit/common.js +++ b/test/mjsunit/common.js @@ -6,10 +6,11 @@ exports.libDir = path.join(exports.testDir, "../../lib"); require.paths.unshift(exports.libDir); -var mjsunit = require("mjsunit"); +var assert = require('assert'); var sys = require("sys"); -process.mixin(exports, mjsunit, sys); +process.mixin(exports, sys); +exports.assert = require('assert'); exports.posix = require("posix"); exports.path = path; diff --git a/test/mjsunit/disabled/test-cat.js b/test/mjsunit/disabled/test-cat.js index 52304d2bbd..2ae15beaba 100644 --- a/test/mjsunit/disabled/test-cat.js +++ b/test/mjsunit/disabled/test-cat.js @@ -22,7 +22,7 @@ var successes = 0; var promise = process.cat("http://localhost:"+PORT, "utf8"); promise.addCallback(function (content) { - assertEquals(body, content); + assert.equal(body, content); server.close(); successes += 1; }); @@ -38,7 +38,7 @@ var x = process.path.join(fixtures, "x.txt"); promise = process.cat(x, "utf8"); promise.addCallback(function (content) { - assertEquals("xyz", content.replace(/[\r\n]/, '')); + assert.equal("xyz", content.replace(/[\r\n]/, '')); successes += 1; }); @@ -47,6 +47,6 @@ promise.addErrback(function () { }); process.addListener("exit", function () { - assertEquals(2, successes); - assertEquals(0, errors); + assert.equal(2, successes); + assert.equal(0, errors); }); diff --git a/test/mjsunit/disabled/test-http-stress.js b/test/mjsunit/disabled/test-http-stress.js index 203d9341f4..003d19fdd2 100644 --- a/test/mjsunit/disabled/test-http-stress.js +++ b/test/mjsunit/disabled/test-http-stress.js @@ -18,7 +18,7 @@ function onLoad () { for (var i = 0; i < request_count; i++) { process.http.cat('http://localhost:'+PORT+'/', 'utf8') .addCallback(function (content) { - assertEquals(response_body, content) + assert.equal(response_body, content) print("."); requests_ok++; requests_complete++; @@ -36,6 +36,6 @@ function onLoad () { } process.addListener("exit", function () { - assertEquals(request_count, requests_complete); - assertEquals(request_count, requests_ok); + assert.equal(request_count, requests_complete); + assert.equal(request_count, requests_ok); }); diff --git a/test/mjsunit/fixtures/b/c.js b/test/mjsunit/fixtures/b/c.js index 68d40bb1ea..b9a82e4569 100644 --- a/test/mjsunit/fixtures/b/c.js +++ b/test/mjsunit/fixtures/b/c.js @@ -1,10 +1,10 @@ var d = require("./d"); -var mjsunit = require("mjsunit"); +var assert = require("assert"); var package = require("./package"); -mjsunit.assertEquals("world", package.hello); +assert.equal("world", package.hello); debug("load fixtures/b/c.js"); diff --git a/test/mjsunit/test-buffered-file.js b/test/mjsunit/test-buffered-file.js index a065ec19b0..21a55ca11c 100644 --- a/test/mjsunit/test-buffered-file.js +++ b/test/mjsunit/test-buffered-file.js @@ -19,11 +19,11 @@ setTimeout(function () { var out = posix.cat(testTxt).wait(); print("the file contains: "); p(out); - assertEquals("hello\nworld\nhello\nworld\n", out); + assert.equal("hello\nworld\nhello\nworld\n", out); var file2 = new File(testTxt, "r"); file2.read(5).addCallback(function (data) { puts("read(5): " + JSON.stringify(data)); - assertEquals("hello", data); + assert.equal("hello", data); posix.unlink(testTxt).addCallback(function () { fileUnlinked = true; }); @@ -33,6 +33,6 @@ setTimeout(function () { }, 10); process.addListener("exit", function () { - assertTrue(fileUnlinked); + assert.equal(true, fileUnlinked); puts("done"); }); diff --git a/test/mjsunit/test-byte-length.js b/test/mjsunit/test-byte-length.js index 5f1ddcabc7..7cca37f969 100644 --- a/test/mjsunit/test-byte-length.js +++ b/test/mjsunit/test-byte-length.js @@ -1,11 +1,15 @@ process.mixin(require("./common")); -assertEquals(14, process._byteLength("Il était tué")); -assertEquals(14, process._byteLength("Il était tué", "utf8")); +assert.equal(14, process._byteLength("Il était tué")); +assert.equal(14, process._byteLength("Il était tué", "utf8")); -assertEquals(12, process._byteLength("Il était tué", "ascii")); +assert.equal(12, process._byteLength("Il était tué", "ascii")); -assertEquals(12, process._byteLength("Il était tué", "binary")); +assert.equal(12, process._byteLength("Il était tué", "binary")); -assertThrows('process._byteLength()'); -assertThrows('process._byteLength(5)'); \ No newline at end of file +assert.throws(function() { + process._byteLength(); +}); +assert.throws(function() { + process._byteLength(5); +}); \ No newline at end of file diff --git a/test/mjsunit/test-chdir.js b/test/mjsunit/test-chdir.js index 11a32c638f..bd7f065d1d 100644 --- a/test/mjsunit/test-chdir.js +++ b/test/mjsunit/test-chdir.js @@ -2,8 +2,8 @@ process.mixin(require("./common")); var dirname = path.dirname(__filename); -assertTrue(process.cwd() !== dirname); +assert.equal(true, process.cwd() !== dirname); process.chdir(dirname); -assertTrue(process.cwd() === dirname); +assert.equal(true, process.cwd() === dirname); diff --git a/test/mjsunit/test-delayed-require.js b/test/mjsunit/test-delayed-require.js index e13c82dca0..a9172687d6 100644 --- a/test/mjsunit/test-delayed-require.js +++ b/test/mjsunit/test-delayed-require.js @@ -5,7 +5,7 @@ setTimeout(function () { }, 50); process.addListener("exit", function () { - assertTrue("A" in a); - assertEquals("A", a.A()); - assertEquals("D", a.D()); + assert.equal(true, "A" in a); + assert.equal("A", a.A()); + assert.equal("D", a.D()); }); diff --git a/test/mjsunit/test-event-emitter-add-listeners.js b/test/mjsunit/test-event-emitter-add-listeners.js index 53fa8ee510..8668e6f730 100644 --- a/test/mjsunit/test-event-emitter-add-listeners.js +++ b/test/mjsunit/test-event-emitter-add-listeners.js @@ -13,8 +13,8 @@ e.addListener("newListener", function (event, listener) { e.addListener("hello", function (a, b) { puts("hello"); times_hello_emited += 1 - assertEquals("a", a); - assertEquals("b", b); + assert.equal("a", a); + assert.equal("b", b); }); puts("start"); @@ -22,8 +22,8 @@ puts("start"); e.emit("hello", "a", "b"); process.addListener("exit", function () { - assertArrayEquals(["hello"], events_new_listener_emited); - assertEquals(1, times_hello_emited); + assert.deepEqual(["hello"], events_new_listener_emited); + assert.equal(1, times_hello_emited); }); diff --git a/test/mjsunit/test-exception-handler.js b/test/mjsunit/test-exception-handler.js index 4a37769606..3fc82cfe5e 100644 --- a/test/mjsunit/test-exception-handler.js +++ b/test/mjsunit/test-exception-handler.js @@ -5,13 +5,13 @@ var caughtException = false; process.addListener('uncaughtException', function (e) { puts("uncaught exception! 1"); - assertEquals(MESSAGE, e.message); + assert.equal(MESSAGE, e.message); caughtException = true; }); process.addListener('uncaughtException', function (e) { puts("uncaught exception! 2"); - assertEquals(MESSAGE, e.message); + assert.equal(MESSAGE, e.message); caughtException = true; }); @@ -21,5 +21,5 @@ setTimeout(function() { process.addListener("exit", function () { puts("exit"); - assertTrue(caughtException); + assert.equal(true, caughtException); }); diff --git a/test/mjsunit/test-exec.js b/test/mjsunit/test-exec.js index 7a9cf8f005..2098fdfd67 100644 --- a/test/mjsunit/test-exec.js +++ b/test/mjsunit/test-exec.js @@ -18,13 +18,13 @@ exec("ls /").addCallback(function (out) { exec("ls /DOES_NOT_EXIST").addCallback(function (out) { success_count++; p(out); - assertTrue(out != ""); + assert.equal(true, out != ""); }).addErrback(function (code, out, err) { error_count++; - assertEquals("", out); - assertTrue(code != 0); + assert.equal("", out); + assert.equal(true, code != 0); puts("error!: " + code); puts("stdout: " + JSON.stringify(out)); @@ -33,6 +33,6 @@ exec("ls /DOES_NOT_EXIST").addCallback(function (out) { process.addListener("exit", function () { - assertEquals(1, success_count); - assertEquals(1, error_count); + assert.equal(1, success_count); + assert.equal(1, error_count); }); diff --git a/test/mjsunit/test-file-cat-noexist.js b/test/mjsunit/test-file-cat-noexist.js index 301cc937fb..fc0d4a43ce 100644 --- a/test/mjsunit/test-file-cat-noexist.js +++ b/test/mjsunit/test-file-cat-noexist.js @@ -7,7 +7,7 @@ var promise = posix.cat(filename, "raw"); promise.addCallback(function (content) { debug("cat returned some content: " + content); debug("this shouldn't happen as the file doesn't exist..."); - assertTrue(false); + assert.equal(true, false); }); promise.addErrback(function () { @@ -16,5 +16,5 @@ promise.addErrback(function () { process.addListener("exit", function () { puts("done"); - assertTrue(got_error); + assert.equal(true, got_error); }); diff --git a/test/mjsunit/test-fs-sendfile.js b/test/mjsunit/test-fs-sendfile.js index 70161fbf1c..93cac12ca2 100644 --- a/test/mjsunit/test-fs-sendfile.js +++ b/test/mjsunit/test-fs-sendfile.js @@ -12,7 +12,7 @@ var server = tcp.createServer(function (socket) { client.close(); socket.close(); server.close(); - assertEquals(expected, found); + assert.equal(expected, found); }); }); server.listen(PORT); @@ -21,7 +21,7 @@ var client = tcp.createConnection(PORT); client.addListener("connect", function () { posix.open(x,process.O_RDONLY, 0666).addCallback(function (fd) { posix.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) { - assertEquals(expected.length, size); + assert.equal(expected.length, size); }); }); }); diff --git a/test/mjsunit/test-fs-stat.js b/test/mjsunit/test-fs-stat.js index 14e155cfb7..37010b8d3b 100644 --- a/test/mjsunit/test-fs-stat.js +++ b/test/mjsunit/test-fs-stat.js @@ -22,33 +22,33 @@ posix.stat(__filename).addCallback(function (s) { success_count++; puts("isDirectory: " + JSON.stringify( s.isDirectory() ) ); - assertFalse(s.isDirectory()); + assert.equal(false, s.isDirectory()); puts("isFile: " + JSON.stringify( s.isFile() ) ); - assertTrue(s.isFile()); + assert.equal(true, s.isFile()); puts("isSocket: " + JSON.stringify( s.isSocket() ) ); - assertFalse(s.isSocket()); + assert.equal(false, s.isSocket()); puts("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) ); - assertFalse(s.isBlockDevice()); + assert.equal(false, s.isBlockDevice()); puts("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) ); - assertFalse(s.isCharacterDevice()); + assert.equal(false, s.isCharacterDevice()); puts("isFIFO: " + JSON.stringify( s.isFIFO() ) ); - assertFalse(s.isFIFO()); + assert.equal(false, s.isFIFO()); puts("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) ); - assertFalse(s.isSymbolicLink()); + assert.equal(false, s.isSymbolicLink()); }).addErrback(function () { got_error = true; }); process.addListener("exit", function () { - assertEquals(2, success_count); - assertFalse(got_error); - assertTrue(stats.mtime instanceof Date); + assert.equal(2, success_count); + assert.equal(false, got_error); + assert.equal(true, stats.mtime instanceof Date); }); diff --git a/test/mjsunit/test-fs-write.js b/test/mjsunit/test-fs-write.js index dd3c68e8ff..b2f7378b01 100644 --- a/test/mjsunit/test-fs-write.js +++ b/test/mjsunit/test-fs-write.js @@ -16,6 +16,6 @@ posix.open(fn, process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).addCa }); process.addListener("exit", function () { - assertEquals(expected, found); + assert.equal(expected, found); }); diff --git a/test/mjsunit/test-http-cat.js b/test/mjsunit/test-http-cat.js index 0f87630ea5..19ccab7266 100644 --- a/test/mjsunit/test-http-cat.js +++ b/test/mjsunit/test-http-cat.js @@ -20,7 +20,7 @@ var bad_server_got_error = false; http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) { puts("got response"); got_good_server_content = true; - assertEquals(body, content); + assert.equal(body, content); server.close(); }); @@ -31,6 +31,6 @@ http.cat("http://localhost:12312/", "utf8").addErrback(function () { process.addListener("exit", function () { puts("exit"); - assertTrue(got_good_server_content); - assertTrue(bad_server_got_error); + assert.equal(true, got_good_server_content); + assert.equal(true, bad_server_got_error); }); diff --git a/test/mjsunit/test-http-chunked.js b/test/mjsunit/test-http-chunked.js index 33ebda6f2a..d5a9a314a3 100644 --- a/test/mjsunit/test-http-chunked.js +++ b/test/mjsunit/test-http-chunked.js @@ -13,10 +13,10 @@ server.listen(PORT); http.cat("http://localhost:"+PORT+"/", "utf8") .addCallback(function (data) { - assertEquals(UTF8_STRING, data); + assert.equal(UTF8_STRING, data); server.close(); }) .addErrback(function() { - assertUnreachable('http.cat should succeed in < 1000ms'); + assert.ok(false, 'http.cat should succeed in < 1000ms'); }) .timeout(1000); \ No newline at end of file diff --git a/test/mjsunit/test-http-client-race.js b/test/mjsunit/test-http-client-race.js index 264ebca20c..eedd276881 100644 --- a/test/mjsunit/test-http-client-race.js +++ b/test/mjsunit/test-http-client-race.js @@ -37,6 +37,6 @@ client.get("/1").finish(function (res1) { }); process.addListener("exit", function () { - assertEquals(body1_s, body1); - assertEquals(body2_s, body2); + assert.equal(body1_s, body1); + assert.equal(body2_s, body2); }); diff --git a/test/mjsunit/test-http-client-upload.js b/test/mjsunit/test-http-client-upload.js index 4ee68b9306..5760664d31 100644 --- a/test/mjsunit/test-http-client-upload.js +++ b/test/mjsunit/test-http-client-upload.js @@ -7,7 +7,7 @@ var server_req_complete = false; var client_res_complete = false; var server = http.createServer(function(req, res) { - assertEquals("POST", req.method); + assert.equal("POST", req.method); req.setBodyEncoding("utf8"); req.addListener("body", function (chunk) { @@ -45,7 +45,7 @@ req.finish(function(res) { }); process.addListener("exit", function () { - assertEquals("1\n2\n3\n", sent_body); - assertTrue(server_req_complete); - assertTrue(client_res_complete); + assert.equal("1\n2\n3\n", sent_body); + assert.equal(true, server_req_complete); + assert.equal(true, client_res_complete); }); diff --git a/test/mjsunit/test-http-malformed-request.js b/test/mjsunit/test-http-malformed-request.js index ea492fa3ed..942b17fa0c 100644 --- a/test/mjsunit/test-http-malformed-request.js +++ b/test/mjsunit/test-http-malformed-request.js @@ -29,5 +29,5 @@ c.addListener("connect", function () { // TODO add more! process.addListener("exit", function () { - assertEquals(nrequests_expected, nrequests_completed); + assert.equal(nrequests_expected, nrequests_completed); }); diff --git a/test/mjsunit/test-http-proxy.js b/test/mjsunit/test-http-proxy.js index 5bd940bbe9..f575fab3ac 100644 --- a/test/mjsunit/test-http-proxy.js +++ b/test/mjsunit/test-http-proxy.js @@ -38,7 +38,7 @@ var req = client.get("/test"); // debug("client req") req.finish(function (res) { // debug("got res"); - assertEquals(200, res.statusCode); + assert.equal(200, res.statusCode); res.setBodyEncoding("utf8"); res.addListener("body", function (chunk) { body += chunk; }); res.addListener("complete", function () { @@ -49,5 +49,5 @@ req.finish(function (res) { }); process.addListener("exit", function () { - assertEquals(body, "hello world\n"); + assert.equal(body, "hello world\n"); }); diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index 39cb32cf2b..56e931844e 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -14,23 +14,23 @@ http.createServer(function (req, res) { req.id = request_number++; if (req.id == 0) { - assertEquals("GET", req.method); - assertEquals("/hello", req.uri.path); - assertEquals("world", req.uri.params["hello"]); - assertEquals("b==ar", req.uri.params["foo"]); + assert.equal("GET", req.method); + assert.equal("/hello", req.uri.path); + assert.equal("world", req.uri.params["hello"]); + assert.equal("b==ar", req.uri.params["foo"]); } if (req.id == 1) { - assertEquals("POST", req.method); - assertEquals("/quit", req.uri.path); + assert.equal("POST", req.method); + assert.equal("/quit", req.uri.path); } if (req.id == 2) { - assertEquals("foo", req.headers['x-x']); + assert.equal("foo", req.headers['x-x']); } if (req.id == 3) { - assertEquals("bar", req.headers['x-x']); + assert.equal("bar", req.headers['x-x']); this.close(); //puts("server closed"); } @@ -64,7 +64,7 @@ c.addListener("receive", function (chunk) { c.send("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); c.close(); - assertEquals(c.readyState, "readOnly"); + assert.equal(c.readyState, "readOnly"); requests_sent += 2; } @@ -75,18 +75,18 @@ c.addListener("eof", function () { }); c.addListener("close", function () { - assertEquals(c.readyState, "closed"); + assert.equal(c.readyState, "closed"); }); process.addListener("exit", function () { - assertEquals(4, request_number); - assertEquals(4, requests_sent); + assert.equal(4, request_number); + assert.equal(4, requests_sent); var hello = new RegExp("/hello"); - assertTrue(hello.exec(server_response) != null); + assert.equal(true, hello.exec(server_response) != null); var quit = new RegExp("/quit"); - assertTrue(quit.exec(server_response) != null); + assert.equal(true, quit.exec(server_response) != null); - assertTrue(client_got_eof); + assert.equal(true, client_got_eof); }); diff --git a/test/mjsunit/test-http-tls.js b/test/mjsunit/test-http-tls.js index dd85c150ee..0d80b9a91a 100644 --- a/test/mjsunit/test-http-tls.js +++ b/test/mjsunit/test-http-tls.js @@ -28,25 +28,25 @@ var keyPem = posix.cat(fixturesDir+"/test_key.pem").wait(); var http_server=http.createServer(function (req, res) { var verified = req.connection.verifyPeer(); var peerDN = req.connection.getPeerCertificate("DNstring"); - assertEquals(verified, 1); - assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + assert.equal(verified, 1); + assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); if (responses_sent == 0) { - assertEquals("GET", req.method); - assertEquals("/hello", req.uri.path); + assert.equal("GET", req.method); + assert.equal("/hello", req.uri.path); p(req.headers); - assertTrue("accept" in req.headers); - assertEquals("*/*", req.headers["accept"]); + assert.equal(true, "accept" in req.headers); + assert.equal("*/*", req.headers["accept"]); - assertTrue("foo" in req.headers); - assertEquals("bar", req.headers["foo"]); + assert.equal(true, "foo" in req.headers); + assert.equal("bar", req.headers["foo"]); } if (responses_sent == 1) { - assertEquals("POST", req.method); - assertEquals("/world", req.uri.path); + assert.equal("POST", req.method); + assert.equal("/world", req.uri.path); this.close(); } @@ -57,7 +57,7 @@ var http_server=http.createServer(function (req, res) { responses_sent += 1; }); - //assertEquals("127.0.0.1", res.connection.remoteAddress); + //assert.equal("127.0.0.1", res.connection.remoteAddress); }); http_server.setSecure("X509_PEM", caPem, 0, keyPem, certPem); http_server.listen(PORT); @@ -68,10 +68,10 @@ var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"}); req.finish(function (res) { var verified = res.connection.verifyPeer(); var peerDN = res.connection.getPeerCertificate("DNstring"); - assertEquals(verified, 1); - assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + assert.equal(verified, 1); + assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); - assertEquals(200, res.statusCode); + assert.equal(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("ascii"); res.addListener("body", function (chunk) { body0 += chunk; }); @@ -83,10 +83,10 @@ setTimeout(function () { req.finish(function (res) { var verified = res.connection.verifyPeer(); var peerDN = res.connection.getPeerCertificate("DNstring"); - assertEquals(verified, 1); - assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + assert.equal(verified, 1); + assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); - assertEquals(200, res.statusCode); + assert.equal(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("utf8"); res.addListener("body", function (chunk) { body1 += chunk; }); @@ -96,12 +96,12 @@ setTimeout(function () { process.addListener("exit", function () { debug("responses_recvd: " + responses_recvd); - assertEquals(2, responses_recvd); + assert.equal(2, responses_recvd); debug("responses_sent: " + responses_sent); - assertEquals(2, responses_sent); + assert.equal(2, responses_sent); - assertEquals("The path was /hello", body0); - assertEquals("The path was /world", body1); + assert.equal("The path was /hello", body0); + assert.equal("The path was /world", body1); }); diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index f71a0ee171..e41175f949 100644 --- a/test/mjsunit/test-http.js +++ b/test/mjsunit/test-http.js @@ -9,20 +9,20 @@ var body1 = ""; http.createServer(function (req, res) { if (responses_sent == 0) { - assertEquals("GET", req.method); - assertEquals("/hello", req.uri.path); + assert.equal("GET", req.method); + assert.equal("/hello", req.uri.path); p(req.headers); - assertTrue("accept" in req.headers); - assertEquals("*/*", req.headers["accept"]); + assert.equal(true, "accept" in req.headers); + assert.equal("*/*", req.headers["accept"]); - assertTrue("foo" in req.headers); - assertEquals("bar", req.headers["foo"]); + assert.equal(true, "foo" in req.headers); + assert.equal("bar", req.headers["foo"]); } if (responses_sent == 1) { - assertEquals("POST", req.method); - assertEquals("/world", req.uri.path); + assert.equal("POST", req.method); + assert.equal("/world", req.uri.path); this.close(); } @@ -33,13 +33,13 @@ http.createServer(function (req, res) { responses_sent += 1; }); - //assertEquals("127.0.0.1", res.connection.remoteAddress); + //assert.equal("127.0.0.1", res.connection.remoteAddress); }).listen(PORT); var client = http.createClient(PORT); var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"}); req.finish(function (res) { - assertEquals(200, res.statusCode); + assert.equal(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("ascii"); res.addListener("body", function (chunk) { body0 += chunk; }); @@ -49,7 +49,7 @@ req.finish(function (res) { setTimeout(function () { req = client.post("/world"); req.finish(function (res) { - assertEquals(200, res.statusCode); + assert.equal(200, res.statusCode); responses_recvd += 1; res.setBodyEncoding("utf8"); res.addListener("body", function (chunk) { body1 += chunk; }); @@ -59,12 +59,12 @@ setTimeout(function () { process.addListener("exit", function () { debug("responses_recvd: " + responses_recvd); - assertEquals(2, responses_recvd); + assert.equal(2, responses_recvd); debug("responses_sent: " + responses_sent); - assertEquals(2, responses_sent); + assert.equal(2, responses_sent); - assertEquals("The path was /hello", body0); - assertEquals("The path was /world", body1); + assert.equal("The path was /hello", body0); + assert.equal("The path was /world", body1); }); diff --git a/test/mjsunit/test-keep-alive.js b/test/mjsunit/test-keep-alive.js index e360f6ef16..1818630acb 100644 --- a/test/mjsunit/test-keep-alive.js +++ b/test/mjsunit/test-keep-alive.js @@ -43,19 +43,19 @@ function runAb(opts, callback) { runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { keepAliveReqSec = reqSec; - assertTrue(keepAliveRequests > 0); + assert.equal(true, keepAliveRequests > 0); puts("keep-alive: " + keepAliveReqSec + " req/sec"); runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) { normalReqSec = reqSec; - assertEquals(0, keepAliveRequests); + assert.equal(0, keepAliveRequests); puts("normal: " + normalReqSec + " req/sec"); server.close(); }); }); process.addListener("exit", function () { - assertTrue(normalReqSec > 50); - assertTrue(keepAliveReqSec > 50); - assertTrue(normalReqSec < keepAliveReqSec); + assert.equal(true, normalReqSec > 50); + assert.equal(true, keepAliveReqSec > 50); + assert.equal(true, normalReqSec < keepAliveReqSec); }); diff --git a/test/mjsunit/test-memory-usage.js b/test/mjsunit/test-memory-usage.js index 2da67f2667..8b9c55d1f4 100644 --- a/test/mjsunit/test-memory-usage.js +++ b/test/mjsunit/test-memory-usage.js @@ -2,5 +2,5 @@ process.mixin(require("./common")); var r = process.memoryUsage(); puts(inspect(r)); -assertTrue(r["rss"] > 0); -assertTrue(r["vsize"] > 0); +assert.equal(true, r["rss"] > 0); +assert.equal(true, r["vsize"] > 0); diff --git a/test/mjsunit/test-mkdir-rmdir.js b/test/mjsunit/test-mkdir-rmdir.js index f68afc0181..dfab84fcff 100644 --- a/test/mjsunit/test-mkdir-rmdir.js +++ b/test/mjsunit/test-mkdir-rmdir.js @@ -24,7 +24,7 @@ posix.mkdir(d, 0x666).addCallback(function () { }); process.addListener("exit", function () { - assertFalse(mkdir_error); - assertFalse(rmdir_error); + assert.equal(false, mkdir_error); + assert.equal(false, rmdir_error); puts("exit"); }); diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js index 7670837985..bba920b9bb 100644 --- a/test/mjsunit/test-module-loading.js +++ b/test/mjsunit/test-module-loading.js @@ -10,44 +10,44 @@ var d3 = require(require('path').dirname(__filename)+"/fixtures/b/d"); // Relative var d4 = require("../mjsunit/fixtures/b/d"); -assertFalse(false, "testing the test program."); +assert.equal(false, false, "testing the test program."); -assertInstanceof(a.A, Function); -assertEquals("A", a.A()); +assert.equal(true, a.A instanceof Function); +assert.equal("A", a.A()); -assertInstanceof(a.C, Function); -assertEquals("C", a.C()); +assert.equal(true, a.C instanceof Function); +assert.equal("C", a.C()); -assertInstanceof(a.D, Function); -assertEquals("D", a.D()); +assert.equal(true, a.D instanceof Function); +assert.equal("D", a.D()); -assertInstanceof(d.D, Function); -assertEquals("D", d.D()); +assert.equal(true, d.D instanceof Function); +assert.equal("D", d.D()); -assertInstanceof(d2.D, Function); -assertEquals("D", d2.D()); +assert.equal(true, d2.D instanceof Function); +assert.equal("D", d2.D()); -assertInstanceof(d3.D, Function); -assertEquals("D", d3.D()); +assert.equal(true, d3.D instanceof Function); +assert.equal("D", d3.D()); -assertInstanceof(d4.D, Function); -assertEquals("D", d4.D()); +assert.equal(true, d4.D instanceof Function); +assert.equal("D", d4.D()); process.addListener("exit", function () { - assertInstanceof(a.A, Function); - assertEquals("A done", a.A()); + assert.equal(true, a.A instanceof Function); + assert.equal("A done", a.A()); - assertInstanceof(a.C, Function); - assertEquals("C done", a.C()); + assert.equal(true, a.C instanceof Function); + assert.equal("C done", a.C()); - assertInstanceof(a.D, Function); - assertEquals("D done", a.D()); + assert.equal(true, a.D instanceof Function); + assert.equal("D done", a.D()); - assertInstanceof(d.D, Function); - assertEquals("D done", d.D()); + assert.equal(true, d.D instanceof Function); + assert.equal("D done", d.D()); - assertInstanceof(d2.D, Function); - assertEquals("D done", d2.D()); + assert.equal(true, d2.D instanceof Function); + assert.equal("D done", d2.D()); puts("exit"); }); diff --git a/test/mjsunit/test-multipart.js b/test/mjsunit/test-multipart.js index aca5efb2fb..ee41a665d9 100644 --- a/test/mjsunit/test-multipart.js +++ b/test/mjsunit/test-multipart.js @@ -18,9 +18,9 @@ var server = http.createServer(function(req, res) { var name = part.name; if (parts_reveived == 1) { - assertEquals('reply', name); + assert.equal('reply', name); } else if (parts_reveived == 2) { - assertEquals('fileupload', name); + assert.equal('fileupload', name); } parts[name] = ''; @@ -28,11 +28,11 @@ var server = http.createServer(function(req, res) { parts[name] += chunk; }); part.addListener('complete', function(chunk) { - assertEquals(0, part.buffer.length); + assert.equal(0, part.buffer.length); if (parts_reveived == 1) { - assertEquals('yes', parts[name]); + assert.equal('yes', parts[name]); } else if (parts_reveived == 2) { - assertEquals('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg', parts[name]); + assert.equal('/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg', parts[name]); } parts_complete++; }); @@ -54,6 +54,6 @@ request.finish(); process.addListener('exit', function() { puts("done"); - assertEquals(2, parts_complete); - assertEquals(2, parts_reveived); + assert.equal(2, parts_complete); + assert.equal(2, parts_reveived); }); diff --git a/test/mjsunit/test-process-buffering.js b/test/mjsunit/test-process-buffering.js index 6943d50d26..6c16c9bf61 100644 --- a/test/mjsunit/test-process-buffering.js +++ b/test/mjsunit/test-process-buffering.js @@ -11,7 +11,7 @@ function pwd (callback) { }); child.addListener("exit", function (c) { puts("exit: " + c); - assertEquals(0, c); + assert.equal(0, c); callback(output); pwd_called = true; }); @@ -20,10 +20,10 @@ function pwd (callback) { pwd(function (result) { p(result); - assertTrue(result.length > 1); - assertEquals("\n", result[result.length-1]); + assert.equal(true, result.length > 1); + assert.equal("\n", result[result.length-1]); }); process.addListener("exit", function () { - assertTrue(pwd_called); + assert.equal(true, pwd_called); }); diff --git a/test/mjsunit/test-process-kill.js b/test/mjsunit/test-process-kill.js index 995b809583..8d642f7e70 100644 --- a/test/mjsunit/test-process-kill.js +++ b/test/mjsunit/test-process-kill.js @@ -4,12 +4,12 @@ var exit_status = -1; var cat = process.createChildProcess("cat"); -cat.addListener("output", function (chunk) { assertEquals(null, chunk); }); -cat.addListener("error", function (chunk) { assertEquals(null, chunk); }); +cat.addListener("output", function (chunk) { assert.equal(null, chunk); }); +cat.addListener("error", function (chunk) { assert.equal(null, chunk); }); cat.addListener("exit", function (status) { exit_status = status; }); cat.kill(); process.addListener("exit", function () { - assertTrue(exit_status > 0); + assert.equal(true, exit_status > 0); }); diff --git a/test/mjsunit/test-process-simple.js b/test/mjsunit/test-process-simple.js index 2413cb7b6e..a4e58f1369 100644 --- a/test/mjsunit/test-process-simple.js +++ b/test/mjsunit/test-process-simple.js @@ -17,7 +17,7 @@ cat.addListener("output", function (chunk) { }); cat.addListener("error", function (chunk) { puts("stderr: " + JSON.stringify(chunk)); - assertEquals(null, chunk); + assert.equal(null, chunk); }); cat.addListener("exit", function (status) { puts("exit event"); @@ -29,6 +29,6 @@ cat.write(" "); cat.write("world"); process.addListener("exit", function () { - assertEquals(0, exit_status); - assertEquals("hello world", response); + assert.equal(0, exit_status); + assert.equal("hello world", response); }); diff --git a/test/mjsunit/test-process-spawn-loop.js b/test/mjsunit/test-process-spawn-loop.js index cc96a12af9..2453451a38 100644 --- a/test/mjsunit/test-process-spawn-loop.js +++ b/test/mjsunit/test-process-spawn-loop.js @@ -29,5 +29,5 @@ function spawn (i) { spawn(0); process.addListener("exit", function () { - assertTrue(finished); + assert.equal(true, finished); }); diff --git a/test/mjsunit/test-promise-cancel.js b/test/mjsunit/test-promise-cancel.js index 2009875213..7a84c7a4eb 100644 --- a/test/mjsunit/test-promise-cancel.js +++ b/test/mjsunit/test-promise-cancel.js @@ -4,7 +4,7 @@ var promise = new process.Promise(); var cancelled = false; promise.addCancelback(function(){ if(cancelled){ - assertUnreachable("promise should not cancel more than once"); + assert.ok(false, "promise should not cancel more than once"); } cancelled = true; }); diff --git a/test/mjsunit/test-promise-timeout.js b/test/mjsunit/test-promise-timeout.js index 8166a528d4..a6f253525e 100644 --- a/test/mjsunit/test-promise-timeout.js +++ b/test/mjsunit/test-promise-timeout.js @@ -4,15 +4,15 @@ var timeouts = 0; var promise = new process.Promise(); promise.timeout(250); -assertEquals(250, promise.timeout()); +assert.equal(250, promise.timeout()); promise.addCallback(function() { - assertUnreachable('addCallback should not fire after a promise error'); + assert.ok(false, 'addCallback should not fire after a promise error'); }); promise.addErrback(function(e) { - assertInstanceof(e, Error); - assertEquals('timeout', e.message); + assert.equal(true, e instanceof Error); + assert.equal('timeout', e.message); timeouts++; }); @@ -24,8 +24,8 @@ var waitPromise = new process.Promise(); try { waitPromise.timeout(250).wait() } catch (e) { - assertInstanceof(e, Error); - assertEquals('timeout', e.message); + assert.equal(true, e instanceof Error); + assert.equal('timeout', e.message); timeouts++; } @@ -36,7 +36,7 @@ setTimeout(function() { }, 250); successPromise.addErrback(function() { - assertUnreachable('addErrback should not fire if there is no timeout'); + assert.ok(false, 'addErrback should not fire if there is no timeout'); }); var errorPromise = new process.Promise(); @@ -46,8 +46,8 @@ setTimeout(function() { }, 250); errorPromise.addErrback(function(e) { - assertInstanceof(e, Error); - assertEquals('intentional', e.message); + assert.equal(true, e instanceof Error); + assert.equal('intentional', e.message); }); var cancelPromise = new process.Promise(); @@ -61,11 +61,11 @@ setTimeout(function() { }, 400); cancelPromise.addCallback(function(e) { - assertUnreachable('addCallback should not fire if the promise is canceled'); + assert.ok(false, 'addCallback should not fire if the promise is canceled'); }); cancelPromise.addErrback(function(e) { - assertUnreachable('addErrback should not fire if the promise is canceled'); + assert.ok(false, 'addErrback should not fire if the promise is canceled'); }); var cancelTimeoutPromise = new process.Promise(); @@ -75,9 +75,9 @@ setTimeout(function() { }, 250); cancelPromise.addErrback(function(e) { - assertUnreachable('addErrback should not fire after a cancel event'); + assert.ok(false, 'addErrback should not fire after a cancel event'); }); process.addListener('exit', function() { - assertEquals(2, timeouts); + assert.equal(2, timeouts); }); \ No newline at end of file diff --git a/test/mjsunit/test-promise-wait.js b/test/mjsunit/test-promise-wait.js index baba7c407c..37c8c4d6a8 100644 --- a/test/mjsunit/test-promise-wait.js +++ b/test/mjsunit/test-promise-wait.js @@ -3,8 +3,8 @@ process.mixin(require("./common")); var p1_done = false; var p1 = new process.Promise(); p1.addCallback(function () { - assertEquals(1, arguments.length); - assertEquals("single arg", arguments[0]); + assert.equal(1, arguments.length); + assert.equal("single arg", arguments[0]); p1_done = true; }); @@ -28,10 +28,10 @@ p3.addCallback(function () { var p4_done = false; var p4 = new process.Promise(); p4.addCallback(function () { - assertEquals(3, arguments.length); - assertEquals("a", arguments[0]); - assertEquals("b", arguments[1]); - assertEquals("c", arguments[2]); + assert.equal(3, arguments.length); + assert.equal("a", arguments[0]); + assert.equal("b", arguments[1]); + assert.equal("c", arguments[2]); p4_done = true; }); @@ -47,36 +47,36 @@ p5.addCallback(function () { p2.emitSuccess(); -assertFalse(p1_done); -assertTrue(p2_done); -assertFalse(p3_done); +assert.equal(false, p1_done); +assert.equal(true, p2_done); +assert.equal(false, p3_done); var ret1 = p1.wait() -assertEquals("single arg", ret1); +assert.equal("single arg", ret1); -assertTrue(p1_done); -assertTrue(p2_done); -assertFalse(p3_done); +assert.equal(true, p1_done); +assert.equal(true, p2_done); +assert.equal(false, p3_done); p3.emitSuccess(); -assertFalse(p4_done); -assertFalse(p5_done); +assert.equal(false, p4_done); +assert.equal(false, p5_done); p5.emitSuccess(); -assertFalse(p4_done); -assertTrue(p5_done); +assert.equal(false, p4_done); +assert.equal(true, p5_done); var ret4 = p4.wait(); -assertArrayEquals(["a","b","c"], ret4); +assert.deepEqual(["a","b","c"], ret4); -assertTrue(p4_done); +assert.equal(true, p4_done); process.addListener("exit", function () { - assertTrue(p1_done); - assertTrue(p2_done); - assertTrue(p3_done); - assertTrue(p4_done); - assertTrue(p5_done); + assert.equal(true, p1_done); + assert.equal(true, p2_done); + assert.equal(true, p3_done); + assert.equal(true, p4_done); + assert.equal(true, p5_done); }); diff --git a/test/mjsunit/test-readdir.js b/test/mjsunit/test-readdir.js index b866f2aea9..79af9a1721 100644 --- a/test/mjsunit/test-readdir.js +++ b/test/mjsunit/test-readdir.js @@ -7,7 +7,7 @@ puts("readdir " + fixturesDir); promise.addCallback(function (files) { p(files); - assertArrayEquals(["a.js", "b", "multipart.js", "test_ca.pem", "test_cert.pem", "test_key.pem", "x.txt"], files.sort()); + assert.deepEqual(["a.js", "b", "multipart.js", "test_ca.pem", "test_cert.pem", "test_key.pem", "x.txt"], files.sort()); }); promise.addErrback(function () { @@ -16,6 +16,6 @@ promise.addErrback(function () { }); process.addListener("exit", function () { - assertFalse(got_error); + assert.equal(false, got_error); puts("exit"); }); diff --git a/test/mjsunit/test-remote-module-loading.js b/test/mjsunit/test-remote-module-loading.js index 1ff7c280e3..198d472edf 100644 --- a/test/mjsunit/test-remote-module-loading.js +++ b/test/mjsunit/test-remote-module-loading.js @@ -17,7 +17,7 @@ var server = http.createServer(function(req, res) { server.listen(PORT); var httpModule = require('http://localhost:'+PORT+'/moduleA.js'); -assertEquals('/moduleA.js', httpModule.httpPath()); +assert.equal('/moduleA.js', httpModule.httpPath()); modulesLoaded++; var nodeBinary = process.ARGV[0]; @@ -34,5 +34,5 @@ sys }); process.addListener('exit', function() { - assertEquals(2, modulesLoaded); + assert.equal(2, modulesLoaded); }); diff --git a/test/mjsunit/test-signal-handler.js b/test/mjsunit/test-signal-handler.js index 5c277ba74a..5348bdd27d 100644 --- a/test/mjsunit/test-signal-handler.js +++ b/test/mjsunit/test-signal-handler.js @@ -29,6 +29,6 @@ setInterval(function () { process.addListener("exit", function () { - assertEquals(1, first); - assertEquals(1, second); + assert.equal(1, first); + assert.equal(1, second); }); diff --git a/test/mjsunit/test-stat-handler.js b/test/mjsunit/test-stat-handler.js index 3df1c5279e..4604c422df 100644 --- a/test/mjsunit/test-stat-handler.js +++ b/test/mjsunit/test-stat-handler.js @@ -11,7 +11,7 @@ var changes = 0; process.watchFile(f, function (curr, prev) { puts(f + " change"); changes++; - assertTrue(curr.mtime != prev.mtime); + assert.equal(true, curr.mtime != prev.mtime); process.unwatchFile(f); }); @@ -24,5 +24,5 @@ file.close().wait(); process.addListener("exit", function () { - assertTrue(changes > 0); + assert.equal(true, changes > 0); }); diff --git a/test/mjsunit/test-tcp-binary.js b/test/mjsunit/test-tcp-binary.js index b628c497ba..b91f2a6bce 100644 --- a/test/mjsunit/test-tcp-binary.js +++ b/test/mjsunit/test-tcp-binary.js @@ -60,7 +60,7 @@ c.addListener("close", function () { process.addListener("exit", function () { puts("recv: " + JSON.stringify(recv)); - assertEquals(2*256, recv.length); + assert.equal(2*256, recv.length); var a = recv.split(""); @@ -70,5 +70,5 @@ process.addListener("exit", function () { var second = a.slice(256,2*256).join(""); puts("second: " + JSON.stringify(second)); - assertEquals(first, second); + assert.equal(first, second); }); diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 2f18ad4c4a..0dfda16113 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/test/mjsunit/test-tcp-many-clients.js @@ -45,8 +45,8 @@ function runClient (callback) { client.addListener("close", function (had_error) { print("."); - assertFalse(had_error); - assertEquals(bytes, client.recved.length); + assert.equal(false, had_error); + assert.equal(bytes, client.recved.length); if (this.connections < connections_per_client) { this.connect(port); } else { @@ -64,6 +64,6 @@ for (var i = 0; i < concurrency; i++) { } process.addListener("exit", function () { - assertEquals(connections_per_client * concurrency, total_connections); + assert.equal(connections_per_client * concurrency, total_connections); puts("\nokay!"); }); diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index 8560e86c96..726ca7d8e8 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -15,30 +15,30 @@ function pingPongTest (port, host, on_complete) { socket.addListener("receive", function (data) { puts(data); - assertEquals("PING", data); - assertEquals("open", socket.readyState); - assertTrue(count <= N); + assert.equal("PING", data); + assert.equal("open", socket.readyState); + assert.equal(true, count <= N); setTimeout(function () { - assertEquals("open", socket.readyState); + assert.equal("open", socket.readyState); socket.send("PONG"); }, DELAY); }); socket.addListener("timeout", function () { debug("server-side timeout!!"); - assertFalse(true); + assert.equal(false, true); }); socket.addListener("eof", function () { puts("server-side socket EOF"); - assertEquals("writeOnly", socket.readyState); + assert.equal("writeOnly", socket.readyState); socket.close(); }); socket.addListener("close", function (had_error) { puts("server-side socket close"); - assertFalse(had_error); - assertEquals("closed", socket.readyState); + assert.equal(false, had_error); + assert.equal("closed", socket.readyState); socket.server.close(); }); }); @@ -49,17 +49,17 @@ function pingPongTest (port, host, on_complete) { client.setEncoding("utf8"); client.addListener("connect", function () { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); client.send("PING"); }); client.addListener("receive", function (data) { puts(data); - assertEquals("PONG", data); - assertEquals("open", client.readyState); + assert.equal("PONG", data); + assert.equal("open", client.readyState); setTimeout(function () { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); if (count++ < N) { client.send("PING"); } else { @@ -72,13 +72,13 @@ function pingPongTest (port, host, on_complete) { client.addListener("timeout", function () { debug("client-side timeout!!"); - assertFalse(true); + assert.equal(false, true); }); client.addListener("close", function () { puts("client close"); - assertEquals(N+1, count); - assertTrue(client_closed); + assert.equal(N+1, count); + assert.equal(true, client_closed); if (on_complete) on_complete(); tests_run += 1; }); @@ -87,5 +87,5 @@ function pingPongTest (port, host, on_complete) { pingPongTest(21988); process.addListener("exit", function () { - assertEquals(1, tests_run); + assert.equal(1, tests_run); }); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index df919bebe6..89d53295ec 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -10,12 +10,12 @@ function pingPongTest (port, host, on_complete) { var sent_final_ping = false; var server = tcp.createServer(function (socket) { - assertTrue(socket.remoteAddress !== null); - assertTrue(socket.remoteAddress !== undefined); + assert.equal(true, socket.remoteAddress !== null); + assert.equal(true, socket.remoteAddress !== undefined); if (host === "127.0.0.1") - assertEquals(socket.remoteAddress, "127.0.0.1"); + assert.equal(socket.remoteAddress, "127.0.0.1"); else if (host == null) - assertEquals(socket.remoteAddress, "127.0.0.1"); + assert.equal(socket.remoteAddress, "127.0.0.1"); socket.setEncoding("utf8"); socket.setNoDelay(); @@ -23,21 +23,21 @@ function pingPongTest (port, host, on_complete) { socket.addListener("receive", function (data) { puts("server got: " + JSON.stringify(data)); - assertEquals("open", socket.readyState); - assertTrue(count <= N); + assert.equal("open", socket.readyState); + assert.equal(true, count <= N); if (/PING/.exec(data)) { socket.send("PONG"); } }); socket.addListener("eof", function () { - assertEquals("writeOnly", socket.readyState); + assert.equal("writeOnly", socket.readyState); socket.close(); }); socket.addListener("close", function (had_error) { - assertFalse(had_error); - assertEquals("closed", socket.readyState); + assert.equal(false, had_error); + assert.equal("closed", socket.readyState); socket.server.close(); }); }); @@ -48,19 +48,19 @@ function pingPongTest (port, host, on_complete) { client.setEncoding("utf8"); client.addListener("connect", function () { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); client.send("PING"); }); client.addListener("receive", function (data) { - assertEquals("PONG", data); + assert.equal("PONG", data); count += 1; if (sent_final_ping) { - assertEquals("readOnly", client.readyState); + assert.equal("readOnly", client.readyState); return; } else { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); } if (count < N) { @@ -73,8 +73,8 @@ function pingPongTest (port, host, on_complete) { }); client.addListener("close", function () { - assertEquals(N+1, count); - assertTrue(sent_final_ping); + assert.equal(N+1, count); + assert.equal(true, sent_final_ping); if (on_complete) on_complete(); tests_run += 1; }); @@ -86,5 +86,5 @@ pingPongTest(20988, null); pingPongTest(20997, "::1"); process.addListener("exit", function () { - assertEquals(3, tests_run); + assert.equal(3, tests_run); }); diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index 96a383ad73..483283846e 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/test/mjsunit/test-tcp-reconnect.js @@ -18,7 +18,7 @@ var server = tcp.createServer(function (socket) { socket.addListener("close", function (had_error) { //puts("server had_error: " + JSON.stringify(had_error)); - assertFalse(had_error); + assert.equal(false, had_error); }); }); server.listen(port); @@ -34,13 +34,13 @@ client.addListener("connect", function () { client.addListener("receive", function (chunk) { client_recv_count += 1; puts("client_recv_count " + client_recv_count); - assertEquals("hello\r\n", chunk); + assert.equal("hello\r\n", chunk); client.close(); }); client.addListener("close", function (had_error) { puts("disconnect"); - assertFalse(had_error); + assert.equal(false, had_error); if (disconnect_count++ < N) client.connect(port); // reconnect else @@ -48,6 +48,6 @@ client.addListener("close", function (had_error) { }); process.addListener("exit", function () { - assertEquals(N+1, disconnect_count); - assertEquals(N+1, client_recv_count); + assert.equal(N+1, disconnect_count); + assert.equal(N+1, client_recv_count); }); diff --git a/test/mjsunit/test-tcp-throttle-kernel-buffer.js b/test/mjsunit/test-tcp-throttle-kernel-buffer.js index cf632e98b9..9548fa8a36 100644 --- a/test/mjsunit/test-tcp-throttle-kernel-buffer.js +++ b/test/mjsunit/test-tcp-throttle-kernel-buffer.js @@ -37,7 +37,7 @@ client.addListener("receive", function (d) { puts("pause"); x = chars_recved; setTimeout(function () { - assertEquals(chars_recved, x); + assert.equal(chars_recved, x); client.readResume(); puts("resume"); paused = false; @@ -51,6 +51,6 @@ client.addListener("eof", function () { }); process.addListener("exit", function () { - assertEquals(N, chars_recved); - assertTrue(npauses > 2); + assert.equal(N, chars_recved); + assert.equal(true, npauses > 2); }); diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index 020e7c577f..2e1e7ac201 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/test/mjsunit/test-tcp-throttle.js @@ -32,11 +32,11 @@ client.addListener("receive", function (d) { setTimeout(function () { chars_recved = recv.length; puts("pause at: " + chars_recved); - assertTrue(chars_recved > 1); + assert.equal(true, chars_recved > 1); client.readPause(); setTimeout(function () { puts("resume at: " + chars_recved); - assertEquals(chars_recved, recv.length); + assert.equal(chars_recved, recv.length); client.readResume(); setTimeout(function () { @@ -46,7 +46,7 @@ setTimeout(function () { setTimeout(function () { puts("resume at: " + chars_recved); - assertEquals(chars_recved, recv.length); + assert.equal(chars_recved, recv.length); client.readResume(); }, 500); @@ -63,6 +63,6 @@ client.addListener("eof", function () { }); process.addListener("exit", function () { - assertEquals(N, recv.length); + assert.equal(N, recv.length); debug("Exit"); }); diff --git a/test/mjsunit/test-tcp-timeout.js b/test/mjsunit/test-tcp-timeout.js index ba76846b09..617b529ff7 100644 --- a/test/mjsunit/test-tcp-timeout.js +++ b/test/mjsunit/test-tcp-timeout.js @@ -37,7 +37,7 @@ client.addListener("connect", function () { }); client.addListener("receive", function (chunk) { - assertEquals("hello\r\n", chunk); + assert.equal("hello\r\n", chunk); if (exchanges++ < 5) { setTimeout(function () { puts("client send 'hello'"); @@ -54,7 +54,7 @@ client.addListener("receive", function (chunk) { client.addListener("timeout", function () { puts("client timeout - this shouldn't happen"); - assertFalse(true); + assert.equal(false, true); }); client.addListener("eof", function () { @@ -65,16 +65,16 @@ client.addListener("eof", function () { client.addListener("close", function (had_error) { puts("client disconnect"); echo_server.close(); - assertFalse(had_error); + assert.equal(false, had_error); }); process.addListener("exit", function () { - assertTrue(starttime != null); - assertTrue(timeouttime != null); + assert.equal(true, starttime != null); + assert.equal(true, timeouttime != null); diff = timeouttime - starttime; puts("diff = " + diff); - assertTrue(timeout < diff); + assert.equal(true, timeout < diff); // Allow for 800 milliseconds more - assertTrue(diff < timeout + 800); + assert.equal(true, diff < timeout + 800); }); diff --git a/test/mjsunit/test-tcp-tls.js b/test/mjsunit/test-tcp-tls.js index 1da3e733e8..f4abc6890b 100644 --- a/test/mjsunit/test-tcp-tls.js +++ b/test/mjsunit/test-tcp-tls.js @@ -10,12 +10,12 @@ function tlsTest (port, host, caPem, keyPem, certPem) { var sent_final_ping = false; var server = tcp.createServer(function (socket) { - assertTrue(socket.remoteAddress !== null); - assertTrue(socket.remoteAddress !== undefined); + assert.equal(true, socket.remoteAddress !== null); + assert.equal(true, socket.remoteAddress !== undefined); if (host === "127.0.0.1") - assertEquals(socket.remoteAddress, "127.0.0.1"); + assert.equal(socket.remoteAddress, "127.0.0.1"); else if (host == null) - assertEquals(socket.remoteAddress, "127.0.0.1"); + assert.equal(socket.remoteAddress, "127.0.0.1"); socket.setEncoding("utf8"); socket.setNoDelay(); @@ -24,25 +24,25 @@ function tlsTest (port, host, caPem, keyPem, certPem) { socket.addListener("receive", function (data) { var verified = socket.verifyPeer(); var peerDN = socket.getPeerCertificate("DNstring"); - assertEquals(verified, 1); - assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + assert.equal(verified, 1); + assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); puts("server got: " + JSON.stringify(data)); - assertEquals("open", socket.readyState); - assertTrue(count <= N); + assert.equal("open", socket.readyState); + assert.equal(true, count <= N); if (/PING/.exec(data)) { socket.send("PONG"); } }); socket.addListener("eof", function () { - assertEquals("writeOnly", socket.readyState); + assert.equal("writeOnly", socket.readyState); socket.close(); }); socket.addListener("close", function (had_error) { - assertFalse(had_error); - assertEquals("closed", socket.readyState); + assert.equal(false, had_error); + assert.equal("closed", socket.readyState); socket.server.close(); }); }); @@ -56,26 +56,26 @@ function tlsTest (port, host, caPem, keyPem, certPem) { client.setSecure('X509_PEM', caPem, 0, keyPem, caPem); client.addListener("connect", function () { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); var verified = client.verifyPeer(); var peerDN = client.getPeerCertificate("DNstring"); - assertEquals(verified, 1); - assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + assert.equal(verified, 1); + assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); client.send("PING"); }); client.addListener("receive", function (data) { - assertEquals("PONG", data); + assert.equal("PONG", data); count += 1; puts("client got PONG"); if (sent_final_ping) { - assertEquals("readOnly", client.readyState); + assert.equal("readOnly", client.readyState); return; } else { - assertEquals("open", client.readyState); + assert.equal("open", client.readyState); } if (count < N) { @@ -88,8 +88,8 @@ function tlsTest (port, host, caPem, keyPem, certPem) { }); client.addListener("close", function () { - assertEquals(N+1, count); - assertTrue(sent_final_ping); + assert.equal(N+1, count); + assert.equal(true, sent_final_ping); tests_run += 1; }); } @@ -114,7 +114,7 @@ if (have_tls) { tlsTest(21443, null, caPem, keyPem, certPem); process.addListener("exit", function () { - assertEquals(2, tests_run); + assert.equal(2, tests_run); }); } else { puts("Not compiled with TLS support."); diff --git a/test/mjsunit/test-timers.js b/test/mjsunit/test-timers.js index 827164a046..37d5a0dc82 100644 --- a/test/mjsunit/test-timers.js +++ b/test/mjsunit/test-timers.js @@ -5,7 +5,7 @@ var WINDOW = 200; // why is does this need to be so big? var interval_count = 0; var setTimeout_called = false; -assertInstanceof(setTimeout, Function); +assert.equal(true, setTimeout instanceof Function); var starttime = new Date; setTimeout(function () { @@ -15,12 +15,12 @@ setTimeout(function () { if (diff < 0) diff = -diff; puts("diff: " + diff); - assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW); + assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW); setTimeout_called = true; }, 1000); // this timer shouldn't execute -var id = setTimeout(function () { assertTrue(false); }, 500); +var id = setTimeout(function () { assert.equal(true, false); }, 500); clearTimeout(id); setInterval(function () { @@ -33,14 +33,14 @@ setInterval(function () { var t = interval_count * 1000; - assertTrue(t - WINDOW < diff && diff < t + WINDOW); + assert.equal(true, t - WINDOW < diff && diff < t + WINDOW); - assertTrue(interval_count <= 3); + assert.equal(true, interval_count <= 3); if (interval_count == 3) clearInterval(this); }, 1000); process.addListener("exit", function () { - assertTrue(setTimeout_called); - assertEquals(3, interval_count); + assert.equal(true, setTimeout_called); + assert.equal(3, interval_count); }); diff --git a/test/mjsunit/test-umask.js b/test/mjsunit/test-umask.js index 1ac9578877..0309a8eadd 100644 --- a/test/mjsunit/test-umask.js +++ b/test/mjsunit/test-umask.js @@ -3,4 +3,4 @@ process.mixin(require("./common")); var mask = 0664; var old = process.umask(mask); -assertEquals(true, mask === process.umask(old)); +assert.equal(true, mask === process.umask(old)); diff --git a/test/mjsunit/test-utf8-scripts.js b/test/mjsunit/test-utf8-scripts.js index 9ad2159f3b..a8f2e96332 100644 --- a/test/mjsunit/test-utf8-scripts.js +++ b/test/mjsunit/test-utf8-scripts.js @@ -4,5 +4,5 @@ process.mixin(require("./common")); puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη"); -assertTrue( /Hellö Wörld/.test("Hellö Wörld") ); +assert.equal(true, /Hellö Wörld/.test("Hellö Wörld") ); diff --git a/test/mjsunit/test-wait-ordering.js b/test/mjsunit/test-wait-ordering.js index d1276a56de..537ad24d8f 100644 --- a/test/mjsunit/test-wait-ordering.js +++ b/test/mjsunit/test-wait-ordering.js @@ -15,12 +15,12 @@ function test_timeout_order(delay, desired_order) { timer(0).addCallback(function() { timer(delay).wait() var b = new Date(); - assertTrue(b - a >= delay); + assert.equal(true, b - a >= delay); order++; // A stronger assertion would be that the ordering is correct. // With Poor Man's coroutines we cannot guarentee that. // Replacing wait() with actual coroutines would solve that issue. - // assertEquals(desired_order, order); + // assert.equal(desired_order, order); }); } test_timeout_order(10, 6); // Why does this have the proper order??