Permalink
Browse files

Fixed stack trace for sync assert

  • Loading branch information...
1 parent 29d6d61 commit 5a79f1fb000849319a7899e4cf0fce0cd3bea810 @5long committed Nov 6, 2010
Showing with 27 additions and 3 deletions.
  1. +1 −1 src/assert.js
  2. +3 −2 src/test.js
  3. +23 −0 test/assert_stack_trace.js
View
2 src/assert.js
@@ -37,7 +37,7 @@ module.exports = util.merge(eA, {
, in: function(key, obj, msg) {
if (!(key in obj)) {
- fail(key, obj, msg, "in", eA.include)
+ fail(key, obj, msg, "in", eA.in)
}
}
View
5 src/test.js
@@ -22,15 +22,16 @@ Test.supportedAsserts = supportedAsserts.reduce(function(set, key) {
supportedAsserts.forEach(function(name) {
if (!(name in assert)) return
- Test.prototype[name] = function() {
+ Test.prototype[name] = function Self() {
var e, posForMsg = assert[name].length - 1
, msg = arguments[posForMsg]
try {
assert[name].apply(assert, arguments)
this._log(true, msg)
} catch (e) {
if (!(e instanceof assert.AssertionError)) this._doEnd(e)
- this._log(false, msg, e)
+ e.stackStartFunction = Self
+ this._log(false, msg, new AssertionError(e))
}
}
})
View
23 test/assert_stack_trace.js
@@ -0,0 +1,23 @@
+var reut = require("../src")
+ , enum = require("../src/util").enum
+ , Test = reut.Test
+ , assert = require("assert")
+
+var t = new Test("a failing one", function(t) {
+ t.ok(0, "native failure")
+ t.in(0, {}, "extended one")
+ function cb(){}
+ t.cb(cb, "an async one")
+ process.nextTick(cb)
+})
+
+t.run(function(err, results) {
+ if (err) throw err
+ results = results.failed
+ results.forEach(function(r) {
+ assert.ok(
+ r.stack.split("\n")[1].indexOf(__filename) != -1
+ , r.message + " aint got proper stack top"
+ )
+ })
+})

0 comments on commit 5a79f1f

Please sign in to comment.