Mercurial > emacs
annotate lisp/eshell/esh-test.el @ 93866:1f769203aa6c
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 08 Apr 2008 14:57:02 +0000 |
parents | 107ccd98fa12 |
children | 606f2d163a64 1e3a407766b9 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33020
diff
changeset
|
1 ;;; esh-test.el --- Eshell test suite |
29876 | 2 |
74509 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
79707 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
78220
a1e8300d3c55
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
29876 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
29876 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; The purpose of this module is to verify that Eshell works as | |
28 ;; expected. To run it on your system, use the command | |
29 ;; \\[eshell-test]. | |
30 | |
31 ;;; Code: | |
32 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
33 (eval-when-compile |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
34 (require 'eshell) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
35 (require 'esh-util)) |
29876 | 36 (require 'esh-mode) |
37 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
38 (defgroup eshell-test nil |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
39 "This module is meant to ensure that Eshell is working correctly." |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
40 :tag "Eshell test suite" |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
41 :group 'eshell) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
42 |
29876 | 43 ;;; User Variables: |
44 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
45 (defface eshell-test-ok |
29876 | 46 '((((class color) (background light)) (:foreground "Green" :bold t)) |
47 (((class color) (background dark)) (:foreground "Green" :bold t))) | |
48 "*The face used to highlight OK result strings." | |
49 :group 'eshell-test) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
50 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
51 (put 'eshell-test-ok-face 'face-alias 'eshell-test-ok) |
29876 | 52 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
53 (defface eshell-test-failed |
29876 | 54 '((((class color) (background light)) (:foreground "OrangeRed" :bold t)) |
55 (((class color) (background dark)) (:foreground "OrangeRed" :bold t)) | |
56 (t (:bold t))) | |
57 "*The face used to highlight FAILED result strings." | |
58 :group 'eshell-test) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
59 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
60 (put 'eshell-test-failed-face 'face-alias 'eshell-test-failed) |
29876 | 61 |
62 (defcustom eshell-show-usage-metrics nil | |
63 "*If non-nil, display different usage metrics for each Eshell command." | |
64 :set (lambda (symbol value) | |
65 (if value | |
66 (add-hook 'eshell-mode-hook 'eshell-show-usage-metrics) | |
67 (remove-hook 'eshell-mode-hook 'eshell-show-usage-metrics)) | |
68 (set symbol value)) | |
69 :type '(choice (const :tag "No metrics" nil) | |
70 (const :tag "Cons cells consumed" t) | |
71 (const :tag "Time elapsed" 0)) | |
72 :group 'eshell-test) | |
73 | |
74 ;;; Code: | |
75 | |
76 (eval-when-compile | |
77 (defvar test-buffer)) | |
78 | |
79 (defun eshell-insert-command (text &optional func) | |
80 "Insert a command at the end of the buffer." | |
81 (goto-char eshell-last-output-end) | |
82 (insert-and-inherit text) | |
83 (funcall (or func 'eshell-send-input))) | |
84 | |
85 (defun eshell-match-result (regexp) | |
86 "Insert a command at the end of the buffer." | |
87 (goto-char eshell-last-input-end) | |
88 (looking-at regexp)) | |
89 | |
90 (defun eshell-command-result-p (text regexp &optional func) | |
91 "Insert a command at the end of the buffer." | |
92 (eshell-insert-command text func) | |
93 (eshell-match-result regexp)) | |
94 | |
95 (defvar eshell-test-failures nil) | |
96 | |
97 (defun eshell-run-test (module funcsym label command) | |
98 "Test whether FORM evaluates to a non-nil value." | |
99 (when (let ((sym (intern-soft (concat "eshell-" (symbol-name module))))) | |
100 (or (memq sym (eshell-subgroups 'eshell)) | |
101 (eshell-using-module sym))) | |
102 (with-current-buffer test-buffer | |
103 (insert-before-markers | |
104 (format "%-70s " (substring label 0 (min 70 (length label))))) | |
105 (insert-before-markers " ....") | |
106 (eshell-redisplay)) | |
107 (let ((truth (eval command))) | |
108 (with-current-buffer test-buffer | |
109 (delete-backward-char 6) | |
110 (insert-before-markers | |
111 "[" (let (str) | |
112 (if truth | |
113 (progn | |
114 (setq str " OK ") | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
115 (put-text-property 0 6 'face 'eshell-test-ok str)) |
29876 | 116 (setq str "FAILED") |
117 (setq eshell-test-failures (1+ eshell-test-failures)) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
118 (put-text-property 0 6 'face 'eshell-test-failed str)) |
29876 | 119 str) "]") |
120 (add-text-properties (line-beginning-position) (point) | |
121 (list 'test-func funcsym)) | |
122 (eshell-redisplay))))) | |
123 | |
124 (defun eshell-test-goto-func () | |
125 "Jump to the function that defines a particular test." | |
126 (interactive) | |
127 (let ((fsym (get-text-property (point) 'test-func))) | |
128 (when fsym | |
129 (let* ((def (symbol-function fsym)) | |
59120
b79ba69139eb
(eshell-test-goto-func): Call symbol-file with `defun'.
Richard M. Stallman <rms@gnu.org>
parents:
55581
diff
changeset
|
130 (library (locate-library (symbol-file fsym 'defun))) |
29876 | 131 (name (substring (symbol-name fsym) |
132 (length "eshell-test--"))) | |
133 (inhibit-redisplay t)) | |
134 (find-file library) | |
135 (goto-char (point-min)) | |
136 (re-search-forward (concat "^(eshell-deftest\\s-+\\w+\\s-+" | |
137 name)) | |
138 (beginning-of-line))))) | |
139 | |
140 (defun eshell-run-one-test (&optional arg) | |
141 "Jump to the function that defines a particular test." | |
142 (interactive "P") | |
143 (let ((fsym (get-text-property (point) 'test-func))) | |
144 (when fsym | |
145 (beginning-of-line) | |
146 (delete-region (point) (line-end-position)) | |
147 (let ((test-buffer (current-buffer))) | |
148 (set-buffer (let ((inhibit-redisplay t)) | |
149 (save-window-excursion (eshell t)))) | |
150 (funcall fsym) | |
151 (unless arg | |
152 (kill-buffer (current-buffer))))))) | |
153 | |
154 ;;;###autoload | |
155 (defun eshell-test (&optional arg) | |
156 "Test Eshell to verify that it works as expected." | |
157 (interactive "P") | |
158 (let* ((begin (eshell-time-to-seconds (current-time))) | |
159 (test-buffer (get-buffer-create "*eshell test*"))) | |
160 (set-buffer (let ((inhibit-redisplay t)) | |
161 (save-window-excursion (eshell t)))) | |
162 (with-current-buffer test-buffer | |
163 (erase-buffer) | |
164 (setq major-mode 'eshell-test-mode) | |
165 (setq mode-name "EShell Test") | |
166 (set (make-local-variable 'eshell-test-failures) 0) | |
167 (local-set-key [(control ?c) (control ?c)] 'eshell-test-goto-func) | |
168 (local-set-key [(control ?c) (control ?r)] 'eshell-run-one-test) | |
169 (local-set-key [(control ?m)] 'eshell-test-goto-func) | |
170 (local-set-key [return] 'eshell-test-goto-func) | |
171 | |
55581
a9bcae5bca8e
2004-05-13 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
172 (insert "Testing Eshell under " (emacs-version)) |
29876 | 173 (switch-to-buffer test-buffer) |
174 (delete-other-windows)) | |
33020 | 175 (eshell-for funcname (sort (all-completions "eshell-test--" |
176 obarray 'functionp) | |
177 'string-lessp) | |
29876 | 178 (with-current-buffer test-buffer |
179 (insert "\n")) | |
180 (funcall (intern-soft funcname))) | |
181 (with-current-buffer test-buffer | |
182 (insert (format "\n\n--- %s --- (completed in %d seconds)\n" | |
183 (current-time-string) | |
184 (- (eshell-time-to-seconds (current-time)) | |
185 begin))) | |
186 (message "Eshell test suite completed: %s failure%s" | |
187 (if (> eshell-test-failures 0) | |
188 (number-to-string eshell-test-failures) | |
189 "No") | |
190 (if (= eshell-test-failures 1) "" "s")))) | |
191 (goto-char eshell-last-output-end) | |
192 (unless arg | |
193 (kill-buffer (current-buffer)))) | |
194 | |
195 | |
196 (defvar eshell-metric-before-command 0) | |
197 (defvar eshell-metric-after-command 0) | |
198 | |
199 (defun eshell-show-usage-metrics () | |
200 "If run at Eshell mode startup, metrics are shown after each command." | |
201 (set (make-local-variable 'eshell-metric-before-command) | |
202 (if (eq eshell-show-usage-metrics t) | |
203 0 | |
204 (current-time))) | |
205 (set (make-local-variable 'eshell-metric-after-command) | |
206 (if (eq eshell-show-usage-metrics t) | |
207 0 | |
208 (current-time))) | |
209 | |
210 (add-hook 'eshell-pre-command-hook | |
211 (function | |
212 (lambda () | |
213 (setq eshell-metric-before-command | |
214 (if (eq eshell-show-usage-metrics t) | |
215 (car (memory-use-counts)) | |
216 (current-time))))) nil t) | |
217 | |
218 (add-hook 'eshell-post-command-hook | |
219 (function | |
220 (lambda () | |
221 (setq eshell-metric-after-command | |
222 (if (eq eshell-show-usage-metrics t) | |
223 (car (memory-use-counts)) | |
224 (current-time))) | |
225 (eshell-interactive-print | |
226 (concat | |
227 (int-to-string | |
228 (if (eq eshell-show-usage-metrics t) | |
229 (- eshell-metric-after-command | |
230 eshell-metric-before-command 7) | |
231 (- (eshell-time-to-seconds | |
232 eshell-metric-after-command) | |
233 (eshell-time-to-seconds | |
234 eshell-metric-before-command)))) | |
235 "\n")))) | |
236 nil t)) | |
237 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
238 (provide 'esh-test) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
239 |
52401 | 240 ;;; arch-tag: 6e32275a-8285-4a4e-b7cf-819aa7c86b8e |
29876 | 241 ;;; esh-test.el ends here |