[gjs/wip/ptomato/develop: 4/9] coverage: Don't count literals as executable



commit 635a11edc35023a939a10d01e185eaa7b6a05129
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.

 installed-tests/js/testCoverage.js |   46 ++++++++++++++++++------------------
 modules/_bootstrap/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 a5f8d30..df3e032 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/_bootstrap/coverage.js b/modules/_bootstrap/coverage.js
index fea755d..c8c5499 100644
--- a/modules/_bootstrap/coverage.js
+++ b/modules/_bootstrap/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]