File: test-documentation.el

package info (click to toggle)
flycheck 30-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,172 kB
  • ctags: 1,544
  • sloc: lisp: 11,139; python: 733; makefile: 243; ruby: 23; cpp: 17; ada: 17; f90: 16; xml: 14; ansic: 12; haskell: 12; sh: 10; erlang: 10; php: 9; perl: 7; fortran: 3; sql: 1
file content (103 lines) | stat: -rw-r--r-- 4,133 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;;; test-documentation.el --- Flycheck Specs: Documentation -*- lexical-binding: t; -*-

;; Copyright (C) 2013-2016 Sebastian Wiesner and Flycheck contributors

;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>

;; This file is not part of GNU Emacs.

;; 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/>.

;;; Commentary:

;; Specs for our documentation

;;; Code:

(require 'flycheck-buttercup)
(require 'cl-lib)
(require 'seq)
(require 'dash)

(defun flycheck/collect-matches (pattern filename)
  "Collect all instances matching PATTERN from FILENAME."
  (let ((matches))
    (with-temp-buffer
      (insert-file-contents filename)
      (goto-char (point-min))
      (while (re-search-forward pattern nil 'noerror)
        (let ((match (intern (match-string 1))))
          (cl-pushnew match matches))
        (-when-let (match (match-string 2))
          (cl-pushnew (intern match) matches))))
    matches))

(defconst flycheck/checker-re
  (rx bol "   .. syntax-checker:: " (group (1+ nonl)) "\n"
      (? "                       " (group (1+ nonl)) eol)))

(defconst flycheck/defcustom-re
  (rx bol "      .. defcustom:: " (group (1+ nonl)) "\n"
      (? "                     " (group (1+ nonl)) eol)))

(describe "Documentation"
  (let* ((source-dir (locate-dominating-file default-directory "Cask"))
         (languages (expand-file-name "doc/languages.rst" source-dir)))

    (describe "Syntax checkers"
      (let ((checkers (flycheck/collect-matches flycheck/checker-re
                                                languages)))

        (it "documents all syntax checkers"
          (expect (seq-difference flycheck-checkers checkers)
                  :to-equal nil))

        (it "doesn't document syntax checkers that don't exist"
          (expect (seq-difference checkers flycheck-checkers)
                  :to-equal nil)))

      (describe "Options"
        (let ((documented-options (flycheck/collect-matches flycheck/defcustom-re
                                                            languages))
              (all-options (seq-mapcat (lambda (c)
                                         (flycheck-checker-get c 'option-vars))
                                       flycheck-checkers)))

          (it "documents all syntax checker options"
            (expect (seq-difference all-options documented-options)
                    :to-equal nil))

          (it "doesn't document syntax checker options that don't exist"
            (expect (seq-difference documented-options all-options)
                    :to-equal nil))))

      (describe "Configuration files"
        (let ((documented-file-vars (flycheck/collect-matches
                                     (rx ".. syntax-checker-config-file:: "
                                         (group (1+ nonl)) eol)
                                     languages))
              (all-file-vars (delq nil
                                   (seq-map (lambda (c)
                                              (flycheck-checker-get
                                               c 'config-file-var))
                                            flycheck-checkers))))
          (it "documents all syntax checker configuration files"
            (expect (seq-difference all-file-vars documented-file-vars)
                    :to-equal nil))

          (it "it doesn't document configuration files that don't exist"
            (expect (seq-difference documented-file-vars all-file-vars)
                    :to-equal nil)))))))

;;; test-documentation.el ends here