From 450dedabd19fd780ae232a3d7645f74eafebba9f Mon Sep 17 00:00:00 2001 From: davidot Date: Tue, 30 Nov 2021 01:00:06 +0100 Subject: [PATCH] LibJS: Add messages to the toEval and toEvalTo tests This makes it a lot easier to understand what is going wrong when an eval test fails. As an example instead of just getting: `ExpectationError` You would now get: `ExpectationError: Expected _1_2E+0_1_ to eval to _12_ but got _120_`. --- Userland/Libraries/LibJS/Tests/test-common.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js index b192a5d9a8..778fff4169 100644 --- a/Userland/Libraries/LibJS/Tests/test-common.js +++ b/Userland/Libraries/LibJS/Tests/test-common.js @@ -353,7 +353,12 @@ class ExpectationError extends Error { toEval() { this.__expect(typeof this.target === "string"); const success = canParseSource(this.target); - this.__expect(this.inverted ? !success : success); + this.__expect( + this.inverted ? !success : success, + () => + `Expected _${valueToString(this.target)}_` + + (this.inverted ? "not to eval but it did" : "to eval but it didn't") + ); } // Must compile regardless of inverted-ness @@ -365,11 +370,18 @@ class ExpectationError extends Error { try { result = eval(this.target); } catch (e) { - throw new ExpectationError(); + throw new ExpectationError( + `Expected _${valueToString(this.target)}_ to eval but it failed with ${e}` + ); } this.__doMatcher(() => { - this.__expect(deepEquals(value, result)); + this.__expect( + deepEquals(value, result), + () => + `Expected _${valueToString(this.target)}_ to eval to ` + + `_${valueToString(value)}_ but got _${valueToString(result)}_` + ); }); }