Skip to content

Test utils #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 1 addition & 5 deletions tests/haskell-font-lock-tests.el
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down
21 changes: 4 additions & 17 deletions tests/haskell-indentation-tests.el
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
60 changes: 60 additions & 0 deletions tests/haskell-test-utils.el
Original file line number Diff line number Diff line change
@@ -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
9 changes: 1 addition & 8 deletions tests/haskell-utils-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down