Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from curious-attempt-bunny/merlyn/test_code_ref…

…actored

Factored out the common test code
  • Loading branch information...
commit c82687d224a5bdb1224d5c7fdd2ef352786d278e 2 parents 08ad654 + 2dc6c80
@chrisdickinson authored
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');
Please sign in to comment.
Something went wrong with that request. Please try again.