branch: master commit 3f63fabe8fbb5135448bb5eb495d2cb9d58e1a68 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Add local coverage configuration. --- .gitignore | 1 + Makefile | 14 +++++- test/{test-helper.el => ci-coverage.el} | 0 test/local-coverage.el | 42 ++++++++++++++++++ test/parse-coverage.js | 72 +++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d0147ab..a269508 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.elc .cask/ /benchmark/logs/ +/test/coverage/ diff --git a/Makefile b/Makefile index f322a81..868bd2a 100644 --- 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 diff --git a/test/test-helper.el b/test/ci-coverage.el 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 index 0000000..7d6ee0d --- /dev/null +++ b/test/local-coverage.el @@ -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 index 0000000..e65eab0 --- /dev/null +++ b/test/parse-coverage.js @@ -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();