Klimi's new dotfiles with stow.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

157 рядки
5.2 KiB

4 роки тому
  1. ;;; flycheck-buttercup.el --- Flycheck: Extensions to Buttercup -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017 Flycheck contributors
  3. ;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors
  4. ;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
  5. ;; Maintainer: Clément Pit-Claudel <clement.pitclaudel@live.com>
  6. ;; fmdkdd <fmdkdd@gmail.com>
  7. ;; Keywords: lisp, tools
  8. ;; This file is not part of GNU Emacs.
  9. ;; This program is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  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. ;;; Commentary:
  20. ;; Extensions to Buttercup to write BDD tests for Flycheck.
  21. ;;
  22. ;; Buttercup is a BDD testing framework for Emacs, see URL
  23. ;; `https://github.com/jorgenschaefer/emacs-buttercup/'. Flycheck uses
  24. ;; Buttercup extensively for new tests.
  25. ;;
  26. ;; This library provides extensions to Buttercup to write Specs for Flycheck.
  27. ;;
  28. ;; * Custom matchers
  29. ;;
  30. ;; (expect 'foo :to-be-local) - Is `foo' a local variable in the current buffer?
  31. ;;; Code:
  32. (require 'buttercup)
  33. (require 'flycheck)
  34. (require 'seq)
  35. ;;; Buttercup helpers
  36. (defun flycheck-buttercup-format-error-list (errors)
  37. "Format ERRORS into a human-readable string."
  38. (mapconcat (lambda (e) (flycheck-error-format e 'with-file-name))
  39. errors "\n"))
  40. ;;; Data matchers
  41. (buttercup-define-matcher :to-be-empty-string (s)
  42. (let ((s (funcall s)))
  43. (if (equal s "")
  44. (cons t (format "Expected %S not be an empty string" s))
  45. (cons nil (format "Expected %S to be an empty string" s)))))
  46. (buttercup-define-matcher :to-match-with-group (re s index match)
  47. (let* ((re (funcall re))
  48. (s (funcall s))
  49. (index (funcall index))
  50. (match (funcall match))
  51. (matches? (string-match re s))
  52. (result (and matches? (match-string index s))))
  53. (if (and matches? (equal result match))
  54. (cons t (format "Expected %S not to match %S with %S in group %s"
  55. re s match index))
  56. (cons nil (format "Expected %S to match %S with %S in group %s, %s"
  57. re s match index
  58. (if matches?
  59. (format "but got %S" result)
  60. "but did not match"))))))
  61. ;;; Emacs feature matchers
  62. (buttercup-define-matcher :to-be-live (buffer)
  63. (let ((buffer (get-buffer (funcall buffer))))
  64. (if (buffer-live-p buffer)
  65. (cons t (format "Expected %S not to be a live buffer, but it is"
  66. buffer))
  67. (cons nil (format "Expected %S to be a live buffer, but it is not"
  68. buffer)))))
  69. (buttercup-define-matcher :to-be-visible (buffer)
  70. (let ((buffer (get-buffer (funcall buffer))))
  71. (cond
  72. ((and buffer (get-buffer-window buffer))
  73. (cons t (format "Expected %S not to be a visible buffer, but it is"
  74. buffer)))
  75. ((not (bufferp buffer))
  76. (cons nil
  77. (format "Expected %S to be a visible buffer, but it is not a buffer"
  78. buffer)))
  79. (t (cons
  80. nil
  81. (format "Expected %S to be a visible buffer, but it is not visible"
  82. buffer))))))
  83. (buttercup-define-matcher :to-be-local (symbol)
  84. (let ((symbol (funcall symbol)))
  85. (if (local-variable-p symbol)
  86. (cons t (format "Expected %S not to be a local variable, but it is"
  87. symbol))
  88. (cons nil (format "Expected %S to be a local variable, but it is not"
  89. symbol)))))
  90. (buttercup-define-matcher :to-contain-match (buffer re)
  91. (let ((buffer (funcall buffer))
  92. (re (funcall re)))
  93. (if (not (get-buffer buffer))
  94. (cons nil (format "Expected %S to contain a match of %s, \
  95. but is not a buffer" buffer re))
  96. (with-current-buffer buffer
  97. (save-excursion
  98. (goto-char (point-min))
  99. (if (re-search-forward re nil 'noerror)
  100. (cons t (format "Expected %S to contain a match \
  101. for %s, but it did not" buffer re))
  102. (cons nil (format "Expected %S not to contain a match for \
  103. %s but it did not." buffer re))))))))
  104. ;;; Flycheck matchers
  105. (buttercup-define-matcher :to-be-equal-flycheck-errors (a b)
  106. (let* ((a (funcall a))
  107. (b (funcall b))
  108. (a-formatted (flycheck-buttercup-format-error-list a))
  109. (b-formatted (flycheck-buttercup-format-error-list b)))
  110. (if (equal a b)
  111. (cons t (format "Expected
  112. %s
  113. not to be equal to
  114. %s" a-formatted b-formatted))
  115. (cons nil (format "Expected
  116. %s
  117. to be equal to
  118. %s" a-formatted b-formatted)))))
  119. (provide 'flycheck-buttercup)
  120. ;; Disable byte compilation for this library, to prevent package.el choking on a
  121. ;; missing `buttercup' library. See
  122. ;; https://github.com/flycheck/flycheck/issues/860
  123. ;; Local Variables:
  124. ;; no-byte-compile: t
  125. ;; End:
  126. ;;; flycheck-buttercup.el ends here