Permalink
Browse files

Stop test execution on failed assertion. Fixes GH-6

  • Loading branch information...
1 parent 414b3d8 commit 317ebec8ad4ddcfdced81fe6a1120d5345cdf7eb @valueof valueof committed Feb 15, 2012
Showing with 29 additions and 6 deletions.
  1. +22 −4 hiro.js
  2. +7 −2 test.js
View
26 hiro.js
@@ -48,6 +48,7 @@ var hiro = (function (window, undefined) {
var Suite;
var Test;
+ var Failure = function () {}
function each(obj, callback) {
for (var key in obj) {
@@ -89,7 +90,6 @@ var hiro = (function (window, undefined) {
}
}
-
// People can load fixtures either by injecting HTML into
// an iframe or by loading another page inside of it. Note,
// that the page has to be on the same domain or we won't
@@ -208,7 +208,12 @@ var hiro = (function (window, undefined) {
try {
self.methods.onTest.apply(test);
} catch (exc) {
- test.fail_({ assertion: 'onTest', result: exc.toString() });
+ try {
+ test.fail_({ assertion: 'onTest', result: exc.toString() });
+ } catch (e) {
+ if (!(e instanceof Failure))
+ throw e;
+ }
}
};
@@ -353,6 +358,7 @@ var hiro = (function (window, undefined) {
hiro.trigger('test.onFailure', [ this, report ]);
this.failed = true;
+ throw new Failure();
},
timedout_: function () {
@@ -372,7 +378,12 @@ var hiro = (function (window, undefined) {
try {
this.suite.methods.onCleanup.apply(this);
} catch (exc) {
- this.fail_({ assertion: 'onComplete', result: exc.toString() });
+ try {
+ this.fail_({ assertion: 'onComplete', result: exc.toString() });
+ } catch (e) {
+ if (!(e instanceof Failure))
+ throw e;
+ }
}
}
@@ -410,7 +421,14 @@ var hiro = (function (window, undefined) {
if (!this.failed) {
this.status = 'running';
- this.func.apply(this, this.args);
+
+ try {
+ this.func.apply(this, this.args);
+ } catch (exc) {
+ if (!(exc instanceof Failure))
+ throw exc;
+ }
+
this.snapshot = timestamp();
}
View
@@ -253,16 +253,18 @@ hiro.module('TestRunnerTests', {
testFailedRun: function (hiro_, Test, Suite) {
var that = this;
+ var flag = true;
var test;
function testCase() {
this.expect(1);
this.assertTrue(false);
+ flag = false; // This line must not be executed.
}
test = new Test('testDummy', testCase, new Suite('test', {}));
hiro_.changeTimeout(500);
- this.expect(11);
+ this.expect(12);
hiro_.once('test.onComplete', function (test, success) {
that.assertEqual(test.name, 'testDummy');
@@ -279,8 +281,11 @@ hiro.module('TestRunnerTests', {
this.assertTrue(test.snapshot != null);
this.assertFalse(test.paused);
this.assertTrue(test.failed);
-
this.assertFalse(test.complete_());
+
+ // The code after failed assertion shouldn't be executed and
+ // thus the flag should always be true.
+ this.assertTrue(flag);
},
testNotAllAssertions: function (hiro_, Test, Suite) {

0 comments on commit 317ebec

Please sign in to comment.