Changeset - 42c889c3a786
[Not reviewed]
0 3 0
Sergey Pashinin - 11 years ago 2014-08-28 00:26:26
sergey@pashinin.com
more tests
3 files changed with 93 insertions and 150 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
@@ -3,7 +3,7 @@
 
EMACS ?= emacs
 
TEST_DIR = src
 
TRAVIS_FILE = .travis.yml
 
EFLAGS ?= -L ../cl-lib -L src -L . -L tests
 
EFLAGS ?= -L ../cl-lib -L src -L . -L tests -L deps
 
BATCH = $(EMACS) $(EFLAGS) -batch -Q
 
NOBATCH = $(EMACS) --debug-init $(EFLAGS) -Q
 
NOBATCHE = $(NOBATCH) -eval
 
@@ -16,11 +16,18 @@ WGCMD = ${EMACS} $(FLAGSWG) --debug-init --eval
 
clean:
 
	find . -name '*.elc' -delete
 

	
 
.PHONY: deps
 
deps:
 
	curl https://raw.githubusercontent.com/rejeep/f.el/master/f.el -o f.el
 
	curl https://raw.githubusercontent.com/magnars/s.el/master/s.el -o s.el
 
	curl https://raw.githubusercontent.com/magnars/dash.el/master/dash.el -o dash.el
 
	curl https://raw.githubusercontent.com/rolandwalker/anaphora/master/anaphora.el -o anaphora.el
 
	mkdir -p deps;
 
	if [ ! -f deps/f.el ];               then curl https://raw.githubusercontent.com/rejeep/f.el/master/f.el -o deps/f.el; fi;
 
	if [ ! -f deps/s.el ];               then curl https://raw.githubusercontent.com/magnars/s.el/master/s.el -o deps/s.el; fi;
 
	if [ ! -f deps/dash.el ];            then curl https://raw.githubusercontent.com/magnars/dash.el/master/dash.el -o deps/dash.el; fi;
 
	if [ ! -f deps/anaphora.el ];        then curl https://raw.githubusercontent.com/rolandwalker/anaphora/master/anaphora.el -o deps/anaphora.el; fi;
 
	if [ ! -f deps/magit.el ];           then curl https://raw.githubusercontent.com/magit/magit/master/magit.el -o deps/magit.el; fi;
 
	if [ ! -f deps/git-commit-mode.el ]; then curl https://raw.githubusercontent.com/magit/git-modes/master/git-commit-mode.el -o deps/git-commit-mode.el; fi;
 
	if [ ! -f deps/git-rebase-mode.el ]; then curl https://raw.githubusercontent.com/magit/git-modes/master/git-rebase-mode.el -o deps/git-rebase-mode.el; fi;
 
	if [ ! -f deps/magit-key-mode.el ];  then curl https://raw.githubusercontent.com/magit/magit/master/magit-key-mode.el -o deps/magit-key-mode.el; fi;
 

	
 

	
 
.PHONY: test
 
test: $(ELCS)
 
@@ -28,7 +35,7 @@ test: $(ELCS)
 
	(require 'cl) \
 
	(require 'ert) \
 
	(put 'flet 'byte-obsolete-info nil))" \
 
	-l tests/workgroups2-tests.el -f ert-run-tests-batch-and-exit
 
	-l tests/ert-my-utils.el -l tests/workgroups2-tests.el -f ert-run-tests-batch-and-exit
 

	
 

	
 
.PHONY: testgui
 
@@ -37,6 +44,6 @@ testgui: $(ELCS)
 
	(require 'cl) \
 
	(require 'ert) \
 
	(put 'flet 'byte-obsolete-info nil))" \
 
	-l tests/workgroups2-tests.el -f my-ert-run-tests
 
	-l tests/ert-my-utils.el -l tests/workgroups2-tests.el -f my-ert-run-tests
 
	if [ -f /tmp/wg-tests.log ]; then cat /tmp/wg-tests.log; exit 1; fi;
 
	if [ -f /tmp/wg-tests-ok.log ]; then cat /tmp/wg-tests-ok.log; fi;
tests/ert-my-utils.el
Show inline comments
 
@@ -5,6 +5,8 @@
 
;;
 
;;; Code:
 

	
 
(require 'cl-lib)
 
(require 'f)
 
(require 'ert)
 

	
 
(defun wg-tests-log (&optional ok)
 
@@ -18,145 +20,27 @@
 
(defun ert--run-test-internal (test-execution-info)
 
  "Low-level function to run a test according to TEST-EXECUTION-INFO.
 

	
 
This mainly sets up debugger-related bindings."
 
My version without `save-window-excursion'."
 
  (setf (ert--test-execution-info-next-debugger test-execution-info) debugger
 
        (ert--test-execution-info-ert-debug-on-error test-execution-info)
 
        ert-debug-on-error)
 
  (catch 'ert--pass
 
    ;; For now, each test gets its own temp buffer and its own
 
    ;; window excursion, just to be safe.  If this turns out to be
 
    ;; too expensive, we can remove it.
 
    ;;(with-temp-buffer
 
      ;;(save-window-excursion
 
      (let ((debugger (lambda (&rest args)
 
                        (ert--run-test-debugger test-execution-info
 
                                                args)))
 
            (debug-on-error t)
 
            (debug-on-quit t)
 
            ;; FIXME: Do we need to store the old binding of this
 
            ;; and consider it in `ert--run-test-debugger'?
 
            (debug-ignored-errors nil)
 
            (ert--infos '()))
 
        (funcall (ert-test-body (ert--test-execution-info-test
 
                                 test-execution-info))))
 
      ;;)
 
    ;;)
 
    ;;(save-window-excursion
 
    (let ((debugger (lambda (&rest args)
 
                      (ert--run-test-debugger test-execution-info args)))
 
          (debug-on-error t)
 
          (debug-on-quit t)
 
          (debug-ignored-errors nil)
 
          (ert--infos '()))
 
      (funcall (ert-test-body (ert--test-execution-info-test
 
                               test-execution-info))))
 
    ;;))
 
    (ert-pass))
 
  (setf (ert--test-execution-info-result test-execution-info)
 
        (make-ert-test-passed))
 
  nil)
 

	
 

	
 
(defun ert-run-tests-batch (&optional selector)
 
  "Run the tests specified by SELECTOR, printing results to the terminal.
 

	
 
SELECTOR works as described in `ert-select-tests', except if
 
SELECTOR is nil, in which case all tests rather than none will be
 
run; this makes the command line \"emacs -batch -l my-tests.el -f
 
ert-run-tests-batch-and-exit\" useful.
 

	
 
Returns the stats object."
 
  (unless selector (setq selector 't))
 
  (ert-run-tests
 
   selector
 
   (lambda (event-type &rest event-args)
 
     (cl-ecase event-type
 
       (run-started
 
        (cl-destructuring-bind (stats) event-args
 
          (message "Running %s tests (%s)"
 
                   (length (ert--stats-tests stats))
 
                   (ert--format-time-iso8601 (ert--stats-start-time stats)))))
 
       (run-ended
 
        (cl-destructuring-bind (stats abortedp) event-args
 
          (let ((unexpected (ert-stats-completed-unexpected stats))
 
                (skipped (ert-stats-skipped stats))
 
                (expected-failures (ert--stats-failed-expected stats)))
 
            (message "\n%sRan %s tests, %s results as expected%s%s (%s)%s\n"
 
                     (if (not abortedp)
 
                         ""
 
                       "Aborted: ")
 
                     (ert-stats-total stats)
 
                     (ert-stats-completed-expected stats)
 
                     (if (zerop unexpected)
 
                         ""
 
                       (format ", %s unexpected" unexpected))
 
                     (if (zerop skipped)
 
                         ""
 
                       (format ", %s skipped" skipped))
 
                     (ert--format-time-iso8601 (ert--stats-end-time stats))
 
                     (if (zerop expected-failures)
 
                         ""
 
                       (format "\n%s expected failures" expected-failures)))
 
            (unless (zerop unexpected)
 
              (message "%s unexpected results:" unexpected)
 
              (cl-loop for test across (ert--stats-tests stats)
 
                       for result = (ert-test-most-recent-result test) do
 
                       (when (not (ert-test-result-expected-p test result))
 
                         (message "%9s  %S"
 
                                  (ert-string-for-test-result result nil)
 
                                  (ert-test-name test))))
 
              (message "%s" ""))
 
            (unless (zerop skipped)
 
              (message "%s skipped results:" skipped)
 
              (cl-loop for test across (ert--stats-tests stats)
 
                       for result = (ert-test-most-recent-result test) do
 
                       (when (ert-test-result-type-p result :skipped)
 
                         (message "%9s  %S"
 
                                  (ert-string-for-test-result result nil)
 
                                  (ert-test-name test))))
 
              (message "%s" "")))))
 
       (test-started
 
        )
 
       (test-ended
 
        (cl-destructuring-bind (stats test result) event-args
 
          (unless (ert-test-result-expected-p test result)
 
            (cl-etypecase result
 
              (ert-test-passed
 
               (message "Test %S passed unexpectedly" (ert-test-name test)))
 
              (ert-test-result-with-condition
 
               (message "Test %S backtrace:" (ert-test-name test))
 
               (with-temp-buffer
 
                 (ert--print-backtrace (ert-test-result-with-condition-backtrace
 
                                        result))
 
                 (goto-char (point-min))
 
                 (while (not (eobp))
 
                   (let ((start (point))
 
                         (end (progn (end-of-line) (point))))
 
                     (setq end (min end
 
                                    (+ start ert-batch-backtrace-right-margin)))
 
                     (message "%s" (buffer-substring-no-properties
 
                                    start end)))
 
                   (forward-line 1)))
 
               (with-temp-buffer
 
                 (ert--insert-infos result)
 
                 (insert "    ")
 
                 (let ((print-escape-newlines t)
 
                       (print-level 5)
 
                       (print-length 10))
 
                   (ert--pp-with-indentation-and-newline
 
                    (ert-test-result-with-condition-condition result)))
 
                 (goto-char (1- (point-max)))
 
                 (cl-assert (looking-at "\n"))
 
                 (delete-char 1)
 
                 (message "Test %S condition:" (ert-test-name test))
 
                 (message "%s" (buffer-string))))
 
              (ert-test-aborted-with-non-local-exit
 
               (message "Test %S aborted with non-local exit"
 
                        (ert-test-name test)))
 
              (ert-test-quit
 
               (message "Quit during %S" (ert-test-name test)))))
 
          (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
 
                 (format-string (concat "%9s  %"
 
                                        (prin1-to-string (length max))
 
                                        "s/" max "  %S")))
 
            (message format-string
 
                     (ert-string-for-test-result result
 
                                                 (ert-test-result-expected-p
 
                                                  test result))
 
                     (1+ (ert--stats-test-pos stats test))
 
                     (ert-test-name test)))))))))
 

	
 

	
 
(defun my-ert-run-tests ()
 
  "My variant of `ert-run-tests-batch-and-exit'.
 
To hack this:
 
@@ -177,5 +61,29 @@ http://stackoverflow.com/questions/25490989/how-should-i-run-emacs-ert-tests-whe
 
      (kill-emacs 0)
 
      )))
 

	
 
(defmacro wg-test-special (mode pkg &rest body)
 
  "Test restoring MODE from PKG.
 
Create needed buffer by executing BODY.
 
Then tests will follow to save it and restore."
 
  (declare (indent 2))
 
  `(let ((wg-log-level 0)
 
         message-log-max)
 
     ;; prepare
 
     (delete-other-windows)
 
     (switch-to-buffer wg-default-buffer)
 

	
 
     ;; create a buffer
 
     (require ,pkg)
 
     ,@body
 
     (should (eq major-mode ,mode))
 
     (wg-save-session)
 

	
 
     ;; save and restore
 
     (workgroups-mode 0)
 
     (switch-to-buffer wg-default-buffer)
 
     (workgroups-mode 1)
 
     (should (eq major-mode ,mode))
 
     ))
 

	
 
(provide 'ert-my-utils)
 
;;; ert-my-utils.el ends here
tests/workgroups2-tests.el
Show inline comments
 
@@ -2,10 +2,8 @@
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'cl)
 
(require 'ert)
 
(require 'cl-lib)
 
(require 'f)
 
(load-file (concat (file-name-directory load-file-name) "ert-my-utils.el"))
 
(require 'workgroups2)
 

	
 
;;(defmacro w-all-buf-uids (value)
 
@@ -14,11 +12,6 @@
 
;;  `(progn
 
;;     (defface ,face ,spec ,doc ,@args)))
 

	
 
(defmacro test-pickel (value)
 
  "Test `wg-pickel' `wg-unpickel' on VALUE."
 
  `(progn
 
     (wg-unpickel (wg-pickel ,value))))
 

	
 
(ert-deftest 000-initial ()
 
  ;;(make-frame)
 
  (if (file-exists-p "/tmp/wg-tests.log")
 
@@ -35,7 +28,8 @@
 
  ;;    (delete-file "/tmp/wg-test"))
 
  (setq wg-session-file "/tmp/wg-test")
 
  ;;(setq wg-session-load-on-start nil)
 
  (workgroups-mode 1)
 
  (let (message-log-max)
 
    (workgroups-mode 1))
 
  (should workgroups-mode)
 
  (should (string= (wg-get-session-file) "/tmp/wg-test")))
 

	
 
@@ -93,13 +87,19 @@
 

	
 
(ert-deftest 100-wg-save ()
 
  (should (= (length (frame-list)) 1))
 
  (wg-save-session)
 
  (let (message-log-max)
 
    (wg-save-session))
 
  (should-not (wg-session-modified (wg-current-session)))
 
  (unless (string-equal "initial_terminal" (terminal-name (selected-frame)))
 
    (unless (file-exists-p "/tmp/wg-test")
 
      (error "WG session file wasn't created"))))
 

	
 

	
 
(defmacro test-pickel (value)
 
  "Test `wg-pickel' `wg-unpickel' on VALUE."
 
  `(progn
 
     (wg-unpickel (wg-pickel ,value))))
 

	
 
(ert-deftest 110-wg-pickel ()
 
  (test-pickel 123)
 
  (test-pickel "str")
 
@@ -107,15 +107,43 @@
 
  (test-pickel (current-buffer))
 
  ;; (get-buffer org-agenda-buffer-name)
 
  (test-pickel (point-marker))
 
  (test-pickel (list 'describe-variable 'help-xref-stack-item (get-buffer "*Help*")))
 
  ;; TODO:
 
  ;;(test-pickel (current-window-configuration))
 
  )
 

	
 

	
 
;;(ert-deftest 300-inferior-python-mode ()
 
;;  (delete-other-windows)
 
;;  (switch-to-buffer wg-default-buffer)
 
;;  )
 

	
 
;;
 
;; Special buffers
 
;;
 

	
 
(require 'python)
 
(ert-deftest 300-special-modes ()
 
  (wg-test-special 'dired-mode 'dired
 
    (dired "/tmp"))
 

	
 
  (wg-test-special 'Info-mode 'info
 
    (info))
 

	
 
  (wg-test-special 'help-mode 'help-mode
 
    (describe-variable 'help-xref-stack-item)
 
    (switch-to-buffer "*Help*"))
 

	
 
  (wg-test-special 'magit-status-mode 'magit
 
    (magit-status "."))
 

	
 
  (wg-test-special 'shell-mode 'shell
 
    (shell))
 

	
 
  (wg-test-special 'term-mode 'term
 
    (term "/bin/sh"))
 

	
 
  (wg-test-special 'inferior-python-mode 'python
 
    (run-python python-shell-interpreter)
 
    (switch-to-buffer (process-buffer (python-shell-get-or-create-process))))
 

	
 
  )
 

	
 
(provide 'workgroups2-tests)
 
;;; workgroups2-tests.el ends here
0 comments (0 inline, 0 general)