ein-testing.el 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; ein-testing.el --- Tools for testing
  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.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.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.el. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (require 'ein-log)
  19. (defmacro ein:setq-if-not (sym val)
  20. `(unless ,sym (setq ,sym ,val)))
  21. (defvar ein:testing-dump-file-log nil
  22. "File to save buffer specified by `ein:log-all-buffer-name'.")
  23. (defvar ein:testing-dump-file-messages nil
  24. "File to save the ``*Messages*`` buffer.")
  25. (defvar ein:testing-dump-file-debug nil)
  26. (defun ein:testing-save-buffer (buffer-or-name file-name)
  27. (when (and buffer-or-name file-name)
  28. (with-current-buffer (get-buffer buffer-or-name)
  29. (write-region (point-min) (point-max) file-name))))
  30. (defun ein:testing-dump-logs ()
  31. (ein:testing-save-buffer "*Messages*" ein:testing-dump-file-messages)
  32. (ein:testing-save-buffer ein:log-all-buffer-name ein:testing-dump-file-log))
  33. (defvar ein:testing-dump-logs--saved nil)
  34. (defun ein:testing-dump-logs-noerror ()
  35. (if ein:testing-dump-logs--saved
  36. (message "EIN:TESTING-DUMP-LOGS-NOERROR called but already saved.")
  37. (condition-case err
  38. (progn (ein:testing-dump-logs)
  39. (setq ein:testing-dump-logs--saved t))
  40. (error
  41. (message "Error while executing EIN:TESTING-DUMP-LOGS. err = %S"
  42. err)
  43. (when ein:testing-dump-file-debug
  44. (signal (car err) (cdr err)))))))
  45. (defadvice ert-run-tests-batch (after ein:testing-dump-logs-hook activate)
  46. "Hook `ein:testing-dump-logs-noerror' because `kill-emacs-hook'
  47. is not run in batch mode before Emacs 24.1."
  48. (ein:testing-dump-logs-noerror))
  49. (add-hook 'kill-emacs-hook #'ein:testing-dump-logs-noerror)
  50. (provide 'ein-testing)
  51. ;;; ein-testing.el ends here