[gjs/gnome-3-26] coverage: Don't count literals as executable



commit 65067b20d83952fa3188ea0c8572d0a4f9b716ff
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Sep 23 10:30:23 2017 -0700

    coverage: Don't count literals as executable
    
    The AST type used to detect this is "Literal", previously it was given as
    "LiteralExpression" which caused literals on their own line to be counted
    as executable, but never executed during code coverage measurements.
    
    Requires some changes in the tests, since there was some test data
    assuming that literals were executable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788166

 installed-tests/js/testCoverage.js |   46 ++++++++++++++++++------------------
 modules/coverage.js                |    2 +-
 2 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/installed-tests/js/testCoverage.js b/installed-tests/js/testCoverage.js
index 1857d3e..338c69e 100644
--- a/installed-tests/js/testCoverage.js
+++ b/installed-tests/js/testCoverage.js
@@ -57,23 +57,23 @@ describe('Coverage.expressionLinesForAST', function () {
         ],
 
         'finds lines inside multiline function arguments': [
-            "function f(a, b, c) {\n" +
-            "}\n" +
-            "f(1,\n" +
-            "  2,\n" +
-            "  3);\n",
+            `function f(a, b, c) {
+            }
+            f(1,
+                2 + 3,
+                3 + 4);`,
             [1, 3, 4, 5],
         ],
 
         'finds lines inside function argument that is an object': [
-            "function f(o) {\n" +
-            "}\n" +
-            "let obj = {\n" +
-            "    Name: new f({ a: 1,\n" +
-            "                  b: 2,\n" +
-            "                  c: 3\n" +
-            "                })\n" +
-            "}\n",
+            `function f(o) {
+            }
+            let obj = {
+                Name: new f({ a: 1,
+                    b: 2 + 3,
+                    c: 3 + 4,
+                })
+            } `,
             [1, 3, 4, 5, 6],
         ],
 
@@ -154,10 +154,10 @@ describe('Coverage.expressionLinesForAST', function () {
         ],
 
         'finds lines for object property literals': [
-            "var a = {\n" +
-            "    Name: 'foo',\n" +
-            "    Ex: 'bar'\n" +
-            "};\n",
+            `var a = {
+                Name: 'foo' + 'bar',
+                Ex: 'bar' + 'foo',
+            }`,
             [1, 2, 3],
         ],
 
@@ -190,12 +190,12 @@ describe('Coverage.expressionLinesForAST', function () {
         ],
 
         'finds lines inside object-valued argument to throw statement': [
-            "function f() {\n" +
-            "    throw {\n" +
-            "        a: 1,\n" +
-            "        b: 2\n" +
-            "    }\n" +
-            "}\n",
+            `function f() {
+                throw {
+                    a: 1 + 2,
+                    b: 2 + 3,
+                }
+            }`,
             [2, 3, 4],
         ],
     };
diff --git a/modules/coverage.js b/modules/coverage.js
index fea755d..c8c5499 100644
--- a/modules/coverage.js
+++ b/modules/coverage.js
@@ -354,7 +354,7 @@ function expressionLinesForNode(statement) {
         /* These expressions aren't executable on their own */
         switch (statement.type) {
         case 'FunctionDeclaration':
-        case 'LiteralExpression':
+        case 'Literal':
             break;
         /* Perplexingly, an empty block statement is actually executable,
          * push it if it is */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]