]> code.delx.au - gnu-emacs-elpa/commitdiff
Add local coverage configuration.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Mon, 4 May 2015 07:42:26 +0000 (00:42 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Mon, 4 May 2015 07:42:26 +0000 (00:42 -0700)
.gitignore
Makefile
test/ci-coverage.el [moved from test/test-helper.el with 100% similarity]
test/local-coverage.el [new file with mode: 0644]
test/parse-coverage.js [new file with mode: 0755]

index d0147ab966076ba53aa824c063582e9d9878f259..a269508e685afa26e080793a204b2787f9f6b9b3 100644 (file)
@@ -1,3 +1,4 @@
 *.elc
 .cask/
 /benchmark/logs/
+/test/coverage/
index f322a8174abafc2730435357b3944fdc2ff66830..868bd2a8dbb3df5b9401013045b7bf69da941d4c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,18 @@ test: ${DEPENDENCIES}
        -L . \
        -l ert \
        -l ert-async \
-       -l test/test-helper.el \
+       -l test/ci-coverage.el \
        -l test/context-coloring-test.el \
        -f ert-run-tests-batch-and-exit
 
-.PHONY: all bench compile uncompile clean test
+cover: ${DEPENDENCIES}
+       COVERALLS_REPO_TOKEN="noop" \
+       ${CASK} exec ${EMACS} -Q -batch \
+       -L . \
+       -l ert \
+       -l ert-async \
+       -l test/local-coverage.el \
+       -l test/context-coloring-test.el \
+       -f ert-run-tests-batch-and-exit
+
+.PHONY: all bench compile uncompile clean test cover
similarity index 100%
rename from test/test-helper.el
rename to test/ci-coverage.el
diff --git a/test/local-coverage.el b/test/local-coverage.el
new file mode 100644 (file)
index 0000000..7d6ee0d
--- /dev/null
@@ -0,0 +1,42 @@
+(defconst context-coloring-test-directory
+  (file-name-directory (or load-file-name buffer-file-name))
+  "This file's directory.")
+
+(defun context-coloring-test-resolve-path (path)
+  "Resolve PATH from this file's directory."
+  (expand-file-name path context-coloring-test-directory))
+
+(defconst context-coloring-coverage-output-file-prefix
+  (format-time-string "%s"))
+
+(defconst context-coloring-coverage-output-file
+  (context-coloring-test-resolve-path
+   (concat "./coverage/" context-coloring-coverage-output-file-prefix ".json")))
+
+(defconst context-coloring-coverage-report-file
+  (context-coloring-test-resolve-path
+   (concat "./coverage/" context-coloring-coverage-output-file-prefix ".txt")))
+
+(defconst context-coloring-test-coverage-parser
+  (concat "node " (context-coloring-test-resolve-path "./parse-coverage.js")))
+
+(require 'undercover)
+(setq undercover-force-coverage t)
+(make-directory (context-coloring-test-resolve-path "./coverage/") t)
+(undercover "context-coloring.el"
+            (:report-file context-coloring-coverage-output-file))
+
+(add-hook
+ 'kill-emacs-hook
+ (lambda ()
+   (let* ((output-buffer (get-buffer-create "*parsed coverage*")))
+     (call-process-shell-command
+      context-coloring-test-coverage-parser
+      context-coloring-coverage-output-file
+      output-buffer)
+     (with-current-buffer output-buffer
+       (princ (buffer-substring-no-properties (point-min) (point-max)))
+       (write-file context-coloring-coverage-report-file))))
+ t)
+
+(require 'context-coloring)
diff --git a/test/parse-coverage.js b/test/parse-coverage.js
new file mode 100755 (executable)
index 0000000..e65eab0
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/env node
+
+// Copyright (C) 2014-2015  Free Software Foundation, Inc.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+'use strict';
+
+var padRight = function (value, padding) {
+    return value + new Array(Math.max(0, padding - String(value).length) + 1).join(' ');
+};
+
+var formatSourceFile = function (sourceFile) {
+    var sourceLines = sourceFile.source.split('\n');
+    var results = [
+        padRight('Hits', 5) + ' | Source',
+        new Array(80 + 1).join('-')
+    ];
+    var linesHit = 0;
+    var linesHittable = 0;
+    results = results.concat(sourceFile.coverage.map(function (hits, index) {
+        var hitsValue = hits === null ? 'N/A' : hits;
+        var column = hits === 0 ? '~' : '|';
+        if (hits > 0) {
+            linesHit += 1;
+        }
+        if (hits !== null) {
+            linesHittable += 1;
+        }
+        return padRight(hitsValue, 5) + ' ' + column + ' ' + sourceLines[index];
+    }));
+    results = results.concat([
+        '',
+        'Lines: ' + linesHit + ' / ' + linesHittable,
+        'Coverage: ' + (Math.round(linesHit / linesHittable * 10000) / 100) + '%'
+    ]);
+    return results.join('\n');
+};
+
+var format = function (json) {
+    return json.source_files.map(formatSourceFile).join('\n');
+};
+
+var read = function () {
+    var whole = '';
+
+    process.stdin.setEncoding('utf8');
+
+    process.stdin.on('readable', function () {
+        var chunk = process.stdin.read();
+        if (chunk !== null) {
+            whole += chunk;
+        }
+    });
+
+    process.stdin.on('end', function () {
+        console.log(format(JSON.parse(whole)));
+    });
+};
+
+read();