Permalink
Browse files

Factored out the common test code

  • Loading branch information...
1 parent 9469f92 commit 2dc6c8004cea84810d90c375f532d2541e9a9928 Merlyn Albery-Speyer committed Mar 15, 2013
Showing with 9 additions and 18 deletions.
  1. +9 −18 test/test.js
View
27 test/test.js
@@ -22,14 +22,7 @@ try {
assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
assert.ok(!!~['<anonymous>', 'local_unnamed'].indexOf(traced.frames[0].named_location));
- assert.equal(traced.first_line, err.stack.split('\n')[0]);
- assert.strictEqual(traced.original_error, err);
-
- var lines = err.stack.split('\n').slice(1);
- for(var i = 0, len = lines.length; i < len; ++i) {
- assert.notStrictEqual(lines[i].indexOf(traced.frames[i].line + ':' + traced.frames[i].character), -1);
- assert.notStrictEqual(lines[i].indexOf(traced.frames[i].filename), -1);
- }
+ assert_stacks_equal(err, traced);
}
try {
@@ -38,14 +31,7 @@ try {
var traced = trace(err);
assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
- assert.equal(traced.first_line, err.stack.split('\n')[0]);
- assert.strictEqual(traced.original_error, err);
-
- var lines = err.stack.split('\n').slice(1);
- for(var i = 0, len = lines.length; i < len; ++i) {
- assert.notStrictEqual(lines[i].indexOf(traced.frames[i].line + ':' + traced.frames[i].character), -1);
- assert.notStrictEqual(lines[i].indexOf(traced.frames[i].filename), -1);
- }
+ assert_stacks_equal(err, traced);
}
try {
@@ -54,6 +40,13 @@ try {
var traced = trace(err);
assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
+ assert_stacks_equal(err, traced);
+}
+
+console.error('Tests passed');
+return;
+
+function assert_stacks_equal(err, traced) {
assert.equal(traced.first_line, err.stack.split('\n')[0]);
assert.strictEqual(traced.original_error, err);
@@ -63,5 +56,3 @@ try {
assert.notStrictEqual(lines[i].indexOf(traced.frames[i].filename), -1);
}
}
-
-console.error('Tests passed');

0 comments on commit 2dc6c80

Please sign in to comment.