ein-testing-kernel.el 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; ein-testing-kernel.el --- Testing utilities for kernel module
  2. ;; Copyright (C) 2012 Takafumi Arakaki
  3. ;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
  4. ;; This file is NOT part of GNU Emacs.
  5. ;; ein-testing-kernel.el is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; ein-testing-kernel.el is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with ein-testing-kernel.el. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (eval-when-compile (require 'cl))
  19. (require 'ert)
  20. (require 'ein-kernel)
  21. ;;; Test `ein:kernel-construct-help-string'
  22. (defvar ein:testing-kernel-construct-help-string-pcallsig-list
  23. '(nil :call_def :init_definition :definition))
  24. (defvar ein:testing-kernel-construct-help-string-pdocstring-list
  25. '(nil :call_docstring :init_docstring :docstring))
  26. (defun ein:testing-kernel-construct-help-string-test-func (content result)
  27. (should (equal (ein:kernel-construct-help-string content) result)))
  28. (defun ein:testing-kernel-construct-help-string-loop
  29. (&optional test pcallsig-list pdocstring-list)
  30. "Run tests for `ein:kernel-construct-help-string-loop'.
  31. TEST
  32. A function takes two arguments, namely CONTENT and RESULT.
  33. CONTENT is the argument to `ein:kernel-construct-help-string' and
  34. RESULT must match to its returned value. Use `should' to test
  35. equality.
  36. PCALLSIG-LIST
  37. `nil' or (subset of) `ein:testing-kernel-construct-help-string-pcallsig-list'.
  38. PDOCSTRING-LIST
  39. `nil' or (subset of) `ein:testing-kernel-construct-help-string-pdocstring-list'.
  40. All combinations of PCALLSIG-LIST and PDOCSTRING-LIST are used to
  41. construct CONTENT and RESULT."
  42. (unless test
  43. (setq test #'ein:testing-kernel-construct-help-string-test-func))
  44. (unless pcallsig-list
  45. (setq pcallsig-list
  46. ein:testing-kernel-construct-help-string-pcallsig-list))
  47. (unless pdocstring-list
  48. (setq pdocstring-list
  49. ein:testing-kernel-construct-help-string-pdocstring-list))
  50. (loop with callsig = "function(a=1, b=2, c=d)"
  51. with docstring = "This function does what."
  52. for pcallsig in pcallsig-list
  53. do (loop for pdoc in pdocstring-list
  54. for content = (append
  55. (when pcallsig (list pcallsig callsig))
  56. (when pdoc (list pdoc docstring)))
  57. for result = (ein:aif (append
  58. (when pcallsig (list callsig))
  59. (when pdoc (list docstring)))
  60. (ein:join-str "\n" it))
  61. do (funcall test content result))))
  62. (provide 'ein-testing-kernel)
  63. ;;; ein-testing-kernel.el ends here