]> code.delx.au - gnu-emacs-elpa/blob - test/context-coloring-coverage.el
0383ac4218cb0e221add5b56c37e655ea6ebadb4
[gnu-emacs-elpa] / test / context-coloring-coverage.el
1 ;;; context-coloring-coverage.el --- Test coverage for context coloring -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; Test coverage support for context coloring.
23
24 ;; Use with `make cover'.
25
26 ;;; Code:
27
28 (require 'undercover)
29
30
31 (defconst context-coloring-coverage-directory
32 (file-name-directory (or load-file-name buffer-file-name))
33 "This file's directory.")
34
35 (defun context-coloring-coverage-resolve-path (path)
36 "Resolve PATH from this file's directory."
37 (expand-file-name path context-coloring-coverage-directory))
38
39 (defconst context-coloring-coverage-output-file-prefix
40 (format-time-string "%s"))
41
42 (defconst context-coloring-coverage-output-directory
43 (context-coloring-coverage-resolve-path "./coverage/"))
44
45 (defconst context-coloring-coverage-output-file
46 (concat context-coloring-coverage-output-directory
47 context-coloring-coverage-output-file-prefix ".json"))
48
49 (defconst context-coloring-coverage-report-file
50 (concat context-coloring-coverage-output-directory
51 context-coloring-coverage-output-file-prefix ".txt"))
52
53 (defconst context-coloring-coverage-parser
54 (concat "node " (context-coloring-coverage-resolve-path "./parse-coverage.js")))
55
56 (defun context-coloring-coverage-local-init ()
57 "Initialize test coverage for local viewing."
58 (make-directory context-coloring-coverage-output-directory t)
59 (setq undercover-force-coverage t)
60 (setenv "COVERALLS_REPO_TOKEN" "noop")
61 (undercover "context-coloring.el"
62 (:report-file context-coloring-coverage-output-file))
63 (add-hook
64 'kill-emacs-hook
65 (lambda ()
66 (let* ((output-buffer (get-buffer-create "*parsed coverage*")))
67 (call-process-shell-command
68 context-coloring-coverage-parser
69 context-coloring-coverage-output-file
70 output-buffer)
71 (with-current-buffer output-buffer
72 (princ (buffer-substring-no-properties (point-min) (point-max)))
73 (write-file context-coloring-coverage-report-file))))
74 t)
75 (require 'context-coloring))
76
77 (defun context-coloring-coverage-ci-init ()
78 "Initialize test coverage for continuous integration."
79 (undercover "context-coloring.el")
80 (require 'context-coloring))
81
82 (provide 'context-coloring-coverage)
83
84 ;; context-coloring-coverage.el ends here