add-log-tests.el 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; add-log-tests.el --- Test suite for add-log.
  2. ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
  3. ;; Author: Masatake YAMATO <yamato@redhat.com>
  4. ;; Keywords: vc tools
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Code:
  17. (require 'ert)
  18. (require 'add-log)
  19. (defmacro add-log-current-defun-deftest (name doc major-mode
  20. content marker expected-defun)
  21. "Generate an ert test for mode-own `add-log-current-defun-function'.
  22. Run `add-log-current-defun' at the point where MARKER specifies in a
  23. buffer which content is CONTENT under MAJOR-MODE. Then it compares the
  24. result with EXPECTED-DEFUN."
  25. (let ((xname (intern (concat "add-log-current-defun-test-"
  26. (symbol-name name)
  27. ))))
  28. `(ert-deftest ,xname ()
  29. ,doc
  30. (with-temp-buffer
  31. (insert ,content)
  32. (goto-char (point-min))
  33. (funcall ',major-mode)
  34. (should (equal (when (search-forward ,marker nil t)
  35. (replace-match "" nil t)
  36. (add-log-current-defun))
  37. ,expected-defun))))))
  38. (add-log-current-defun-deftest
  39. sh-func1
  40. "Test sh-current-defun-name can find function."
  41. sh-mode "
  42. function foo
  43. {
  44. ><
  45. }" "><" "foo")
  46. (add-log-current-defun-deftest
  47. sh-func2
  48. "Test sh-current-defun-name can find function."
  49. sh-mode "
  50. foo()
  51. {
  52. ><
  53. }" "><" "foo")
  54. (add-log-current-defun-deftest
  55. sh-func3
  56. "Test sh-current-defun-name can find function."
  57. sh-mode "
  58. function foo()
  59. {
  60. ><
  61. }" "><" "foo")
  62. (add-log-current-defun-deftest
  63. sh-var
  64. "Test sh-current-defun-name can find variable definition."
  65. sh-mode "
  66. PATH=a:/ab:/usr/abc
  67. DIR=/pr><oc"
  68. "><" "DIR")
  69. (provide 'add-log-tests)
  70. ;;; add-log-tests.el ends here