PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/test/utils/test-helper.el

http://github.com/technomancy/clojure-mode
Emacs Lisp | 59 lines | 24 code | 16 blank | 19 comment | 1 complexity | 3ddc584264a2c36a76d5d1df173c79f0 MD5 | raw file
  1. ;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2014-2020 Bozhidar Batsov <bozhidar@batsov.com>
  3. ;; This file is not part of GNU Emacs.
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Non-interactive test suite setup.
  16. ;;; Code:
  17. (message "Running tests on Emacs %s" emacs-version)
  18. (let* ((current-file (if load-in-progress load-file-name (buffer-file-name)))
  19. (source-directory (locate-dominating-file current-file "Cask"))
  20. ;; Do not load outdated byte code for tests
  21. (load-prefer-newer t))
  22. ;; Load the file under test
  23. (load (expand-file-name "clojure-mode" source-directory)))
  24. (defmacro with-clojure-buffer (text &rest body)
  25. "Create a temporary buffer, insert TEXT, switch to clojure-mode and evaluate BODY."
  26. (declare (indent 1))
  27. `(with-temp-buffer
  28. (erase-buffer)
  29. (insert ,text)
  30. (clojure-mode)
  31. ,@body))
  32. (defmacro when-refactoring-it (description before after &rest body)
  33. "Return a buttercup spec.
  34. Insert BEFORE into a buffer, evaluate BODY and compare the resulting buffer to
  35. AFTER.
  36. BODY should contain the refactoring that transforms BEFORE into AFTER.
  37. DESCRIPTION is the description of the spec."
  38. (declare (indent 1))
  39. `(it ,description
  40. (with-clojure-buffer ,before
  41. ,@body
  42. (expect (buffer-string) :to-equal ,after))))
  43. ;;; test-helper.el ends here