v8/test/mjsunit/mjsunit-assertion-error.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.2 KiB
JavaScript
Raw Normal View History

Reland "[mjsunit] Improve mjsunit stracktrace readability" This is a reland of f720d024dca19d110e8d4c2d7040fbd664da4456 Original change's description: > [mjsunit] Improve mjsunit stracktrace readability > > Format the function name and file-position into proper columns to easily spot > where the test code ends and the mjsunit framework code starts. > > BEFORE: > Stack: Error > at new MjsUnitAssertionError (test/mjsunit/mjsunit.js:36:18) > at failWithMessage (test/mjsunit/mjsunit.js:310:11) > at fail (test/mjsunit/mjsunit.js:327:12) > at assertEquals (test/mjsunit/mjsunit.js:398:7) > at closure (test/mjsunit/regress/regress-4121.js:20:7) > at literals_sharing_test (test/mjsunit/regress/regress-4121.js:27:3) > at test (test/mjsunit/regress/regress-4121.js:37:5) > at eval (eval at <anonymous> (test/mjsunit/regress/regress-4121.js:49:6), <anonymous>:1:1) > at test/mjsunit/regress/regress-4121.js:49:6 > at Array.forEach.call (test/mjsunit/regress/regress-4121.js:50:7) > throw new MjsUnitAssertionError(message); > > AFTER: > Stack: MjsUnitAssertionError > at assertEquals test/mjsunit/mjsunit.js 398:7 > at closure test/mjsunit/regress/regress-4121.js 20:7 > at literals_sharing_test test/mjsunit/regress/regress-4121.js 27:3 > at test test/mjsunit/regress/regress-4121.js 37:5 > at eval eval at <anonymous> (test/mjsunit/regress/regress-4121.js:49:6) > at test/mjsunit/regress/regress-4121.js 49:6 > at Array.forEach.call test/mjsunit/regress/regress-4121.js 50:7 > throw new MjsUnitAssertionError(message); > > > Change-Id: Iad3460a648e26effb43c00426ab043743ee6a138 > Reviewed-on: https://chromium-review.googlesource.com/563627 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Reviewed-by: Igor Sheludko <ishell@chromium.org> > Commit-Queue: Camillo Bruni <cbruni@chromium.org> > Cr-Commit-Position: refs/heads/master@{#46589} Change-Id: I44bf07f7be4114369315605542cafd17345b4397 Reviewed-on: https://chromium-review.googlesource.com/567063 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#46602}
2017-07-12 15:28:49 +00:00
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let fileName = 'mjsunit-assertion-error.js';
function addDefaultFrames(frameExpectations) {
// The last frame contains the error instantiation.
frameExpectations.unshift('assertTrue.*mjsunit.js');
// Frist frame is the top-level script.
frameExpectations.push(fileName);
}
function assertErrorMessage(frameExpectations, error) {
let stack = error.stack.split("\n");
let title = stack.shift();
assertContains('MjsUnitAssertionError', title);
addDefaultFrames(frameExpectations);
// Add default frames to the expectations.
assertEquals(frameExpectations.length, stack.length);
for (let i = 0; i < stack.length; i++) {
let frame = stack[i];
let expectation = frameExpectations[i];
assertTrue(frame.search(expectation) != -1,
`Frame ${i}: Did not find '${expectation}' in '${frame}'`);
}
}
// Toplevel
try {
assertTrue(false);
} catch(e) {
assertErrorMessage([], e);
}
// Single function.
function throwError() {
assertTrue(false);
}
try {
throwError();
assertUnreachable();
} catch(e) {
assertErrorMessage(['throwError'], e);
}
// Nested function.
function outer() {
throwError();
}
try {
outer();
assertUnreachable();
} catch(e) {
assertErrorMessage(['throwError', 'outer'], e);
}
// Test Array helper nesting
try {
[1].map(throwError);
assertUnreachable();
} catch(e) {
assertErrorMessage(['throwError', 'Array.map'], e);
}
try {
Array.prototype.map.call([1], throwError);
assertUnreachable();
} catch(e) {
assertErrorMessage(['throwError', 'Array.map'], e);
}
// Test eval
try {
eval("assertTrue(false);");
assertUnreachable();
} catch(e) {
assertErrorMessage(['eval'], e);
}
(function testNestedEval() {
try {
eval("assertTrue(false);");
assertUnreachable();
} catch(e) {
assertErrorMessage(['eval', 'testNestedEval'], e);
}
})();
(function testConstructor() {
class Failer {
constructor() {
assertTrue(false);
}
}
try {
new Failer();
assertUnreachable();
} catch(e) {
assertErrorMessage(['new Failer', 'testConstructor'], e);
}
})();