diff --git a/Makefile b/Makefile index 98b871bb4..0a202c8c5 100644 --- a/Makefile +++ b/Makefile @@ -110,10 +110,11 @@ check-%: tests/%-tests.el $(BATCH) -l "$<" -f ert-run-tests-batch-and-exit; check: $(ELCHECKS) build-$(EMACS_VERSION) - $(BATCH) --eval "(when (>= emacs-major-version 24) \ + $(BATCH) --eval "(when (>= emacs-major-version 24) \ (require 'undercover) \ (undercover \"*.el\" (:exclude \"haskell-mode-pkg.el\")))" \ - $(patsubst %,-l %,$(ELCHECKS)) \ + -L tests \ + $(patsubst %,-l %,$(ELCHECKS)) \ -f ert-run-tests-batch-and-exit @TAB=$$(echo "\t"); \ if grep -Hn "[ $${TAB}]\+\$$" *.el; then \ diff --git a/tests/haskell-font-lock-tests.el b/tests/haskell-font-lock-tests.el index e25c0f241..616596b9f 100644 --- a/tests/haskell-font-lock-tests.el +++ b/tests/haskell-font-lock-tests.el @@ -1,12 +1,8 @@ (require 'ert) +(require 'haskell-test-utils) (require 'haskell-font-lock) (require 'haskell-mode) -(defun insert-lines (&rest lines) - (dolist (line lines) - (insert line) - (insert "\n"))) - ;; Emacs 24.3 has sql-mode that runs without a product and therefore ;; without font lock initially and needs to be extra enabled (add-hook 'sql-mode-hook (lambda () (sql-set-product 'ansi))) diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index f2466bca4..fb4255fe5 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -1,6 +1,7 @@ ;;; haskell-indentation-tests.el --- tests for indentation module -;; Copyright (C) 2015 Haskell Mode contributors +;; Copyright © 2015 Haskell Mode contributors. All rights reserved. +;; 2016 Arthur Fayzrakhmanov. ;; This file is not part of GNU Emacs. @@ -19,11 +20,12 @@ ;;; Commentary: -;; These are tests for `haskell-indentation-mode'. It's easy to add new +;; These are tests for `haskell-indentation-mode'. It's easy to add new ;; tests, just... (require 'cl-lib) (require 'ert) +(require 'haskell-test-utils) (require 'haskell-mode) (require 'haskell-font-lock) (require 'haskell-indentation) @@ -880,21 +882,6 @@ fun = if | guard1 -> expr1 (2 9) (3 0 11)) -(defmacro with-temp-switch-to-buffer (&rest body) - "Create a temporary buffer, use `switch-to-buffer' and evaluate BODY there like `progn'. - -Seems that `execute-kbd-macro' is not able to correctly execute keybindings without this." - (declare (indent 0) (debug t)) - (let ((temp-buffer (make-symbol "temp-buffer"))) - `(let ((,temp-buffer (generate-new-buffer " *temp*"))) - ;; FIXME: kill-buffer can change current-buffer in some odd cases. - (unwind-protect - (progn - (switch-to-buffer ,temp-buffer) - ,@body) - (and (buffer-name ,temp-buffer) - (kill-buffer ,temp-buffer)))))) - (ert-deftest haskell-indentation-ret-indents () (with-temp-switch-to-buffer (haskell-mode) diff --git a/tests/haskell-test-utils.el b/tests/haskell-test-utils.el new file mode 100644 index 000000000..7bdd63962 --- /dev/null +++ b/tests/haskell-test-utils.el @@ -0,0 +1,60 @@ +;;; haskell-test-utils.el --- Utilities for Haskell Mode tests. + +;; Copyright © 2016 Arthur Fayzrakhmanov. All rights reserved. + +;; This file is part of haskell-mode package. +;; You can contact with authors using GitHub issue tracker: +;; https://github.com/haskell/haskell-mode/issues + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; This package provides utilities for `haskell-mode' tests. + +;;; Code: + +(defun insert-lines (&rest lines) + "Insert all LINES in current buffer." + (let ((ls lines) + (line "")) + (while ls + (setq line (car ls)) + (setq ls (cdr ls)) + (when ls + (insert line) + (insert "\n"))) + (insert line))) + +(defmacro with-temp-switch-to-buffer (&rest body) + "Create a temporary buffer and evalute BODY there. +Uses `switch-to-buffer' and evaluates BODY in temp buffer like `progn'. + +Seems that `execute-kbd-macro' is not able to correctly execute +keybindings without this." + (declare (indent 0) (debug t)) + (let ((temp-buffer (make-symbol "temp-buffer"))) + `(let ((,temp-buffer (generate-new-buffer " *temp*"))) + ;; FIXME: kill-buffer can change current-buffer in some odd cases. + (unwind-protect + (progn + (switch-to-buffer ,temp-buffer) + ,@body) + (and (buffer-name ,temp-buffer) + (kill-buffer ,temp-buffer)))))) + +(provide 'haskell-test-utils) +;;; haskell-test-utils.el ends here diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index 0bbb02355..1c57cf126 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -28,13 +28,9 @@ ;;; Code: (require 'ert) +(require 'haskell-test-utils) (require 'haskell-utils) -(defun insert-lines (&rest lines) - "Insert all LINES in current buffer." - (dolist (line lines) - (insert (concat line "\n")))) - (ert-deftest simple-import-parse () (should (equal "A.B.C" (with-temp-buffer @@ -166,9 +162,6 @@ strings will change in future." (setq test-b-points (point)) ;; go to the end of do-block (goto-char (point-max)) - ;; note `insert-line' inserts one extra newline, go up one line - (forward-line -1) - (goto-char (line-end-position)) (setq test-b-points `(,test-b-points . ,(point))) (setq test-a-result (haskell-utils-compose-type-at-command test-a-points))