Bläddra i källkod

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_`.
davidot 3 år sedan
förälder
incheckning
450dedabd1
1 ändrade filer med 15 tillägg och 3 borttagningar
  1. 15 3
      Userland/Libraries/LibJS/Tests/test-common.js

+ 15 - 3
Userland/Libraries/LibJS/Tests/test-common.js

@@ -353,7 +353,12 @@ class ExpectationError extends Error {
         toEval() {
         toEval() {
             this.__expect(typeof this.target === "string");
             this.__expect(typeof this.target === "string");
             const success = canParseSource(this.target);
             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
         // Must compile regardless of inverted-ness
@@ -365,11 +370,18 @@ class ExpectationError extends Error {
             try {
             try {
                 result = eval(this.target);
                 result = eval(this.target);
             } catch (e) {
             } catch (e) {
-                throw new ExpectationError();
+                throw new ExpectationError(
+                    `Expected _${valueToString(this.target)}_ to eval but it failed with ${e}`
+                );
             }
             }
 
 
             this.__doMatcher(() => {
             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)}_`
+                );
             });
             });
         }
         }