~a-roehler/s-x-emacs-werkstatt/trunk

« back to all changes in this revision

Viewing changes to thingatpt-utils-core/test/ar-setup-ert-tests.el

  • Committer: Andreas Röhler
  • Date: 2016-10-06 09:41:19 UTC
  • Revision ID: andreas.roehler@online.de-20161006094119-g49r1wy2kh07de1s
thingatpt-utils-core new dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; sh-werk-setup-ert-tests.el --- Provide needed forms
 
2
 
 
3
;; Copyright (C) 2015  Andreas Röhler
 
4
 
 
5
;; Author: Andreas Röhler <andreas.roehler@easy-emacs.de>
 
6
 
 
7
;; Keywords: lisp
 
8
 
 
9
;; This program is free software; you can redistribute it and/or modify
 
10
;; it under the terms of the GNU General Public License as published by
 
11
;; the Free Software Foundation, either version 3 of the License, or
 
12
;; (at your option) any later version.
 
13
 
 
14
;; This program is distributed in the hope that it will be useful,
 
15
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
;; GNU General Public License for more details.
 
18
 
 
19
;; You should have received a copy of the GNU General Public License
 
20
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
;;; Commentary:
 
23
 
 
24
;;; Code:
 
25
 
 
26
(defvar ar-switch-p nil
 
27
  "Switch into test-buffer.")
 
28
 
 
29
(defcustom ar-switch-p nil
 
30
  ""
 
31
  :type 'boolean
 
32
  :group 'werkstatt)
 
33
 
 
34
(defun ar-toggle-switch-p ()
 
35
  "Toggle `ar-switch-p'. "
 
36
  (interactive)
 
37
  (setq ar-switch-p (not ar-switch-p))
 
38
  (message "ar-switch-p: %s"  ar-switch-p))
 
39
 
 
40
(defmacro ar-test-with-temp-buffer (contents &rest body)
 
41
  "Create temp buffer inserting CONTENTS.
 
42
BODY is code to be executed within the temp buffer.  Point is
 
43
 at the end of buffer."
 
44
  (declare (indent 2) (debug t))
 
45
  `(with-temp-buffer
 
46
     (let (hs-minor-mode)
 
47
       (insert ,contents)
 
48
       (when ar-switch-p
 
49
         (switch-to-buffer (current-buffer)))
 
50
       (font-lock-fontify-buffer)
 
51
       ,@body)))
 
52
 
 
53
(defmacro ar-test-with-temp-buffer-point-min (contents &rest body)
 
54
  "Create temp buffer inserting CONTENTS.
 
55
BODY is code to be executed within the temp buffer.  Point is
 
56
 at the end of buffer."
 
57
  (declare (indent 2) (debug t))
 
58
  `(with-temp-buffer
 
59
     (let (hs-minor-mode)
 
60
       (insert ,contents)
 
61
       (goto-char (point-min))
 
62
       (when ar-switch-p
 
63
         (switch-to-buffer (current-buffer)))
 
64
       (font-lock-fontify-buffer)
 
65
       ,@body)))
 
66
 
 
67
(defmacro ar-test-with-python-buffer-point-min (contents &rest body)
 
68
  "Create temp buffer in `python-mode' inserting CONTENTS.
 
69
BODY is code to be executed within the temp buffer.  Point is
 
70
 at the beginning of buffer."
 
71
  (declare (indent 1) (debug t))
 
72
  `(with-temp-buffer
 
73
     (let (hs-minor-mode)
 
74
       (python-mode)
 
75
       (insert ,contents)
 
76
       (goto-char (point-min))
 
77
       (when ar-switch-p
 
78
         (switch-to-buffer (current-buffer)))
 
79
       (font-lock-fontify-buffer)
 
80
       ,@body)))
 
81
 
 
82
(defmacro ar-test-with-python-buffer (contents &rest body)
 
83
  "Create temp buffer in `python-mode' inserting CONTENTS.
 
84
BODY is code to be executed within the temp buffer.  Point is
 
85
 at the end of buffer."
 
86
  (declare (indent 1) (debug t))
 
87
  `(with-temp-buffer
 
88
     (let (hs-minor-mode)
 
89
       (python-mode)
 
90
       (insert ,contents)
 
91
       (when ar-switch-p
 
92
         (switch-to-buffer (current-buffer)))
 
93
       (font-lock-fontify-buffer)
 
94
       ;; (message "ERT %s" (point))
 
95
       ,@body)))
 
96
 
 
97
(defmacro ar-test-with-haskell-buffer-point-min (contents &rest body)
 
98
  "Create temp buffer in `haskell-mode' inserting CONTENTS.
 
99
BODY is code to be executed within the temp buffer.  Point is
 
100
 at the beginning of buffer."
 
101
  (declare (indent 1) (debug t))
 
102
  `(with-temp-buffer
 
103
     (let (hs-minor-mode)
 
104
       (haskell-mode)
 
105
       (insert ,contents)
 
106
       (goto-char (point-min))
 
107
       (when ar-switch-p
 
108
         (switch-to-buffer (current-buffer)))
 
109
       (font-lock-fontify-buffer)
 
110
       ,@body)))
 
111
 
 
112
(defmacro ar-test-with-haskell-buffer (contents &rest body)
 
113
  "Create temp buffer in `haskell-mode' inserting CONTENTS.
 
114
BODY is code to be executed within the temp buffer.  Point is
 
115
 at the end of buffer."
 
116
  (declare (indent 1) (debug t))
 
117
  `(with-temp-buffer
 
118
     (let (hs-minor-mode)
 
119
       (haskell-mode)
 
120
       (insert ,contents)
 
121
       (when ar-switch-p
 
122
         (switch-to-buffer (current-buffer)))
 
123
       (font-lock-fontify-buffer)
 
124
       ;; (message "ERT %s" (point))
 
125
       ,@body)))
 
126
 
 
127
(defmacro ar-test-with-elisp-buffer (contents &rest body)
 
128
  "Create temp buffer in `emacs-lisp-mode' inserting CONTENTS.
 
129
BODY is code to be executed within the temp buffer.  Point is
 
130
 at the end of buffer."
 
131
  (declare (indent 1) (debug t))
 
132
  `(with-temp-buffer
 
133
     (let (hs-minor-mode)
 
134
       (emacs-lisp-mode)
 
135
       (insert ,contents)
 
136
       (when ar-switch-p
 
137
         (switch-to-buffer (current-buffer)))
 
138
       (font-lock-fontify-buffer)
 
139
       ,@body)))
 
140
 
 
141
(defmacro ar-test-with-elisp-buffer-point-min (contents &rest body)
 
142
  "Create temp buffer inserting CONTENTS.
 
143
BODY is code to be executed within the temp buffer.  Point is
 
144
 at the end of buffer."
 
145
  (declare (indent 2) (debug t))
 
146
  `(with-temp-buffer
 
147
     (let (hs-minor-mode)
 
148
       (insert ,contents)
 
149
       (emacs-lisp-mode)
 
150
       (goto-char (point-min))
 
151
       (when ar-switch-p
 
152
         (switch-to-buffer (current-buffer)))
 
153
       (font-lock-fontify-buffer)
 
154
       ,@body)))
 
155
 
 
156
(defmacro ar-test-with-shell-script-buffer (contents &rest body)
 
157
  "Create temp buffer in shell-script mode inserting CONTENTS.
 
158
BODY is code to be executed within the temp buffer.  Point is
 
159
 at the end of buffer."
 
160
  (declare (indent 2) (debug t))
 
161
  `(with-temp-buffer
 
162
     (let (hs-minor-mode)
 
163
       (insert ,contents)
 
164
       (shell-script-mode)
 
165
       (when ar-switch-p
 
166
         (switch-to-buffer (current-buffer)))
 
167
       (font-lock-fontify-buffer)
 
168
       ,@body)))
 
169
 
 
170
(defmacro ar-test-with-shell-script-buffer-point-min (contents &rest body)
 
171
  "Create temp buffer inserting CONTENTS.
 
172
BODY is code to be executed within the temp buffer.  Point is
 
173
 at the end of buffer."
 
174
  (declare (indent 2) (debug t))
 
175
  `(with-temp-buffer
 
176
     (let (hs-minor-mode)
 
177
       (insert ,contents)
 
178
       (shell-script-mode)
 
179
       (goto-char (point-min))
 
180
       (when ar-switch-p
 
181
         (switch-to-buffer (current-buffer)))
 
182
       (font-lock-fontify-buffer)
 
183
       ,@body)))
 
184
 
 
185
(provide 'ar-setup-ert-tests)
 
186
;; sh-werk-setup-ert-tests.el ends here