]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/tests/nxhtmltest-suites.el
5af8ab8135225993ba55f861f717758ad9241620
[.emacs.d.git] / emacs / nxhtml / tests / nxhtmltest-suites.el
1 ;;; nxhtmltest-suites.el --- Test suites for mumamo / nXhtml
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-07-08T20:17:36+0200 Tue
5 ;; Version: 0.12
6 ;; Last-Updated: 2008-09-01T01:13:28+0200 Sun
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 ;;
13 ;;; Commentary:
14 ;;
15 ;; Defines `nxhtmltest-run'.  When (getenv "nxhtmltest-run-Q")
16 ;; returns non-nil also runs this function.
17 ;;
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;;
20 ;;; Change log:
21 ;;
22 ;; Added code from Christian Ohler for writing ert tests.
23 ;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;
26 ;; This program is free software; you can redistribute it and/or
27 ;; modify it under the terms of the GNU General Public License as
28 ;; published by the Free Software Foundation; either version 2, or
29 ;; (at your option) any later version.
30 ;;
31 ;; This program is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34 ;; General Public License for more details.
35 ;;
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with this program; see the file COPYING.  If not, write to
38 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
39 ;; Floor, Boston, MA 02110-1301, USA.
40 ;;
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 ;;
43 ;;; Code:
44
45 ;;(eval-when-compile (require 'cl))
46 (eval-when-compile (require 'cl))
47 (eval-when-compile (require 'rng-valid))
48 (eval-when-compile (require 'rngalt))
49 (require 'mumamo)
50 (require 'mumamo-fun)
51 (require 'nxhtml)
52 (require 'nxhtml-mumamo)
53 (when (fboundp 'nxml-mode)
54   (require 'rng-valid)
55   (require 'rngalt))
56
57 (setq debug-on-error t)
58
59 (defvar nxhtmltest-ert-default-selector "nxhtml-ert-"
60   "Set this to run a single test with `nxhtmltest-run-Q'.")
61
62 (defvar nxhtmltest-bin
63   (file-name-directory (if load-file-name load-file-name buffer-file-name)))
64
65 (pushnew nxhtmltest-bin load-path)
66 (require 'nxhtmltest-helpers)
67 ;;(require 'ert)
68
69 (defvar nxhtmltest-files-root
70   (let* ((this-dir nxhtmltest-bin)
71          (root (expand-file-name "in/" this-dir)))
72     (unless (file-accessible-directory-p root)
73           (error (if (file-exists-p root)
74                      "Can't read files in test directory %s"
75                    "Can't find test directory %s")
76                  root))
77     root))
78
79 (let ((distr-in "c:/EmacsW32/nxhtml/tests/in/"))
80   (when (file-directory-p distr-in)
81     (setq nxhtmltest-files-root distr-in)))
82
83 ;; (setq nxhtmltest-update-method
84 ;;       ;;'font-lock-wait
85 ;;       'font-lock-run-timers
86 ;;       ;;'font-lock-fontify-buffer
87 ;;       )
88
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90 ;; Define tests using ert.el
91
92 (ert-deftest nxhtml-ert-bug531328 ()
93   "Test of eRuby chunks with nothing between."
94   (ert-with-temp-buffer-include-file "bug531328.rhtml"
95     (add-hook 'ert-simulate-command-post-hook
96               'nxhtmltest-should-no-mumamo-errors
97               nil t)
98     (ert-simulate-command '(eruby-html-mumamo-mode) t)
99     (nxhtmltest-get-fontification-method)
100     (nxhtmltest-fontify-default-way 2 "trans")
101     (ert-simulate-command '(goto-char 12) t)
102     (ert-should (eq major-mode 'ruby-mode))
103     ))
104
105 (ert-deftest nxhtml-ert-indent-bug-johan-2010-02-17()
106   "Test of eRuby indentation.
107 Got a bug report by mail on the emacs-on-rails list."
108   (ert-with-temp-buffer-include-file "bug-johan-2010-02-17.erb"
109     (add-hook 'ert-simulate-command-post-hook
110               'nxhtmltest-should-no-mumamo-errors
111               nil t)
112     (ert-simulate-command '(eruby-html-mumamo-mode) t)
113     (nxhtmltest-fontify-default-way 2 "trans")
114     (ert-simulate-command '(mark-whole-buffer) t)
115     (ert-simulate-command '(indent-for-tab-command) t)
116     (nxhtmltest-goto-line 1)  (ert-should (= 0 (current-indentation)))
117     (nxhtmltest-goto-line 2)  (ert-should (= 2 (current-indentation)))
118     (nxhtmltest-goto-line 3)  (ert-should (= 0 (current-indentation)))
119     ))
120
121 (ert-deftest nxhtml-ert-indent-bug-johan-2010-02-12()
122   "Test of eRuby indentation.
123 Got a bug report by mail on the emacs-on-rails list."
124   (ert-with-temp-buffer-include-file "bug-johan-2010-02-12.rhtml"
125     (add-hook 'ert-simulate-command-post-hook
126               'nxhtmltest-should-no-mumamo-errors
127               nil t)
128     (ert-simulate-command '(eruby-html-mumamo-mode) t)
129     (nxhtmltest-fontify-default-way 2 "trans")
130     (ert-simulate-command '(mark-whole-buffer) t)
131     (ert-simulate-command '(indent-for-tab-command) t)
132     (nxhtmltest-goto-line 12)  (ert-should (= 2 (current-indentation)))
133     ))
134
135 ;;(setq nxhtmltest-ert-default-selector "nxhtml-ert-indent-rr-min8")
136 (ert-deftest nxhtml-ert-indent-rr-min8 ()
137   "Test of indentation bug.
138 As per Richard Riley's bug report 2009-10-08.  Last line gave an
139 error."
140   (ert-with-temp-buffer-include-file "rr-min8.php"
141     (add-hook 'ert-simulate-command-post-hook
142               'nxhtmltest-should-no-mumamo-errors
143               nil t)
144     (ert-simulate-command '(nxhtml-mumamo-mode) t)
145     (nxhtmltest-fontify-default-way 2 "trans")
146     (ert-simulate-command '(mark-whole-buffer) t)
147     (ert-simulate-command '(indent-for-tab-command) t)))
148
149 ;;(setq nxhtmltest-ert-default-selector "nxhtml-ert-bug-400415")
150 (ert-deftest nxhtml-ert-bug-400415-foo2 ()
151   "Test for changes before in-here-doc using 400415.
152 See URL `https://bugs.launchpad.net/nxhtml/+bug/400415'. This is
153 not the bug reported there however."
154   (ert-with-temp-buffer-include-file "bug400415-foo2.php"
155     (add-hook 'ert-simulate-command-post-hook
156               'nxhtmltest-should-no-mumamo-errors
157               nil t)
158     (ert-simulate-command '(nxhtml-mumamo-mode) t)
159     (nxhtmltest-fontify-default-way 2 "trans")
160     (ert-simulate-command '(goto-char 74) t)
161     (ert-should (eq major-mode 'sql-mode))
162     (ert-simulate-command '(goto-char 23) t)
163     (ert-simulate-command '(backward-delete-char-untabify 1) t)
164     (ert-simulate-command '(goto-char 74) t)
165     (ert-should (eq major-mode 'sql-mode))
166     ))
167
168 (ert-deftest nxhtml-ert-bug-300946-index ()
169   "Test for bug 300946 in Launchpad.
170 See URL `https://bugs.launchpad.net/nxhtml/+bug/300946'.  This is
171 a test for the file attached by Chris on 2008-12-02."
172   (ert-with-temp-buffer-include-file "bug-300946-index.html"
173     (add-hook 'ert-simulate-command-post-hook
174               'nxhtmltest-should-no-mumamo-errors
175               nil t)
176     (ert-simulate-command '(nxhtml-mumamo-mode) t)
177     (font-lock-mode 1)
178     ))
179
180 (ert-deftest nxhtml-ert-indent-bug290364 ()
181   "Test for bug 290364 in Launchpad.
182 See URL `https://bugs.launchpad.net/nxhtml/+bug/290364'.
183
184 Note: If this test fails Emacs loops.  Therefore the whole test
185 is included in a when clause so you can avoid it easily."
186   ;;(when t
187     (ert-with-temp-buffer-include-file "bug-290364.php"
188       (add-hook 'ert-simulate-command-post-hook
189                 'nxhtmltest-should-no-mumamo-errors
190                 nil t)
191       (ert-simulate-command '(nxhtml-mumamo-mode) t)
192       (font-lock-mode 1)
193       ))
194 ;)
195
196 (ert-deftest nxhtml-ert-indent-bug271497 ()
197   "Test for bug 271497 in Launchpad.
198 This is a bug in Emacs 22. It should work in Emacs 23 though.
199 See URL `https://bugs.launchpad.net/nxhtml/+bug/271497'."
200   (ert-with-temp-buffer-include-file "bug271497.txt"
201     (add-hook 'ert-simulate-command-post-hook
202               'nxhtmltest-should-no-mumamo-errors
203               nil t)
204     (load-file (ert-get-test-file-name "bug271497.el"))
205     (ert-simulate-command '(bug271497-mumamo) t)
206     ;;(font-lock-mode 1)
207     (nxhtmltest-fontify-default-way 2 "trans")
208     (ert-simulate-command '(goto-char 42) t)
209     (message "after goto-char 42")
210     (let ((ac42 after-change-functions)
211           ac88)
212       (ert-simulate-command '(goto-char 88) t)
213       (message "after goto-char 88")
214       (setq ac88 after-change-functions)
215       (ert-should (not (equal ac88 ac42))))))
216
217 (ert-deftest nxhtml-ert-indent-question43320 ()
218   "Test for question 43320 in Launchpad.
219 See URL `https://answers.launchpad.net/nxhtml/+question/43320'.
220
221 Note: This fails in Emacs 22, but should work in Emacs 23."
222 ;; I did see some problem here:
223
224 ;; - nXhtml 081222 + unpatched Emacs 081219 => ok
225 ;; - nXhtml 081222 + unpatched Emacs 081124 => ok
226 ;; - nXhtml 081222 + patched Emacs 081219 => ok
227
228 ;; - nXhtml 081222 + patched Emacs 081124 => ok, but it fails if I
229 ;;   use `nxhtmltest-run-Q'! I e, it fails if the autostart.el from
230 ;;   the nxhtml dir in 081222 is used - but not if the copy in
231 ;;   c:/EmacsW32 is used??? Which turned out to be if the old
232 ;;   php-mode was used ...
233
234   (ert-with-temp-buffer-include-file "question43320.html"
235     (add-hook 'ert-simulate-command-post-hook
236               'nxhtmltest-should-no-mumamo-errors
237               nil t)
238     (ert-simulate-command '(nxhtml-mumamo-mode) t)
239     (font-lock-mode 1)
240     (nxhtmltest-goto-line 25)  (ert-should (/= 14 (current-indentation)))
241     (put 'mumamo-submode-indent-offset-0 'permanent-local t)
242     (put 'mumamo-submode-indent-offset 'permanent-local t)
243     ;;
244     ;;(set (make-local-variable 'mumamo-submode-indent-offset-0) nil)
245     (set (make-local-variable 'mumamo-submode-indent-offset-0) 0)
246     (set (make-local-variable 'mumamo-submode-indent-offset) nil)
247     ;;(set (make-local-variable 'mumamo-submode-indent-offset) 2)
248     (ert-simulate-command '(mark-whole-buffer) t)
249     (ert-simulate-command '(indent-for-tab-command) t)
250     (nxhtmltest-goto-line 8)   (ert-should (= 8 (current-indentation)))
251     (nxhtmltest-goto-line 9)   (ert-should (= 0 (current-indentation)))
252     (nxhtmltest-goto-line 15)  (ert-should (= 8 (current-indentation)))
253     (nxhtmltest-goto-line 16)  (ert-should (= 8 (current-indentation)))
254     (nxhtmltest-goto-line 22)  (ert-should (= 6 (current-indentation)))
255     (nxhtmltest-goto-line 25)  (ert-should (= 4 (current-indentation)))
256     (nxhtmltest-goto-line 8) (indent-line-to 0)
257     ;;(message "before indent-for-tab-command")
258     (ert-simulate-command '(indent-for-tab-command) t)
259     ;;(message "after indent-for-tab-command")
260     (ert-should (= 8 (current-indentation)))
261     ;;
262     (set (make-local-variable 'mumamo-submode-indent-offset-0) 0)
263     (set (make-local-variable 'mumamo-submode-indent-offset) 2)
264     (ert-simulate-command '(mark-whole-buffer) t)
265     (ert-simulate-command '(indent-for-tab-command) t)
266     (nxhtmltest-goto-line 8)   (ert-should (= 8 (current-indentation)))
267     (nxhtmltest-goto-line 9)   (ert-should (= 10 (current-indentation)))
268     (nxhtmltest-goto-line 15)  (ert-should (= 8 (current-indentation)))
269     (nxhtmltest-goto-line 16)  (ert-should (= 8 (current-indentation)))
270     (nxhtmltest-goto-line 22)  (ert-should (= 16 (current-indentation)))
271     (nxhtmltest-goto-line 25)  (ert-should (= 14 (current-indentation)))
272     ))
273
274 (ert-deftest nxhtml-ert-only-php-no-end ()
275   "Check for nXml error."
276   (ert-with-temp-buffer-include-file "no-php-end-4.php"
277     (nxhtml-mumamo-mode)
278     (run-hooks 'after-change-major-mode-hook)
279     (run-hooks 'post-command-hook)
280     (nxhtmltest-fontify-default-way 2 "trans")
281     (rng-validate-mode 1)
282     ;;(rngalt-validate)
283     (ert-should (eq rng-validate-mode t))
284     (nxhtmltest-should-no-mumamo-errors)
285     (nxhtmltest-should-no-nxml-errors)
286     (goto-char 324)
287     (message "before insert, after-change-functions local=%s" after-change-functions)
288     (insert "\n")
289     (nxhtmltest-should-no-mumamo-errors)
290     (nxhtmltest-should-no-nxml-errors)))
291
292 (ert-deftest nxhtml-ert-xhtml-1.0-transitional ()
293   "Test XHTML 1.0 Transitional with `nxhtml-mumamo-mode'.
294 NOTICE: This test SHOULD FAIL because there is currently no rng
295 schema for transitional. The schema for strict is used instead
296 and the file is invalid then."
297   (ert-with-temp-buffer-include-file "lg-080813-label.html"
298     (nxhtml-mumamo-mode)
299     (nxhtmltest-fontify-default-way 2 "trans")
300     (rng-validate-mode 1)
301     (rngalt-validate)
302     (ert-should (eq rng-validate-mode t))
303     (nxhtmltest-should-no-mumamo-errors)
304 ;;;     (ert-should
305 ;;;      (not (eq (get-char-property 398 'category)
306 ;;;               'rng-error)))
307     (ert-should
308      (eq (get-text-property 398 'face)
309          'font-lock-function-name-face))
310     (ert-should-not
311      (= 0 rng-error-count))
312     ))
313
314 (ert-deftest nxhtml-ert-genshi-valid-in-genshi ()
315   (ert-with-temp-buffer-include-file "genshi-auto-mode.html"
316     (message "\n")
317     (genshi-nxhtml-mumamo-mode)
318     (font-lock-mode 1)
319     (mumamo-post-command)
320     (ert-should (eq font-lock-mode t))
321     (ert-should (eq major-mode 'nxhtml-genshi-mode))
322     (ert-should
323      (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
324                                      genshi-html-mumamo-mode)))
325     (nxhtmltest-fontify-default-way 2 "sheit")
326     (rng-validate-mode 1)
327     (rngalt-validate)
328     (ert-should (eq rng-validate-mode t))
329     (nxhtmltest-should-no-mumamo-errors)
330     (ert-should
331       (= 0 rng-error-count))))
332
333 (ert-deftest nxhtml-ert-genshi-invalid-in-nxhtml ()
334   (ert-with-temp-buffer-include-file "genshi-auto-mode.html"
335     (message "\n")
336     (nxhtml-mumamo-mode)
337     (nxhtmltest-fontify-default-way 2 "sheit")
338     (font-lock-mode 1)
339     (mumamo-post-command)
340     (rng-validate-mode 1)
341     (rngalt-validate)
342     (ert-should (eq rng-validate-mode t))
343     (nxhtmltest-should-no-mumamo-errors)
344     (ert-should
345       (= 2 rng-error-count))))
346
347 (ert-deftest nxhtml-ert-genshi-magic-mode ()
348   "Test if genshi file is recognized."
349   (let ((file1 (ert-get-test-file-name "genshi-auto-mode.html"))
350         buf1)
351     ;; Ensure we open the files
352     (setq buf1 (find-buffer-visiting file1))
353     (when buf1 (kill-buffer buf1))
354     ;; Open file 1
355     (setq buf1 (find-file file1))
356     (nxhtmltest-fontify-default-way 2 "mod")
357     (nxhtmltest-should-no-mumamo-errors)
358     (ert-should
359      (with-current-buffer buf1
360        (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
361                                        genshi-html-mumamo-mode))))
362     (kill-buffer buf1)))
363
364 (ert-deftest nxhtml-ert-genshi-auto-mode ()
365   "Test if file extension .ghtml is recognized."
366   (let ((file1 (ert-get-test-file-name "genshi-HelloWorldPage.ghtml"))
367         buf1)
368     ;; Ensure we open the files
369     (setq buf1 (find-buffer-visiting file1))
370     (when buf1 (kill-buffer buf1))
371     ;; Open file 1
372     (setq buf1 (find-file file1))
373     (nxhtmltest-fontify-default-way 2 "mod")
374     (nxhtmltest-should-no-mumamo-errors)
375     (ert-should
376      (with-current-buffer buf1
377        (memq mumamo-multi-major-mode '(genshi-nxhtml-mumamo-mode
378                                        genshi-html-mumamo-mode))))
379     (kill-buffer buf1)))
380
381 (ert-deftest nxhtml-ert-opened-modified ()
382   "Test if buffer get modified when opening a file."
383   (let ((file1 (ert-get-test-file-name "cvd-080805-ac.php"))
384         (file2 (ert-get-test-file-name "cvd-080805-cc.php"))
385         buf1
386         buf2)
387     ;; Ensure we open the files
388     (setq buf1 (find-buffer-visiting file1))
389     (when buf1 (kill-buffer buf1))
390     (setq buf2 (find-buffer-visiting file2))
391     (when buf2 (kill-buffer buf2))
392     ;; Open file 1
393     (setq buf1 (find-file file1))
394     (nxhtmltest-fontify-default-way 2 "mod")
395     (nxhtmltest-should-no-mumamo-errors)
396     ;; Open file 2
397     (setq buf2 (find-file file2))
398     (nxhtmltest-fontify-default-way 2 "mod")
399     (nxhtmltest-should-no-mumamo-errors)
400     (ert-should
401      (not (or (buffer-modified-p buf1)
402               (buffer-modified-p buf2))))
403     (kill-buffer buf1)
404     (kill-buffer buf2)))
405
406 (ert-deftest nxhtml-ert-wiki-strange-hili-080629 ()
407   "From a report on EmacsWiki."
408   (ert-with-temp-buffer-include-file "wiki-strange-hili-080629.html"
409     ;;(ert-should (not font-lock-mode))
410     (nxhtml-mumamo-mode)
411     ;;(ert-should (not font-lock-mode))
412     (nxhtmltest-fontify-default-way 2 "hili")
413     (goto-char 44)
414     (nxhtmltest-should-no-mumamo-errors)
415     (message "face at 44=%s" (get-text-property 44 'face))
416     (ert-should
417      (eq (get-text-property 44 'face)
418          'font-lock-function-name-face))))
419
420 (ert-deftest nxhtml-ert-indent-wiki-080708-ind-problem ()
421   (ert-with-temp-buffer-include-file "wiki-080708-ind-problem.rhtml"
422     (require 'ruby-mode nil t)
423     (if (not (featurep 'ruby-mode))
424         ;; Fix-me: ert should maybe have some way to just display
425         ;; informational messages?
426         (error "ruby-mode not available, skipping test")
427       ;;(ert-should (not font-lock-mode))
428       (eruby-nxhtml-mumamo-mode)
429       ;;(ert-should (not font-lock-mode))
430       (nxhtmltest-fontify-default-way 2 "ind")
431       (mark-whole-buffer)
432       (indent-for-tab-command)
433       (nxhtmltest-goto-line 3)
434       (nxhtmltest-should-no-mumamo-errors)
435       (ert-should (= (current-indentation) 0)))))
436
437 (ert-deftest nxhtml-ert-indent-wiki-080708-ind-problem-a ()
438   "From a report on EmacsWiki.
439 NOTICE: This SHOULD FAIL. There is currently no support for the
440 kind of indentation needed here.
441
442 Notice 2: For some reason I sometimes get the error overlayp, nil
443 here."
444   (ert-with-temp-buffer-include-file "wiki-080708-ind-problem.rhtml"
445     (require 'ruby-mode nil t)
446     (if (not (featurep 'ruby-mode))
447         (error "ruby-mode not available, skipping test")
448       ;;(ert-should (not font-lock-mode))
449       (eruby-nxhtml-mumamo-mode)
450       ;;(ert-should (not font-lock-mode))
451       (nxhtmltest-fontify-default-way 2 "ind")
452       (insert "  ")
453       (mark-whole-buffer)
454       (indent-for-tab-command)
455       (nxhtmltest-goto-line 3)
456       ;; Test
457       (nxhtmltest-should-no-mumamo-errors)
458       (ert-should-not (= (current-indentation) 2)))))
459
460 (ert-deftest nxhtml-ert-sheit-2007-12-26 ()
461   (ert-with-temp-buffer-include-file "sheit-2007-12-26.php"
462     ;;(ert-should (not font-lock-mode))
463     (nxhtml-mumamo-mode)
464     ;;(ert-should (not font-lock-mode))
465     (nxhtmltest-fontify-default-way 2 "sheit")
466     (nxhtmltest-should-no-mumamo-errors)
467     (ert-should
468      (and
469       (eq (get-text-property 21 'face)
470           'font-lock-comment-face)
471       (eq (get-text-property 22 'face)
472           'font-lock-comment-face)
473       (eq (get-text-property 35 'face)
474           'font-lock-comment-face)))))
475
476
477 ;; Now some tests with a big file. Jumping backwards can fail.
478
479 (defun nxhtml-ert-nxhtml-changes-jump-back-2 (pos)
480   ;;(ert-should (not font-lock-mode))
481   (nxhtml-mumamo-mode)
482   (run-hooks 'post-command-hook)
483   ;;(ert-should (not font-lock-mode))
484   (goto-char (- (point-max) (- 64036 63869)))
485   (nxhtmltest-fontify-default-way 2)
486   (nxhtmltest-should-no-mumamo-errors)
487   (ert-should
488    (eq (get-text-property (point) 'face)
489        'font-lock-variable-name-face))
490   (message "here 1")
491   (goto-char pos)
492   (nxhtmltest-fontify-default-way 2)
493   (nxhtmltest-should-no-mumamo-errors)
494   (message "here 2")
495   (ert-should
496    (eq (get-text-property (point) 'face)
497        'font-lock-function-name-face)))
498
499 ;; Fix-me: forgot to copy nxhtml-changes.html. I can't find any
500 ;; similar error now.
501 ;;
502 ;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-back-7014-2 ()
503 ;;   "this is a docstring.
504 ;; wonder how that works now ..."
505 ;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
506 ;;     (nxhtml-ert-nxhtml-changes-jump-back-2 7014)))
507
508 ;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-back-10488-2 ()
509 ;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
510 ;;     (nxhtml-ert-nxhtml-changes-jump-back-2 10488)))
511
512 ;; (ert-deftest nxhtml-ert-nxhtml-changes-jump-2 ()
513 ;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
514 ;;     ;;(ert-should (not font-lock-mode))
515 ;;     (nxhtml-mumamo-mode)
516 ;;     ;;(ert-should (not font-lock-mode))
517 ;;     (goto-char 10420)
518 ;;     (nxhtmltest-fontify-default-way 2 "jump-2")
519 ;;     (nxhtmltest-should-no-mumamo-errors)
520 ;;     (ert-should
521 ;;      (eq (get-text-property (point) 'face)
522 ;;          'font-lock-variable-name-face))))
523
524 ;;; Indentation tests
525
526 (ert-deftest nxhtml-ert-php-indent-bug-1 ()
527   "Test indentation in php only file.
528 The indentation on line 7 should be 0."
529   (ert-with-temp-buffer-include-file "only-php.php"
530     (nxhtml-mumamo-mode)
531     ;; No fontification needed for indentation.
532     (nxhtmltest-goto-line 7)
533     (indent-for-tab-command)
534     (nxhtmltest-should-no-mumamo-errors)
535     (ert-should
536      (= 0
537         (current-indentation)))))
538
539 ;;; Scroll tests
540
541 ;; (ert-deftest nxhtml-ert-scroll-jump-test ()
542 ;;   "Test if `scroll-conservatively' eq 1 works."
543 ;;   (ert-with-temp-buffer-include-file "../../nxhtml/doc/nxhtml-changes.html"
544 ;;     (ert-should (not font-lock-mode))
545 ;;     (nxhtml-mumamo-mode)
546 ;;     (ert-should (not font-lock-mode))
547 ;;     (nxhtmltest-fontify-default-way 2 "jump-2")
548 ;;     (let ((scroll-conservatively 1)
549 ;;           (ws (list (window-start)))
550 ;;           (xi (loop for ii from 1 to 100 by 1
551 ;;                     do
552 ;;                     (next-line)
553 ;;                     (sit-for 0.01)
554 ;;                     collect (list (window-start)
555 ;;                                   (let ((here (point)))
556 ;;                                     (goto-char (window-start))
557 ;;                                     (prog1 (line-end-position)
558 ;;                                       (goto-char here)))
559 ;;                                   (point))
560 ;;                     ))
561 ;;           (jumps 0)
562 ;;           prev-win-start
563 ;;           prev-win-start-le
564 ;;           )
565 ;;       (loop for xx in xi
566 ;;             do
567 ;;             (message "xx=%s" xx)
568 ;;             (let ((win-start (nth 0 xx))
569 ;;                   (win-start-le (nth 1 xx))
570 ;;                   (cur-point (nth 2 xx)))
571 ;;               (unless (or (not prev-win-start)
572 ;;                           (= prev-win-start win-start)
573 ;;                           (= (1+ prev-win-start-le) win-start))
574 ;;                 (setq jumps (1+ jumps)))
575 ;;               (setq prev-win-start win-start)
576 ;;               (setq prev-win-start-le win-start-le)
577 ;;               )
578 ;;             )
579 ;;       (ert-should (= 0 jumps))
580 ;;       )))
581
582 ;;(defvar ert-error-on-test-redefinition nil)
583
584 ;;; End of test definitions
585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
586
587 (defun nxhtmltest-run-ert (selector)
588   "Run test with ert library."
589   (unless selector (setq selector nxhtmltest-ert-default-selector))
590   (setq ert-test-files-root nxhtmltest-files-root)
591   (if noninteractive
592       (ert-run-tests-batch selector)
593     (ert-kill-temp-test-buffers)
594     (ert-run-tests-interactively selector)
595     (other-window 1)
596     (ert-list-temp-test-buffers)))
597
598 ;;;###autoload
599 (defun nxhtmltest-run-indent ()
600   "Run indentation tests."
601   (interactive)
602   (setq ert-test-files-root nxhtmltest-files-root)
603   (let ((selector "nxhtml-ert-indent-"))
604     (ert-kill-temp-test-buffers)
605     (nxhtmltest-get-fontification-method)
606     (ert-run-tests-interactively selector))
607   (other-window 1)
608   (ert-list-temp-test-buffers))
609
610 ;;;###autoload
611 (defun nxhtmltest-run ()
612   "Run all tests defined for nXhtml.
613 Currently there are only tests using ert.el defined.
614
615 Note that it is currently expected that the following tests will
616 fail (they corresponds to known errors in nXhtml/Emacs):
617
618   `nxhtml-ert-nxhtml-changes-jump-back-10549'
619   `nxhtml-ert-nxhtml-changes-jump-back-7014'
620 "
621   (interactive)
622   (setq message-log-max t)
623   (when (called-interactively-p)
624     (nxhtmltest-get-fontification-method))
625   (nxhtmltest-run-ert nil))
626
627 (when (getenv "nxhtmltest-run-Q")
628   (nxhtmltest-run))
629
630 (provide 'nxhtmltest-suites)
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
632 ;;; nxhtmltest-suites.el ends here