[gjs] coverage: Call log() directly instead of using reporters



commit 9cf1ffe9ab09c77257e1ba176e0b092bfaa93933
Author: Sam Spilsbury <smspillaz gmail com>
Date:   Fri Jul 3 03:48:25 2015 +0800

    coverage: Call log() directly instead of using reporters
    
    Reporters were initially used to inject the depedency on
    warning() which wasn't available in the tests. Now that we
    have log() everywhere, just use log()

 installed-tests/js/testCoverage.js |   19 ++++++++-----------
 modules/coverage.js                |   20 ++++++--------------
 2 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/installed-tests/js/testCoverage.js b/installed-tests/js/testCoverage.js
index 839aaf1..1ceeb5c 100644
--- a/installed-tests/js/testCoverage.js
+++ b/installed-tests/js/testCoverage.js
@@ -1210,7 +1210,7 @@ function testIncrementExpressionCountersThrowsIfLineOutOfRange() {
     ];
 
     JSUnit.assertRaises(function() {
-        Coverage._incrementExpressionCounters(expressionCounters, 2);
+        Coverage._incrementExpressionCounters(expressionCounters, 'script', 2);
     });
 }
 
@@ -1220,7 +1220,7 @@ function testIncrementExpressionCountersIncrementsIfInRange() {
         0
     ];
 
-    Coverage._incrementExpressionCounters(expressionCounters, 1);
+    Coverage._incrementExpressionCounters(expressionCounters, 'script', 1);
     JSUnit.assertEquals(1, expressionCounters[1]);
 }
 
@@ -1231,16 +1231,13 @@ function testWarnsIfWeHitANonExecutableLine() {
         undefined
     ];
 
-    let wasCalledContainer = { calledWith: undefined };
-    let reporter = function(cont) {
-        let container = cont;
-        return function(line) {
-            container.calledWith = line;
-        };
-    } (wasCalledContainer);
+    let messages = _fetchLogMessagesFrom(function() {
+        Coverage._incrementExpressionCounters(expressionCounters, 'script', 2);
+    });
 
-    Coverage._incrementExpressionCounters(expressionCounters, 2, reporter);
-    JSUnit.assertEquals(wasCalledContainer.calledWith, 2);
+    JSUnit.assertEquals(messages[0],
+                        "script:2 Executed line previously marked " +
+                        "non-executable by Reflect");
     JSUnit.assertEquals(expressionCounters[2], 1);
 }
 
diff --git a/modules/coverage.js b/modules/coverage.js
index 13f4ca6..1b4f2cc 100644
--- a/modules/coverage.js
+++ b/modules/coverage.js
@@ -618,12 +618,10 @@ function _incrementFunctionCounters(functionCounters,
  * expressonCounters: An array of either a hit count for a found
  * executable line or undefined for a known non-executable line.
  * line: an executed line
- * reporter: A function a single integer to report back when
- * we executed lines that we didn't expect
  */
 function _incrementExpressionCounters(expressionCounters,
-                                      offsetLine,
-                                      reporter) {
+                                      script,
+                                      offsetLine) {
     let expressionCountersLen = expressionCounters.length;
 
     if (offsetLine >= expressionCountersLen)
@@ -648,7 +646,8 @@ function _incrementExpressionCounters(expressionCounters,
      * and BlockStatement, neither of which would ordinarily be
      * executed */
     if (expressionCounters[offsetLine] === undefined) {
-        reporter(offsetLine);
+        log(script + ':' + offsetLine + ' Executed line previously marked ' +
+            'non-executable by Reflect');
         expressionCounters[offsetLine] = 0;
     }
 
@@ -954,15 +953,8 @@ function CoverageStatistics(prefixes, cache) {
 
             try {
                 _incrementExpressionCounters(statistics.expressionCounters,
-                                             offsetLine,
-                                             function(line) {
-                                                 log("executed " +
-                                                     frame.script.url +
-                                                     ":" +
-                                                     line +
-                                                     " which we thought" +
-                                                     " wasn't executable");
-                                             });
+                                             frame.script.url,
+                                             offsetLine);
                 this._branchTracker.incrementBranchCounters(offsetLine);
             } catch (e) {
                 /* Something bad happened. Log the exception and delete


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