Browse files

Fixed problem with node assert module when executing in a new context.

Updated test cases to run in the should framework.
  • Loading branch information...
1 parent 88e94ce commit d0cb80a43360fcea170518b0397418ae4448c916 @lukebayes committed Feb 20, 2011
View
23 src/node_should/assert.js
@@ -241,19 +241,11 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
};
function expectedException(actual, expected) {
- //console.log('------------------------');
- //console.log(">> expectedException with actual: " + actual + " and expected: " + expected);
- //console.log(">> actual: " + actual + " type: " + typeof(actual));
- //console.log(">> expected: " + expected + " type: " + typeof(expected));
- //console.log(">> expected is regex?: " + (expected instanceof RegExp));
-
if (!actual || !expected) {
return false;
}
- //console.log(">> passed one");
-
- if (expected instanceof RegExp) {
+ if (typeof(expected['test']) == "function") {
return expected.test(actual);
} else if (actual instanceof expected) {
return true;
@@ -308,3 +300,16 @@ assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
};
assert.ifError = function(err) { if (err) {throw err;}};
+
+assert.match = function(regexp, string) {
+ if(!string.match(regexp)) {
+ assert.fail('Unable to match ' + regexp + ' in: ' + string);
+ }
+}
+
+assert.same = function(expected, actual) {
+ if(expected !== actual) {
+ assert.fail('Expected (' + expected + ') does not reference the same object as (' + actual +')');
+ }
+}
+
View
2 src/node_should/context.js
@@ -211,7 +211,7 @@ Context.prototype._callHandler = function(handlerData, options) {
//console.log("-----------------");
//console.log(e);
- if (e instanceof AssertionError) {
+ if (e.name == 'AssertionError') {
if (failureLabel) {
e.message = failureLabel + '\n' + e.toString();
}
View
9 src/node_should/printer.js
@@ -269,10 +269,13 @@ Printer.prototype._printDurationDetails = function() {
}
});
-
+ var count = 10;
+ self._printInfo('Printing 10 slowest test methods:\n\n');
items.forEach(function(test) {
- var durationLabel = self._insertLeadingSpaces(test.duration, 6);
- self._printInfo(durationLabel + ' ms : ' + test.label + '\n');
+ if (count-- > 0) {
+ var durationLabel = self._insertLeadingSpaces(test.duration, 6);
+ self._printInfo(durationLabel + ' ms : ' + test.label + '\n');
+ }
});
}
}
View
6 test/common.js
@@ -1,9 +1,9 @@
// This file found in nodejs test module, but added minor modifications here.
var path = require('path');
-var assert = require('assert');
-require('assert_match');
-require('assert_same');
+var assert = require('node_should/assert');
+//require('assert_match');
+//require('assert_same');
exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
View
58 test/unit/array_iterator_test.js
@@ -14,36 +14,34 @@ context('ArrayIterator', function() {
itr.next();
}, /no more items/);
});
-});
-/*
-(function iteratorLoopsOverThreeChildren() {
- var itr = new ArrayIterator(['a', 'b', 'c']);
- assert.ok(itr.hasNext());
- assert.equal('a', itr.next());
- assert.ok(itr.hasNext());
- assert.equal('b', itr.next());
- assert.ok(itr.hasNext());
- assert.equal('c', itr.next());
-
- assert.ok(!itr.hasNext());
- assert.throws(function() {
+ should('loop over three children', function() {
+ var itr = new ArrayIterator(['a', 'b', 'c']);
+ assert.ok(itr.hasNext());
+ assert.equal('a', itr.next());
+ assert.ok(itr.hasNext());
+ assert.equal('b', itr.next());
+ assert.ok(itr.hasNext());
+ assert.equal('c', itr.next());
+
+ assert.ok(!itr.hasNext());
+ assert.throws(function() {
+ itr.next();
+ }, /no more items/);
+ });
+
+ should('return next item from peek', function() {
+ var itr = new ArrayIterator(['a', 'b']);
+ assert.equal('a', itr.peek());
+ itr.next();
+ assert.equal('b', itr.peek());
itr.next();
- }, /no more items/);
-})();
-
-(function peekReturnsNextItem() {
- var itr = new ArrayIterator(['a', 'b']);
- assert.equal('a', itr.peek());
- itr.next();
- assert.equal('b', itr.peek());
- itr.next();
-
- assert.ok(!itr.hasNext());
-
- assert.throws(function() {
- itr.peek();
- }, /no more items/);
-})();
-*/
+
+ assert.ok(!itr.hasNext());
+
+ assert.throws(function() {
+ itr.peek();
+ }, /no more items/);
+ });
+});
View
193 test/unit/composite_test.js
@@ -0,0 +1,193 @@
+
+var Composite = require('node_should/composite').Composite;
+var LabelComposite = require('label_composite').LabelComposite;
+require('common');
+
+context('A new Composite', function() {
+
+ should('be instantiable', function() {
+ var root = new Composite();
+ });
+
+ context('with addChild', function() {
+
+ should('accept children', function() {
+ var child = new Composite();
+ var root = new Composite();
+ root.addChild(child);
+ });
+
+ should('fail with null', function() {
+ var root = new Composite();
+ assert.throws(function() {
+ root.addChild(null);
+ }, /requires a child/);
+ });
+
+ should('update numChildren', function() {
+ var child = new Composite();
+ var root = new Composite();
+ root.addChild(child);
+ assert.equal(1, root.numChildren);
+ });
+
+ should('update child.parent reference', function() {
+ var child = new Composite();
+ var root = new Composite();
+ assert.ok(child.parent == null);
+ root.addChild(child);
+ assert.same(root, child.parent);
+ });
+ });
+
+ context('with getChildAt', function() {
+
+ should('require a number', function() {
+ var root = new Composite();
+ assert.throws(function() {
+ root.getChildAt(null);
+ }, /must be a number/);
+ });
+
+ should('require a number greater than zero', function() {
+ var root = new Composite();
+ assert.throws(function() {
+ root.getChildAt(-1);
+ }, /greater than zero/);
+ });
+
+ should('require a number less than num children', function() {
+ var root = new Composite();
+ root.addChild(new Composite());
+ assert.throws(function() {
+ root.getChildAt(1);
+ }, /less than numChildren/);
+ });
+
+ should('return requested child', function() {
+ var child1 = new Composite();
+ var child2 = new Composite();
+ var root = new Composite();
+ root.addChild(child1);
+ root.addChild(child2);
+ assert.equal(2, root.numChildren);
+ assert.same(child1, root.getChildAt(0));
+ assert.same(child2, root.getChildAt(1));
+ });
+ });
+
+ context('getChildren', function() {
+ should('return children', function() {
+ var child1 = new Composite();
+ var child2 = new Composite();
+ var root = new Composite();
+ root.addChild(child1);
+ root.addChild(child2);
+ var children = root.getChildren();
+ assert.equal(2, children.length);
+ assert.same(child1, children[0]);
+ assert.same(child2, children[1]);
+ });
+ });
+
+ context('removeChildAt', function() {
+
+ should('decrement numChildren', function() {
+ var child1 = new Composite();
+ var child2 = new Composite();
+ var root = new Composite();
+ root.addChild(child1);
+ root.addChild(child2);
+ var result = root.removeChildAt(0);
+ assert.same(child1, result);
+ assert.same(child2, root.getChildAt(0));
+ });
+ });
+
+ context('with iterator', function() {
+
+ should('enumerate children', function() {
+ var root = new Composite();
+ var child = new Composite();
+ root.addChild(child);
+
+ var itr = root.iterator();
+ assert.ok(itr.hasNext());
+
+ assert.same(child, itr.next());
+ assert.ok(!itr.hasNext());
+
+ assert.throws(function() {
+ itr.next();
+ }, /no more items/);
+ });
+
+ should('enumerate three children', function() {
+ var root = new Composite();
+ var child1 = new Composite();
+ var child2 = new Composite();
+ var child3 = new Composite();
+ root.addChild(child1);
+ root.addChild(child2);
+ root.addChild(child3);
+
+ var itr = root.iterator();
+ assert.ok(itr.hasNext());
+ assert.same(child1, itr.next());
+ assert.ok(itr.hasNext());
+ assert.same(child2, itr.next());
+ assert.ok(itr.hasNext());
+ assert.same(child3, itr.next());
+
+ assert.ok(!itr.hasNext());
+ assert.throws(function() {
+ itr.next();
+ }, /no more items/);
+ });
+
+ should('enumerate composite', function() {
+ var root = new Composite();
+ var child1 = new Composite();
+ var child2 = new Composite();
+ var child3 = new Composite();
+
+ root.addChild(child1);
+ child1.addChild(child2);
+ root.addChild(child3);
+
+ var itr = root.iterator();
+
+ assert.ok(itr.hasNext());
+ assert.strictEqual(child1, itr.next());
+ assert.ok(itr.hasNext());
+ assert.strictEqual(child2, itr.next());
+ assert.ok(itr.hasNext());
+ assert.strictEqual(child3, itr.next());
+ });
+
+ should('enumerate deep composite', function() {
+ var root = new LabelComposite('root');
+ var child1 = new LabelComposite('child1');
+ var child2 = new LabelComposite('child2');
+ var child3 = new LabelComposite('child3');
+ var child4 = new LabelComposite('child4');
+ var child5 = new LabelComposite('child5');
+ var child6 = new LabelComposite('child6');
+
+ root.addChild(child1);
+ root.addChild(child2);
+ root.addChild(child3);
+ child2.addChild(child4);
+ child4.addChild(child5);
+
+ var actualItem = null;
+ var itr = root.iterator();
+ [child1, child2, child4, child5, child3].forEach(function(expectedItem) {
+ assert.ok(itr.hasNext(), 'Failed to haveNext on: ' + expectedItem);
+ actualItem = itr.next();
+ assert.strictEqual(expectedItem, actualItem);
+ });
+ });
+ });
+});
+
View
368 test/unit/context_test.js
@@ -0,0 +1,368 @@
+
+var Context = require('node_should/context').Context;
+require('common');
+
+context('A new Context', function() {
+
+ should('be instantiable', function() {
+ var c = new Context();
+ });
+
+ should('inherit from Composite', function() {
+ var c = new Context();
+ c.addChild(new Context());
+ assert.equal(1, c.numChildren);
+ });
+
+ context('label', function() {
+
+ should('accept empty string', function() {
+ var c = new Context();
+ assert.equal('', c.getLabel());
+ });
+
+ should('accept any string', function() {
+ var c = new Context('root');
+ assert.equal('root', c.getLabel());
+ });
+
+ should('build from composite', function() {
+ var root = new Context('SomeClass');
+ var child1 = new Context('with child');
+ root.addChild(child1);
+
+ assert.equal('SomeClass with child', child1.getLabel());
+ });
+
+ should('build from composite, ignoring null child labels', function() {
+ var root = new Context('SomeClass');
+ var child1 = new Context();
+ root.addChild(child1);
+
+ assert.equal('SomeClass', child1.getLabel());
+ });
+
+ should('build from composite, ignoring null root label', function() {
+ var root = new Context();
+ var child1 = new Context('SomeClass');
+ root.addChild(child1);
+
+ assert.equal('SomeClass', child1.getLabel());
+ });
+ });
+
+ context('setup handler', function() {
+
+ should('fail with null handler', function() {
+ var c = new Context();
+ assert.throws(function() {
+ c.addSetupHandler();
+ }, /must not be null/);
+ });
+
+ should('accept function', function() {
+ var c = new Context();
+ c.addSetupHandler(function() {});
+ });
+
+ should('grab parent setups', function() {
+ var executed = [];
+ var parent = new Context('SomeParent');
+ parent.addSetupHandler(function() {
+ executed.push('parentsetup');
+ this.param = {};
+ });
+ parent.addTeardownHandler(function() {
+ executed.push('parentteardwon');
+ });
+ var child = new Context('with a child');
+ child.addSetupHandler(function() {
+ executed.push('childsetup');
+ this.param.name = 'childvalue';
+ });
+ child.addTeardownHandler(function() {
+ executed.push('childteardown');
+ });
+ child.addTestHandler('do something', function() {
+ executed.push('testmethod1');
+ assert.equal(this.param.name, 'childvalue');
+ });
+ child.addTestHandler('do something else', function() {
+ executed.push('testmethod2');
+ });
+
+ parent.addChild(child);
+ child.execute();
+ assert.equal(10, executed.length);
+ assert.equal('parentsetup', executed[0]);
+ });
+ });
+
+ context('teardown handler', function() {
+
+ should('fail with null handler', function() {
+ var c = new Context();
+ assert.throws(function() {
+ c.addTeardownHandler();
+ }, /must not be null/);
+ });
+
+ should('accept function', function() {
+ var c = new Context();
+ c.addTeardownHandler(function() {});
+ });
+ });
+
+ context('test handler', function() {
+
+ should('fail with null handler', function() {
+ var c = new Context();
+ assert.throws(function() {
+ c.addTestHandler();
+ }, /must not be null/);
+ });
+
+ should('accept function', function() {
+ var c = new Context();
+ c.addTestHandler(function() {});
+ });
+ });
+
+ context('execution', function() {
+
+ should('fail if no tests', function() {
+ var c = new Context();
+ assert.throws(function() {
+ c.execute();
+ }, /no tests/);
+ });
+
+ should('run setup, then tests, then teardowns', function() {
+ var executed = [];
+ var c = new Context('SomeClass');
+ c.addSetupHandler(function() {
+ executed.push('setup');
+ });
+ c.addTestHandler(function() {
+ executed.push('test');
+ });
+ c.addTeardownHandler(function() {
+ executed.push('teardown');
+ });
+ c.execute();
+
+ var expected = ['setup', 'test', 'teardown'];
+ assert.equal(expected.length, executed.length);
+ assert.equal(expected[0], executed[0]);
+ assert.equal(expected[1], executed[1]);
+ assert.equal(expected[2], executed[2]);
+ });
+
+ should('run handlers in shared scope', function() {
+ var c = new Context('SomeClass');
+ c.addSetupHandler(function() {
+ this.foo = 'bar';
+ });
+ c.addTestHandler(function() {
+ assert.equal(this.foo, 'bar');
+ });
+ c.execute();
+ });
+
+ should('call setups for each test method', function() {
+ var executed = [];
+ var c = new Context('SomeClass');
+ c.addSetupHandler(function() { executed.push('setup1'); });
+ c.addSetupHandler(function() { executed.push('setup2'); });
+ c.addTestHandler(function() { executed.push('test1') });
+ c.addTestHandler(function() { executed.push('test2') });
+ c.addTestHandler(function() { executed.push('test3') });
+ c.addTestHandler(function() { executed.push('test4') });
+ c.addTeardownHandler(function() { executed.push('teardown1'); });
+ c.addTeardownHandler(function() { executed.push('teardown2'); });
+ c.execute();
+
+ assert.equal(20, executed.length);
+ });
+
+ should('use different scope for different test methods', function() {
+ var firstScope = null;
+ var secondScope = null;
+ var c = new Context();
+ c.addTestHandler(function() { firstScope = this });
+ c.addTestHandler(function() { secondScope = this });
+ c.execute();
+ assert.notStrictEqual(firstScope, secondScope);
+ });
+
+ should('run setup asynchronously, if requested', function() {
+ var executed = [];
+ var c = new Context();
+ c.addSetupHandler(function() {
+ var asyncHandler = this.async(function() {
+ executed.push('asyncsetup');
+ });
+ setTimeout(asyncHandler, 0);
+ });
+ c.addTestHandler(function() {
+ executed.push('test');
+ });
+ c.execute(function() {
+ assert.equal(2, executed.length);
+ assert.equal('asyncsetup', executed[0]);
+ assert.equal('test', executed[1]);
+ });
+ });
+
+ should('run tests asynchronously, if requested', function() {
+ var executed = [];
+ var c = new Context();
+ c.addSetupHandler(function() {
+ setTimeout(this.async(function() {
+ executed.push('asyncsetup');
+ }), 0);
+ });
+ c.addTestHandler(function() {
+ setTimeout(this.async(function() {
+ executed.push('asynctest1');
+ }), 0);
+ // TODO(lukebayes) Problem with async tests:
+ // Make the previous line:
+ //}), 500);
+ // This fails!!!!!
+ });
+ c.addTestHandler(function() {
+ setTimeout(this.async(function() {
+ executed.push('asynctest2');
+ }), 0);
+ });
+ c.addTeardownHandler(function() {
+ setTimeout(this.async(function() {
+ executed.push('asyncteardown');
+ }), 0);
+ });
+
+ c.execute(function() {
+ assert.equal(6, executed.length);
+ });
+ });
+
+ should('capture runtime errors', function() {
+ var error = null;
+ var c = new Context('SomeClass');
+ c.addListener('error', function(test) {
+ error = test.error;
+ });
+ c.addTestHandler('do something', function() {
+ throw 'unknown application error';
+ });
+ c.execute();
+ assert.match(/SomeClass should do something/, error.toString());
+ assert.match(/unknown application error/, error.toString());
+ });
+
+ should('capture assertion exceptions', function() {
+ var failure = null;
+ var c = new Context();
+ c.addListener('failure', function(f) {
+ failure = f;
+ });
+
+ c.addTestHandler(function() {
+ assert.ok(false, 'should be false');
+ });
+
+ c.execute();
+ assert.ok(failure);
+ });
+
+ should('capture async errors', function() {
+ var failure = null;
+ var c = new Context();
+ c.addListener('failure', function(f) {
+ failure = f;
+ });
+ c.addTestHandler(function() {
+ setTimeout(this.async(function() {
+ assert.ok(false, 'should be false');
+ }), 0);
+ });
+ c.execute(function() {
+ assert.ok(failure);
+ });
+ });
+
+ should('include helpful label on setup error', function() {
+ var error = null;
+ var c = new Context('OtherClass');
+ c.addListener('error', function(test) {
+ error = test.error;
+ });
+ c.addSetupHandler(function() {
+ throw 'unknown setup error';
+ });
+ c.addTestHandler('do something', function() {});
+ c.execute();
+ assert.match(/OtherClass should do something \(setup\)/, error.toString());
+ });
+
+ should('handle multiple asyncs in same call', function() {
+ var executed = [];
+ var c = new Context();
+ c.addTestHandler(function() {
+ setTimeout(this.async(function() {
+ executed.push('one');
+ }), 0);
+ setTimeout(this.async(function() {
+ executed.push('two');
+ }), 0);
+ setTimeout(this.async(function() {
+ executed.push('three');
+ }), 0);
+ });
+
+ c.execute(function() {
+ assert.equal(3, executed.length);
+ assert.equal(executed[0], 'one');
+ assert.equal(executed[1], 'two');
+ assert.equal(executed[2], 'three');
+ });
+ });
+ });
+
+ context('failure', function() {
+
+ should('display helpful message', function() {
+ var c = new Context('SomeClass');
+ c.addTestHandler('accept argument', function() {
+ assert.ok(false);
+ });
+ c.addListener('failure', function(test) {
+ assert.match(/SomeClass should accept argument/, test.failure.message);
+ });
+ c.execute();
+ });
+
+ should('create default label', function() {
+ var c = new Context('SomeClass');
+ c.addTestHandler(function() {
+ assert.ok(false);
+ });
+ c.addListener('failure', function(test) {
+ assert.match(/SomeClass/, test.failure.stack);
+ });
+ c.execute();
+ });
+
+ should('work with throws assertion failures', function() {
+ var composite = new Context('SomeClass');
+ composite.addTestHandler(function() {
+ assert.throws(function() {
+ throw 'hello world';
+ }, /hello world/);
+ });
+ composite.execute();
+ });
+ });
+});
+
View
287 test/unit/printer_test.js
@@ -0,0 +1,287 @@
+
+require('common');
+var Printer = require('node_should').Printer;
+var Context = require('node_should').Context;
+var FakePrinter = require('fake_printer').FakePrinter;
+
+context('printer', function() {
+
+ should('be instantiable', function() {
+ assert.ok(new Printer() != null);
+ });
+
+ should('display start text', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ assert.equal("'Node Should' by Luke Bayes\n\n", p.out.message);
+ });
+
+ should('not allow start to be called > once', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ assert.throws(function() {
+ p.start();
+ }, /start already/);
+ });
+
+ should('not allow tests without first calling start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ assert.throws(function() {
+ p._testSuccessHandler();
+ }, /must be preceeded by start/);
+ });
+
+ should('allow success after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p.finish();
+
+ assert.match(/^\./gm, p.out.message);
+ assert.equal(1, p.length);
+ });
+
+ should('allow success multiple times', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p.finish();
+
+ var message = p.out.message;
+ assert.match(/^\.\.\.\./gm, message);
+ assert.match(/Test Count: 4, OK: 4, Failures: 0, Errors: 0, Ignored: 0/, message);
+ assert.equal(4, p.length);
+ });
+
+ should('only allow failure after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ assert.throws(function() {
+ p._testFailureHandler();
+ }, /must be preceeded by start/);
+ });
+
+ should('allow failure after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ try {
+ assert.fail(null, 'fake actual value', 'fake expected value', '!=', 'foo');
+ } catch (failure) {
+ p._testFailureHandler({failure: failure});
+ }
+ p.finish();
+
+ var message = p.out.message;
+
+ assert.equal(1, p.length);
+ assert.match(/^F/gm, message);
+ assert.match(/Test Count: 1, OK: 0, Failures: 1, Errors: 0, Ignored: 0/, message);
+ assert.match(/printer_test.js/, message);
+ });
+
+ should('work with multiple calls', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p._testFailureHandler();
+ p._testSuccessHandler();
+ p._testFailureHandler();
+ p._testFailureHandler();
+ p._testSuccessHandler();
+ p.finish();
+
+ var message = p.out.message;
+ assert.equal(7, p.length);
+ assert.match(/^\.\.F\.FF\./gm, message);
+ assert.match(/Test Count: 7, OK: 4, Failures: 3, Errors: 0, Ignored: 0/, message);
+ });
+
+ should('only allow errors after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ assert.throws(function() {
+ p._testErrorHandler();
+ }, /must be preceeded by start/);
+ });
+
+ should('allow errors after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ try {
+ throw new Error('fake error');
+ } catch (err) {
+ p._testErrorHandler({error: err});
+ }
+ p.finish();
+
+ var message = p.out.message;
+ assert.match(/^E/gm, message);
+ assert.match(/Test Count: 1, OK: 0, Failures: 0, Errors: 1, Ignored: 0/, message);
+ assert.match(/fake error/, message);
+ assert.equal(1, p.length);
+ });
+
+ should('allow errors with multiple calls', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p._testFailureHandler();
+ p._testSuccessHandler();
+
+ p._testErrorHandler();
+
+ p._testFailureHandler();
+ p._testFailureHandler();
+
+ p._testErrorHandler();
+ p._testSuccessHandler();
+ p.finish();
+
+ var message = p.out.message;
+ assert.match(/^\.\.F\.EFFE\./gm, message);
+ assert.equal(9, p.length);
+ });
+
+ should('only allow ignore after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ assert.throws(function() {
+ p.testIgnoreHandler();
+ }, /must be preceeded by start/);
+ });
+
+ should('allow ignore after start', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p.testIgnoreHandler();
+ p.finish();
+
+ var message = p.out.message;
+ assert.match(/^I/gm, message);
+ assert.equal(1, p.length);
+ });
+
+ should('allow ignore with multiple calls', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p._testFailureHandler();
+ p._testSuccessHandler();
+
+ p.testIgnoreHandler({message: 'ignore message a'});
+
+ p._testFailureHandler();
+ p._testFailureHandler();
+
+ p.testIgnoreHandler({message: 'ignore message b'});
+ p._testSuccessHandler();
+ p.finish();
+
+ var message = p.out.message;
+ assert.match(/^\.\.F\.IFFI\./gm, message);
+ assert.match(/Test Count: 9, OK: 4, Failures: 3, Errors: 0, Ignored: 2/, message);
+ assert.match(/ignore message a/, message);
+ assert.equal(9, p.length);
+ });
+
+ should('only allow finish if started', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ assert.throws(function() {
+ p.finish();
+ });
+ });
+
+ should('only allow finish if at least one result', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ assert.throws(function() {
+ p.finish();
+ });
+ });
+
+ should('allow finish after start and a test', function() {
+ var p = new FakePrinter();
+ //p.out = process.stdout;
+ p.start();
+ p._testSuccessHandler();
+ p.finish();
+ assert.equal(1, p.length);
+
+ var message = p.out.message;
+ assert.match(/Total Time: \d ms/, message);
+ assert.match(/Test Count: 1, OK: 1, Failures: 0, Errors: 0, Ignored: 0/, message);
+ });
+
+ should('display durations', function() {
+ var p = new FakePrinter();
+ p.start();
+ p._testSuccessHandler({label: 'abcd', duration: 1});
+ p._testSuccessHandler({label: 'efgh', duration: 87});
+ p._testSuccessHandler({label: 'mnop', duration: 34});
+ p._testSuccessHandler({label: 'ijkl', duration: 34});
+ p._testSuccessHandler({label: 'qrst', duration: 242});
+ p._testSuccessHandler();
+ p._testSuccessHandler();
+ p.finish();
+
+ var message = p.out.message;
+ //console.log(message);
+
+ // Ensure that the list is present, AND sorted:
+ assert.match(/ 242 ms : qrst.*\n.*efgh/gm, message);
+ assert.match(/ 87 ms : efgh.*\n.*mnop/gm, message);
+ assert.match(/ 34 ms : mnop.*\n.*ijkl/gm, message);
+ assert.match(/ 34 ms : ijkl.*\n.*abcd/gm, message);
+ assert.match(/ 1 ms : abcd/gm, message);
+ });
+
+ should('accept failing context', function() {
+ var c = new Context('SomeClass');
+ c.addTestHandler('should do something', function() {
+ assert.ok(false, 'expected failure!');
+ });
+
+ var p = new FakePrinter();
+ p.start();
+ p.addContext(c);
+ c.execute();
+ p.finish();
+ var message = p.out.message;
+ assert.match(/Test Count: 1, OK: 0, Failures: 1, Errors: 0, Ignored: 0/, message);
+ });
+
+ should('accept passing context', function() {
+ var c = new Context('SomeClass');
+ c.addTestHandler('should do something', function() {
+ assert.ok(true);
+ });
+
+ var p = new FakePrinter();
+ p.start();
+ p.addContext(c);
+ c.execute();
+ p.finish();
+ var message = p.out.message;
+ assert.match(/Test Count: 1, OK: 1, Failures: 0, Errors: 0, Ignored: 0/, message);
+ });
+});
+
View
21 test/unit/runner_test.js
@@ -0,0 +1,21 @@
+
+require('common');
+var Runner = require('node_should/runner').Runner;
+var FakePrinter = require('fake_printer').FakePrinter;
+
+context('A new Runner', function() {
+
+ should('be instantiable', function() {
+ var r = new Runner();
+ });
+
+ should('load specified files', function() {
+ var printer = new FakePrinter();
+ var r = new Runner();
+ r.run(/first.js/, 'test/fixtures', [printer], function() {
+ //console.log(printer.out.message);
+ assert.match(/OK: 2/, printer.out.message);
+ });
+ });
+});
+
View
45 test/unit/test_array_iterator.js
@@ -1,45 +0,0 @@
-
-var assert = require('assert');
-require('../common');
-var ArrayIterator = require('node_should/array_iterator').ArrayIterator;
-
-(function iteratorLoopsOverOneChild() {
- var itr = new ArrayIterator(['a']);
- assert.ok(itr.hasNext());
- assert.equal('a', itr.next());
-
- assert.ok(!itr.hasNext());
- assert.throws(function() {
- itr.next();
- }, /no more items/);
-})();
-
-(function iteratorLoopsOverThreeChildren() {
- var itr = new ArrayIterator(['a', 'b', 'c']);
- assert.ok(itr.hasNext());
- assert.equal('a', itr.next());
- assert.ok(itr.hasNext());
- assert.equal('b', itr.next());
- assert.ok(itr.hasNext());
- assert.equal('c', itr.next());
-
- assert.ok(!itr.hasNext());
- assert.throws(function() {
- itr.next();
- }, /no more items/);
-})();
-
-(function peekReturnsNextItem() {
- var itr = new ArrayIterator(['a', 'b']);
- assert.equal('a', itr.peek());
- itr.next();
- assert.equal('b', itr.peek());
- itr.next();
-
- assert.ok(!itr.hasNext());
-
- assert.throws(function() {
- itr.peek();
- }, /no more items/);
-})();
-
View
177 test/unit/test_composite.js
@@ -1,177 +0,0 @@
-
-var Composite = require('node_should/composite').Composite;
-var LabelComposite = require('label_composite').LabelComposite;
-var assert = require('assert');
-
-require('../common');
-
-(function isInstantiable() {
- var root = new Composite();
-})();
-
-(function canAddChild() {
- var child = new Composite();
- var root = new Composite();
- root.addChild(child);
-})();
-
-(function addChildFailsWithNullChild() {
- var root = new Composite();
- assert.throws(function() {
- root.addChild(null);
- }, /requires a child/);
-})();
-
-(function addChildUpdatesNumChildren() {
- var child = new Composite();
- var root = new Composite();
- root.addChild(child);
- assert.equal(1, root.numChildren);
-})();
-
-(function getChildAtRequiresANumber() {
- var root = new Composite();
- assert.throws(function() {
- root.getChildAt(null);
- }, /must be a number/);
-})();
-
-(function getChildAtRequiresANumberGreaterThanZero() {
- var root = new Composite();
- assert.throws(function() {
- root.getChildAt(-1);
- }, /greater than zero/);
-})();
-
-(function getChildAtRequiresANumberLessThanNumChildren() {
- var root = new Composite();
- root.addChild(new Composite());
- assert.throws(function() {
- root.getChildAt(1);
- }, /less than numChildren/);
-})();
-
-(function getChildAtReturnsAddedChild() {
- var child1 = new Composite();
- var child2 = new Composite();
- var root = new Composite();
- root.addChild(child1);
- root.addChild(child2);
- assert.equal(2, root.numChildren);
- assert.same(child1, root.getChildAt(0));
- assert.same(child2, root.getChildAt(1));
-})();
-
-(function getChildrenReturnsChildren() {
- var child1 = new Composite();
- var child2 = new Composite();
- var root = new Composite();
- root.addChild(child1);
- root.addChild(child2);
- var children = root.getChildren();
- assert.equal(2, children.length);
- assert.same(child1, children[0]);
- assert.same(child2, children[1]);
-})();
-
-(function removeChildAtDecrementsNumChildren() {
- var child1 = new Composite();
- var child2 = new Composite();
- var root = new Composite();
- root.addChild(child1);
- root.addChild(child2);
- var result = root.removeChildAt(0);
- assert.same(child1, result);
- assert.same(child2, root.getChildAt(0));
-})();
-
-(function addingChildUpdatesParent() {
- var child = new Composite();
- var root = new Composite();
- root.addChild(child);
- assert.same(root, child.parent);
-})();
-
-(function iteratorLoopsOverOneChild() {
- var root = new Composite();
- var child = new Composite();
- root.addChild(child);
-
- var itr = root.iterator();
- assert.ok(itr.hasNext());
-
- assert.same(child, itr.next());
- assert.ok(!itr.hasNext());
-
- assert.throws(function() {
- itr.next();
- }, /no more items/);
-})();
-
-(function iteratorLoopsOverThreeChildren() {
- var root = new Composite();
- var child1 = new Composite();
- var child2 = new Composite();
- var child3 = new Composite();
- root.addChild(child1);
- root.addChild(child2);
- root.addChild(child3);
-
- var itr = root.iterator();
- assert.ok(itr.hasNext());
- assert.same(child1, itr.next());
- assert.ok(itr.hasNext());
- assert.same(child2, itr.next());
- assert.ok(itr.hasNext());
- assert.same(child3, itr.next());
-
- assert.ok(!itr.hasNext());
- assert.throws(function() {
- itr.next();
- }, /no more items/);
-})();
-
-(function iteratorLoopsOverDepth() {
- var root = new Composite();
- var child1 = new Composite();
- var child2 = new Composite();
- var child3 = new Composite();
-
- root.addChild(child1);
- child1.addChild(child2);
- root.addChild(child3);
-
- var itr = root.iterator();
-
- assert.ok(itr.hasNext());
- assert.strictEqual(child1, itr.next());
- assert.ok(itr.hasNext());
- assert.strictEqual(child2, itr.next());
- assert.ok(itr.hasNext());
- assert.strictEqual(child3, itr.next());
-})();
-
-(function iteratorLoopsOverNestedTree() {
- var root = new LabelComposite('root');
- var child1 = new LabelComposite('child1');
- var child2 = new LabelComposite('child2');
- var child3 = new LabelComposite('child3');
- var child4 = new LabelComposite('child4');
- var child5 = new LabelComposite('child5');
- var child6 = new LabelComposite('child6');
-
- root.addChild(child1);
- root.addChild(child2);
- root.addChild(child3);
- child2.addChild(child4);
- child4.addChild(child5);
-
- var actualItem = null;
- var itr = root.iterator();
- [child1, child2, child4, child5, child3].forEach(function(expectedItem) {
- assert.ok(itr.hasNext(), 'Failed to haveNext on: ' + expectedItem);
- actualItem = itr.next();
- assert.strictEqual(expectedItem, actualItem);
- });
-})();
-
View
357 test/unit/test_context.js
@@ -1,357 +0,0 @@
-
-var Context = require('node_should/context').Context;
-var assert = require('assert');
-require('../common');
-
-// Configuration
-
-(function contextIsInstantiable() {
- var c = new Context();
-})();
-
-(function contextIsComposite() {
- var c = new Context();
- c.addChild(new Context());
- assert.equal(1, c.numChildren);
-})();
-
-(function contextAddSetupHandlerFailsWithNullHandler() {
- var c = new Context();
- assert.throws(function() {
- c.addSetupHandler();
- }, /must not be null/);
-})();
-
-(function contextAcceptsSetupHandler() {
- var c = new Context();
- c.addSetupHandler(function() {});
-})();
-
-(function contextAddTeardownHandlerFailsWithNullHandler() {
- var c = new Context();
- assert.throws(function() {
- c.addTeardownHandler();
- }, /must not be null/);
-})();
-
-(function contextAcceptsTeardownHandlers() {
- var c = new Context();
- c.addTeardownHandler(function() {});
-})();
-
-(function contextUsesEmptyStringAsDefaultLabel() {
- var c = new Context();
- assert.equal('', c.getLabel());
-})();
-
-(function contextFailsWithNullTestHandler() {
- var c = new Context();
- assert.throws(function() {
- c.addTestHandler();
- }, /must not be null/);
-})();
-
-(function contextAcceptsTestHandler() {
- var c = new Context();
- c.addTestHandler(function() {});
-})();
-
-(function contextAcceptsLabel() {
- var c = new Context('root');
- assert.equal('root', c.getLabel());
-})();
-
-(function contextBuildsLabelFromComposite() {
- var root = new Context('SomeClass');
- var child1 = new Context('with child');
- root.addChild(child1);
-
- assert.equal('SomeClass with child', child1.getLabel());
-})();
-
-(function contextBuildsLabelFromComposite() {
- var root = new Context('SomeClass');
- var child1 = new Context();
- root.addChild(child1);
-
- assert.equal('SomeClass', child1.getLabel());
-})();
-
-(function contextBuildsLabelFromComposite() {
- var root = new Context();
- var child1 = new Context('SomeClass');
- root.addChild(child1);
-
- assert.equal('SomeClass', child1.getLabel());
-})();
-
-// Execution
-
-(function contextFailsToExecuteIfNoTests() {
- var c = new Context();
- assert.throws(function() {
- c.execute();
- }, /no tests/);
-
-})();
-
-(function contextRunsSetupsThenTestsThenTeardowns() {
- var executed = [];
- var c = new Context('SomeClass');
- c.addSetupHandler(function() {
- executed.push('setup');
- });
- c.addTestHandler(function() {
- executed.push('test');
- });
- c.addTeardownHandler(function() {
- executed.push('teardown');
- });
- c.execute();
-
- var expected = ['setup', 'test', 'teardown'];
- assert.equal(expected.length, executed.length);
- assert.equal(expected[0], executed[0]);
- assert.equal(expected[1], executed[1]);
- assert.equal(expected[2], executed[2]);
-})();
-
-(function contextRunsHandlersInSharedScope() {
- var c = new Context('SomeClass');
- c.addSetupHandler(function() {
- this.foo = 'bar';
- });
- c.addTestHandler(function() {
- assert.equal(this.foo, 'bar');
- });
- c.execute();
-})();
-
-(function setupsCalledForEachTestMethod() {
- var executed = [];
- var c = new Context('SomeClass');
- c.addSetupHandler(function() { executed.push('setup1'); });
- c.addSetupHandler(function() { executed.push('setup2'); });
- c.addTestHandler(function() { executed.push('test1') });
- c.addTestHandler(function() { executed.push('test2') });
- c.addTestHandler(function() { executed.push('test3') });
- c.addTestHandler(function() { executed.push('test4') });
- c.addTeardownHandler(function() { executed.push('teardown1'); });
- c.addTeardownHandler(function() { executed.push('teardown2'); });
- c.execute();
-
- assert.equal(20, executed.length);
-})();
-
-(function testMethodsCalledWithDifferentScope() {
- var firstScope = null;
- var secondScope = null;
- var c = new Context();
- c.addTestHandler(function() { firstScope = this });
- c.addTestHandler(function() { secondScope = this });
- c.execute();
- assert.notStrictEqual(firstScope, secondScope);
-})();
-
-(function contextRunsSetupAsynchronouslyIfRequested() {
- var executed = [];
- var c = new Context();
- c.addSetupHandler(function() {
- var asyncHandler = this.async(function() {
- executed.push('asyncsetup');
- });
- setTimeout(asyncHandler, 0);
- });
- c.addTestHandler(function() {
- executed.push('test');
- });
- c.execute(function() {
- assert.equal(2, executed.length);
- assert.equal('asyncsetup', executed[0]);
- assert.equal('test', executed[1]);
- });
-})();
-
-(function contextRunsTestAsynchronously() {
- var executed = [];
- var c = new Context();
- c.addSetupHandler(function() {
- setTimeout(this.async(function() {
- executed.push('asyncsetup');
- }), 0);
- });
- c.addTestHandler(function() {
- setTimeout(this.async(function() {
- executed.push('asynctest1');
- }), 0);
- // TODO(lukebayes) Problem with async tests:
- // Make the previous line:
- //}), 500);
- // This fails!!!!!
- });
- c.addTestHandler(function() {
- setTimeout(this.async(function() {
- executed.push('asynctest2');
- }), 0);
- });
- c.addTeardownHandler(function() {
- setTimeout(this.async(function() {
- executed.push('asyncteardown');
- }), 0);
- });
-
- c.execute(function() {
- assert.equal(6, executed.length);
- });
-})();
-
-(function contextCapturesAssertionExceptions() {
- var failure = null;
- var c = new Context();
- c.addListener('failure', function(f) {
- failure = f;
- });
-
- c.addTestHandler(function() {
- assert.ok(false, 'should be false');
- });
-
- c.execute();
- assert.ok(failure);
-})();
-
-(function contextCapturesAssertionErrors() {
- var failure = null;
- var c = new Context();
- c.addListener('failure', function(f) {
- failure = f;
- });
- c.addTestHandler(function() {
- setTimeout(this.async(function() {
- assert.ok(false, 'should be false');
- }), 0);
- });
- c.execute(function() {
- assert.ok(failure);
- });
-})();
-
-(function contextCapturesRuntimeErrors() {
- var error = null;
- var c = new Context('SomeClass');
- c.addListener('error', function(test) {
- error = test.error;
- });
- c.addTestHandler('do something', function() {
- throw 'unknown application error';
- });
- c.execute();
- assert.match(/SomeClass should do something/, error.toString());
- assert.match(/unknown application error/, error.toString());
-})();
-
-(function contextSetupErrorsIncludeHelpfulLabel() {
- var error = null;
- var c = new Context('OtherClass');
- c.addListener('error', function(test) {
- error = test.error;
- });
- c.addSetupHandler(function() {
- throw 'unknown setup error';
- });
- c.addTestHandler('do something', function() {});
- c.execute();
- assert.match(/OtherClass should do something \(setup\)/, error.toString());
-})();
-
-(function contextHandlesMultipleAsyncsInSameCall() {
- var executed = [];
- var c = new Context();
- c.addTestHandler(function() {
- setTimeout(this.async(function() {
- executed.push('one');
- }), 0);
- setTimeout(this.async(function() {
- executed.push('two');
- }), 0);
- setTimeout(this.async(function() {
- executed.push('three');
- }), 0);
- });
-
- c.execute(function() {
- assert.equal(3, executed.length);
- assert.equal(executed[0], 'one');
- assert.equal(executed[1], 'two');
- assert.equal(executed[2], 'three');
- });
-})();
-
-// Failure Messages
-
-(function contextDisplaysHelpfulTestMessages() {
- var c = new Context('SomeClass');
- c.addTestHandler('accept argument', function() {
- assert.ok(false);
- });
- c.addListener('failure', function(test) {
- assert.match(/SomeClass should accept argument/, test.failure.message);
- });
- c.execute();
-})();
-
-(function contextLabelShowsEvenIfNoTestLable() {
- var c = new Context('SomeClass');
- c.addTestHandler(function() {
- assert.ok(false);
- });
- c.addListener('failure', function(test) {
- assert.match(/SomeClass/, test.failure.stack);
- });
- c.execute();
-})();
-
-// Composite Setup and Teardown
-
-(function contextGrabsParentSetups() {
- var executed = [];
- var parent = new Context('SomeParent');
- parent.addSetupHandler(function() {
- executed.push('parentsetup');
- this.param = {};
- });
- parent.addTeardownHandler(function() {
- executed.push('parentteardwon');
- });
- var child = new Context('with a child');
- child.addSetupHandler(function() {
- executed.push('childsetup');
- this.param.name = 'childvalue';
- });
- child.addTeardownHandler(function() {
- executed.push('childteardown');
- });
- child.addTestHandler('do something', function() {
- executed.push('testmethod1');
- assert.equal(this.param.name, 'childvalue');
- });
- child.addTestHandler('do something else', function() {
- executed.push('testmethod2');
- });
-
- parent.addChild(child);
- child.execute();
- assert.equal(10, executed.length);
- assert.equal('parentsetup', executed[0]);
-})();
-
-(function testThrowsAssertion() {
- var composite = new Context('SomeClass');
- composite.addTestHandler(function() {
- assert.throws(function() {
- throw 'hello world';
- }, /hello world/);
- });
- composite.execute();
-})();
-
View
302 test/unit/test_printer.js
@@ -1,302 +0,0 @@
-
-require('../common');
-var assert = require('assert');
-var Printer = require('node_should').Printer;
-var Context = require('node_should').Context;
-var FakePrinter = require('fake_printer').FakePrinter;
-
-// Construction
-
-(function printerIsInstantiable() {
- assert.ok(new Printer() != null);
-})();
-
-// Start
-
-(function printerStartDisplaysExpectedText() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- assert.equal("'Node Should' by Luke Bayes\n\n", p.out.message);
-})();
-
-(function printerStartThrowsAfterFirstCall() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- assert.throws(function() {
- p.start();
- }, /start already/);
-})();
-
-// Success
-
-(function printerTestSucceededOnlyWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- assert.throws(function() {
- p._testSuccessHandler();
- }, /must be preceeded by start/);
-})();
-
-(function printerSuccessWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p.finish();
-
- assert.match(/^\./gm, p.out.message);
- assert.equal(1, p.length);
-})();
-
-(function printerSuccessWorksWithMultipleCalls() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p.finish();
-
- var message = p.out.message;
- assert.match(/^\.\.\.\./gm, message);
- assert.match(/Test Count: 4, OK: 4, Failures: 0, Errors: 0, Ignored: 0/, message);
- assert.equal(4, p.length);
-})();
-
-// Failure
-
-(function printerTestFailureOnlyWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- assert.throws(function() {
- p._testFailureHandler();
- }, /must be preceeded by start/);
-})();
-
-(function printerFailureWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- try {
- assert.fail(null, 'fake actual value', 'fake expected value', '!=', 'foo');
- } catch (failure) {
- p._testFailureHandler({failure: failure});
- }
- p.finish();
-
- var message = p.out.message;
-
- assert.equal(1, p.length);
- assert.match(/^F/gm, message);
- assert.match(/Test Count: 1, OK: 0, Failures: 1, Errors: 0, Ignored: 0/, message);
- assert.match(/test_printer.js/, message);
-})();
-
-(function printerFailureWorksWithMultipleCalls() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p._testFailureHandler();
- p._testSuccessHandler();
- p._testFailureHandler();
- p._testFailureHandler();
- p._testSuccessHandler();
- p.finish();
-
- var message = p.out.message;
- assert.equal(7, p.length);
- assert.match(/^\.\.F\.FF\./gm, message);
- assert.match(/Test Count: 7, OK: 4, Failures: 3, Errors: 0, Ignored: 0/, message);
-})();
-
-// Error
-
-(function printerTestErrorOnlyWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- assert.throws(function() {
- p._testErrorHandler();
- }, /must be preceeded by start/);
-})();
-
-(function printerErrorWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- try {
- throw new Error('fake error');
- } catch (err) {
- p._testErrorHandler({error: err});
- }
- p.finish();
-
- var message = p.out.message;
- assert.match(/^E/gm, message);
- assert.match(/Test Count: 1, OK: 0, Failures: 0, Errors: 1, Ignored: 0/, message);
- assert.match(/fake error/, message);
- assert.equal(1, p.length);
-})();
-
-(function printerErrorWorksWithMultipleCalls() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p._testFailureHandler();
- p._testSuccessHandler();
-
- p._testErrorHandler();
-
- p._testFailureHandler();
- p._testFailureHandler();
-
- p._testErrorHandler();
- p._testSuccessHandler();
- p.finish();
-
- var message = p.out.message;
- assert.match(/^\.\.F\.EFFE\./gm, message);
- assert.equal(9, p.length);
-})();
-
-// Ignore
-
-(function printerTestIgnoreOnlyWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- assert.throws(function() {
- p.testIgnoreHandler();
- }, /must be preceeded by start/);
-})();
-
-(function printerIgnoreWorksAfterStart() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p.testIgnoreHandler();
- p.finish();
-
- var message = p.out.message;
- assert.match(/^I/gm, message);
- assert.equal(1, p.length);
-})();
-
-(function printerIgnoreWorksWithMultipleCalls() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p._testSuccessHandler();
- p._testFailureHandler();
- p._testSuccessHandler();
-
- p.testIgnoreHandler({message: 'ignore message a'});
-
- p._testFailureHandler();
- p._testFailureHandler();
-
- p.testIgnoreHandler({message: 'ignore message b'});
- p._testSuccessHandler();
- p.finish();
-
- var message = p.out.message;
- assert.match(/^\.\.F\.IFFI\./gm, message);
- assert.match(/Test Count: 9, OK: 4, Failures: 3, Errors: 0, Ignored: 2/, message);
- assert.match(/ignore message a/, message);
- assert.equal(9, p.length);
-})();
-
-// Finish
-
-(function printerFinishOnlyWorksIfStarted() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- assert.throws(function() {
- p.finish();
- });
-})();
-
-(function printerFinishOnlyWorksIfStartedAndAtLeastOneResult() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- assert.throws(function() {
- p.finish();
- });
-})();
-
-(function printerFinishWorksAfterTests() {
- var p = new FakePrinter();
- //p.out = process.stdout;
- p.start();
- p._testSuccessHandler();
- p.finish();
- assert.equal(1, p.length);
-
- var message = p.out.message;
- assert.match(/Total Time: \d ms/, message);
- assert.match(/Test Count: 1, OK: 1, Failures: 0, Errors: 0, Ignored: 0/, message);
-})();
-
-// Durations
-
-(function printerDisplaysTestDurations() {
- var p = new FakePrinter();
- p.start();
- p._testSuccessHandler({label: 'abcd', duration: 1});
- p._testSuccessHandler({label: 'efgh', duration: 87});
- p._testSuccessHandler({label: 'mnop', duration: 34});
- p._testSuccessHandler({label: 'ijkl', duration: 34});
- p._testSuccessHandler({label: 'qrst', duration: 242});
- p._testSuccessHandler();
- p._testSuccessHandler();
- p.finish();
-
- var message = p.out.message;
- //console.log(message);
-
- // Ensure that the list is present, AND sorted:
- assert.match(/ 242 ms : qrst.*\n.*efgh/gm, message);
- assert.match(/ 87 ms : efgh.*\n.*mnop/gm, message);
- assert.match(/ 34 ms : mnop.*\n.*ijkl/gm, message);
- assert.match(/ 34 ms : ijkl.*\n.*abcd/gm, message);
- assert.match(/ 1 ms : abcd/gm, message);
-})();
-
-// addContext
-
-(function printerAcceptsFailingContext() {
- var c = new Context('SomeClass');
- c.addTestHandler('should do something', function() {
- assert.ok(false, 'expected failure!');
- });
-
- var p = new FakePrinter();
- p.start();
- p.addContext(c);
- c.execute();
- p.finish();
- var message = p.out.message;
- assert.match(/Test Count: 1, OK: 0, Failures: 1, Errors: 0, Ignored: 0/, message);
-})();
-
-(function printerAcceptsPassingContext() {
- var c = new Context('SomeClass');
- c.addTestHandler('should do something', function() {
- assert.ok(true);
- });
-
- var p = new FakePrinter();
- p.start();
- p.addContext(c);
- c.execute();
- p.finish();
- var message = p.out.message;
- assert.match(/Test Count: 1, OK: 1, Failures: 0, Errors: 0, Ignored: 0/, message);
-})();
View
20 test/unit/test_runner.js
@@ -1,20 +0,0 @@
-
-require('../common');
-
-var assert = require('assert');
-var Runner = require('node_should/runner').Runner;
-var FakePrinter = require('fake_printer').FakePrinter;
-
-(function runnerCanBeInstantiated() {
- var r = new Runner();
-})();
-
-(function runnerCanLoadFiles() {
- var printer = new FakePrinter();
- var r = new Runner();
- r.run(/first.js/, 'test/fixtures', [printer], function() {
- //console.log(printer.out.message);
- assert.match(/OK: 2/, printer.out.message);
- });
-})();
-

0 comments on commit d0cb80a

Please sign in to comment.