1 ;; Some tests for edebug.
3 ;;=======================
6 (testing (one two) three)
18 ;;===========================
22 (macroexpand '(` ((, (a)) . (, test))))
26 (progn (` ((, (point)) . (, (point)))))
44 (eval (edebug-` (append [(, (point)) (, (point))] nil)))
45 (eval (edebug-` (append (, (point)) (, (point)) nil)))
47 (eval (progn (edebug-` (edebug-` (, '(, (point)))))))
49 (eval (edebug-` (let (((, 'a) 'b))
54 (let ((r '(union x y)))
55 (` (` (foo (, '(, r))))))
59 (let ((a '(one two))) a))
61 (def-edebug-spec test-func (sexp &rest def-form))
63 (setq edebug-unwrap-results t)
64 (setq edebug-unwrap-results nil)
66 (defmacro test-func (func &rest args)
67 (edebug-` ((, func) (,@ args))))
69 (test-func message (concat "hi%s" "there") (+ 1 2))
71 (defmacro test-progn (&rest body)
72 (edebug-` (progn (,@ body))))
74 (def-edebug-spec test-progn (&rest def-form))
81 ;; Testing read syntax.
83 (format "testing %s %s %s" 1 2 (+ 1 2))
86 (setq mode-line-stuff'("draft(%b) ^C^S(end) ^C^Q(uit) ^C^K(ill)"))
87 ;; (re-search-forward "[.?!][])""']*$" nil t)
95 ;;====================
99 (mapconcat (function identity) x ", "))
102 (mapconcat 'identity x ", "))
105 (mapconcat (function (lambda (x) x)) x ", "))
110 (mapconcat (function* (lambda (x &optional (y (1+ x)) &key xyz) x)) x ", "))
113 (mapconcat '(lambda (x) x) x ", "))
117 (apply 'identity one two)
122 (def-edebug-spec test1
129 (def-edebug-spec test1
132 (test (test1 xyz (message "jfdjfd")))
134 ;;====================
135 ;; Anonymous function test
138 (interactive (list 2))
139 ((lambda (luttr &rest params)
140 (apply luttr luttr params))
141 (function (lambda (self n)
142 (edebug-trace "n: %s" n)
143 (if (= n 5) (edebug nil "n is 5"))
144 (edebug-tracing "cond"
147 (t (* n (funcall self self (1- n))))))))
154 (hej edebug-execution-mode)
158 (defun lambda-test ()
159 ((lambda (arg) arg) 'xyz))
164 (with left paren on start of line)"
170 (save-window-excursion
173 (setq w (next-window)))
174 (edebug-window-live-p w))
177 ;;====================
178 ;; Test edebugging top-level-forms
180 (def-edebug-spec test nil)
181 (let ((arg (list 'a 'b 'c)))
187 (fset 'emacs-setq (symbol-function 'setq))
189 (defmacro my-setq (&rest args)
191 (set (car args) (eval (car (cdr args))))
192 (setq args (cdr (cdr args)))))
194 (defmacro test-macro (&rest args)
196 (def-edebug-spec test-macro 0)
199 (test-macro (message "testing")))
203 (message "something")
205 (message "something else")))
210 ;;====================
213 (symbolp ["from" def-form ["to" def-form] ["do" &rest def-form]]))
215 ;; (symbolp ['from form ['to form] ['do &rest form]])
219 (list 'setq var (list '1+ var)))
221 (defmacro for (var from init to final do &rest body)
222 (let ((tempvar (make-symbol "max")))
223 (edebug-` (let (((, var) (, init))
224 ((, tempvar) (, final)))
225 (while (<= (, var) (, tempvar))
229 (defun test-for (one two)
230 (for i from one to two do
235 (for i from n to (* n (+ n 1)) do
240 ;;====================
241 ;; Test condition-case
242 (def-edebug-spec condition-case
245 &rest (symbolp &optional form)))
247 (setq edebug-on-signal '(error))
249 (defun test-condition-case ()
251 (signal 'error '(oh))
252 (error (message "error: %s" err))
254 (test-condition-case)
261 (defun test-lexical ()
262 (funcall (lexical-let ((xyz 123))
263 (function (lambda (arg) (+ arg xyz))))
267 ;;====================
269 (defun test-case (one)
271 ((one) (message "(one)"))
272 ("one" (message "one"))
273 ('one (message "'one"))
278 ;;====================
279 ;; Test of do from cl.el
281 (defun list-reverse (list)
282 (do ((x list (cdr x))
283 (y nil (cons (car x) y)))
285 (message "x: %s y: %s" x y)
289 (list-reverse '(testing one two three))
291 (defmacro test-backquote (arg list)
294 (message "%s %s" (, arg) (, list))
295 (mapcar (function (lambda (arg1)
296 (message "%s %s" arg1 (, arg)))) (, list)))))
298 (def-edebug-spec test-backquote (def-form def-form))
299 (test-backquote (symbol-name 'something) (list 1 2 3))
302 (defmacro dired-map-over-marks (body arg &optional show-progress)
304 (let (buffer-read-only case-fold-search found results)
306 (if (integerp (, arg))
307 (progn;; no save-excursion, want to move point.
308 (dired-repeat-over-lines
311 (if (, show-progress) (sit-for 0))
312 (setq results (cons (, body) results)))))
316 ;; non-nil, non-integer ARG means use current file:
318 (let ((regexp (dired-marker-regexp)) next-position)
320 (goto-char (point-min))
321 ;; remember position of next marked file before BODY
322 ;; can insert lines before the just found file,
323 ;; confusing us by finding the same marked file again
325 (setq next-position (and (re-search-forward regexp nil t)
327 found (not (null next-position)))
329 (goto-char next-position)
330 (if (, show-progress) (sit-for 0))
331 (setq results (cons (, body) results))
332 ;; move after last match
333 (goto-char next-position)
335 (set-marker next-position nil)
336 (setq next-position (and (re-search-forward regexp nil t)
341 ;; save-excursion loses, again
342 (dired-move-to-filename))))
345 (def-edebug-spec dired-map-over-marks (&rest def-form))
347 (dired-map-over-marks
348 (message "here") (+ 1 2) t)
350 ;;====================
351 ;; circular structure test
353 (edebug-install-custom-print)
354 (edebug-uninstall-custom-print)
358 (edebug-install-custom-print)
364 (format "%s" (setcar a a)))))
370 (let ((print-circle t)
371 (circ-list (list 'a 'b (vector 1 2 3 4) 'd 'e 'f)))
372 (setcar (nthcdr 3 circ-list) circ-list)
373 (aset (nth 2 circ-list) 2 circ-list)
374 (prin1-to-string circ-list)))
376 ;;====================
377 ;; interactive-p test
378 (defun test-interactive ()
383 (call-interactively 'test-interactive)
386 ;;====================
387 ;; test several things:
389 ;; - display scrolling.
392 (defmacro testmacro ()
395 (call-interactively 'testing1)
398 (defun testing1 (arg)
399 (interactive (list 3))
400 (message "%s" (interactive-p)) (sit-for 2)
401 (edebug-trace "interactive: %s" (testmacro))
404 ;; (custom-message "%s" arg "extra")
407 (while (< 0 (setq arg (1- arg)))
441 (edebug-trace-display "*testing*" "one")
442 (edebug-tracer "one\n")
445 (call-interactively 'testing1)
451 (defmacro testmacro ()
456 (let* ((buf (get-buffer-create "testing"))
457 (win (get-buffer-window buf)))
462 ;; (read-stream-char buf)
470 (set-buffer (get-buffer-create "*testing*"))
478 ;;====================
479 ;; anonymous function test
480 (defun testanon (arg)
481 (mapcar '(lambda (x) x) arg)
482 (mapcar (function (lambda (x) x)) arg)
483 (mapcar (function testing3 ) arg)
488 ;;====================
489 ;; upward funarg test
491 (defmacro lambda (&rest args)
492 "Return the quoted lambda expression."
493 (cons 'function (list (cons 'lambda args))))
495 (lambda (testing) one two)
498 "return an anoymous function."
499 (function (lambda (x) x))
501 ;; Emacs 19 has a lambda macro
503 "return an anoymous function."
512 (mapcar #'(lambda (x)
514 (append '(0) '(a b c d e f))))
517 ;;====================
518 ;; downward funarg test
524 (xxx (function (lambda () (message "hello")))))
529 (def-edebug-spec test nil)
530 (defun test (func list)
536 (test (function (lambda (x) (print x))) ;; set breakpoints in anon.
544 (defun alep-write-history (&rest args)
545 (message "alep-write-history( %s )\n"
548 '(write-region (format ";;Saved on %s\n" (current-time-string))
549 nil buffer-file-name nil 'shut-up)
550 ;; dump all not deleted actions
551 (flet ((write-solution (sol)
553 (write-action (action)
554 (if (a-h-action-deleted action)
555 ;; nothing to be done
558 (format "(alep-new-history-action %S %S %S)\n"
559 (a-h-action-name action)
560 (alep-tnowv-string (a-h-action-in-tnowv
562 (a-h-action-timestamp action))
563 nil buffer-file-name t 'shut-up)
564 (mapc 'write-solution
565 (a-h-action-solutions action)))))
569 (setq history-list '(1 2 3))
572 ;;=========================
574 (edebug-trace "my stuff")
577 (if (= n 0) (edebug))
589 ;;====================
590 ;; Timing test - how bad is edebug?
594 (while (< i n) (setq i (1+ i)))))
598 ;;====================
599 ;; eval-depth testing.
601 (defun test-depth (i)
604 ;; Without edebug i reaches 193, failing on eval depth
605 ;; With edebug, i reaches about 57. Better safe than sorry.
606 (setq max-lisp-eval-depth 200)
609 ;;====================
610 ;; specpdl-size testing.
611 (defun test-depth2 (i max)
612 (let ((test max-specpdl-size)
613 (max-lisp-eval-depth (+ 2 max-lisp-eval-depth))
615 (test-depth2 (1+ i) max-specpdl-size)))
617 (let ((max-lisp-eval-depth 300)
618 (max-specpdl-size 3))
619 (test-depth2 0 max-specpdl-size))
621 ;;====================
624 (defun zprint-region-1 (start end switches)
625 (let ((name (concat (buffer-name) ""))
628 (message "Spooling...")
629 (let ((oldbuf (current-buffer)))
630 (set-buffer (get-buffer-create " *spool temp*"))
633 (insert-buffer-substring oldbuf start end)
634 (setq tab-width width)
636 (untabify (point-min) (point-max)))
637 (setq start (point-min) end (point-max)))
638 (apply 'call-process-region
639 (nconc (list start end zpr-command nil nil nil
640 "-h" name switches)))
641 (message "Spooling...done")
648 (defun quick-hanoi (nrings)
649 (with-output-to-temp-buffer "*hanio*"
650 (set-buffer "*hanio*")
651 (princ (format "Solution to %s ring hanoi problem\n\n" nrings))
652 (hanoi0 nrings 'pole-1 'pole-2 'pole-3)))
654 (defun hanoi0 (n from to work)
655 ;; (edebug-set-window-configuration (edebug-current-window-configuration))
659 ;; (set-buffer "*hanio*")
660 ;; (message "Point=%s window-point=%s" (point)
661 ;; (window-point (get-buffer-window "*hanio*")))
662 ;; (set-window-point (get-buffer-window "*hanio*") (point))
665 (hanoi0 (1- n) from work to)
666 (princ (format "ring %s from %s to %s\n" n from to))
667 (hanoi0 (1- n) work to from))))
672 ;;====================
675 (defun error-generating-function ()
676 (message "try again?") (sit-for 1)
678 (signal 'bogus '("some error" xyz abc))
679 (error "debug-on-error: %s edebug-entered: %s edebug-recursion-depth: %s"
680 debug-on-error edebug-entered edebug-recursion-depth)))
682 ;; --><-- point will be left between the two arrows
683 (setq debug-on-error nil)
684 (setq edebug-on-signal '(bogus))
687 (defun testing-function ()
690 (error-generating-function)
694 (let ((debug-on-error t))
697 ;;====================
698 ;; Quitting with unwind-protect
700 (defun unwind-test ()
705 (message "unwinding1"))
706 (message "unwinding2")
712 (defmacro save-buffer-points (&rest body)
713 (` (let ((buffer-points
714 (mapcar (function (lambda (buf)
721 (mapcar (function (lambda (buf-point)
722 (if (buffer-name (car buf-point))
724 (set-buffer (car buf-point))
725 (goto-char (cdr buf-point))))))
729 (with-output-to-temp-buffer "*testing*"
741 ;;====================
742 ;; edebug-form-specs for Guido Bosch's flavors
744 (def-edebug-spec defmethod defun) ; same as defun
745 (def-edebug-spec defwhopper defun) ; same as defun
747 ;;======================
748 ;; Check syntax errors.
750 (defun test-too-many-arguments ()
751 (mapcar 'test one two))
755 (defun test-not-enough-arguments ()
758 (defun test-bad-function ()
761 (defun test-bad-function ()
765 (defun test-bad-lambda-arguments ()
766 (function (lambda "bad" )))
768 (defun test-bad-defun-arguments "bad"
769 (function (lambda "bad" )))
771 (defun test-bad-defun-arguments (arg "bad") ;; wrong error
772 (function (lambda "bad" )))
774 (defun test-bad-defun-arguments (&optional)
775 (function (lambda "bad" )))
777 (defun test-bad-let-in-lambda ()
779 (let ((something one bad)))))) ;; wrong error
781 (defun test-bad-interactive ()
782 (interactive one bad))
784 (defun test-bad-defvar ()
785 (defvar test-defvar nil [bad]))
787 (defun test-bad-let1 ()
790 (defun test-bad-let2 ()
791 (let ((something one bad))))
793 (defun test-good-let ()
796 (defun test-bad-let3 ()
799 (defun test-bad-let4 ()
802 (let ((good (list 'one))) good)
804 (defun test-bad-setq ()
810 (defun test-bad-cond ()
815 (defun test-bad-cond ()
818 (defun test-bad-condition-case1 ()
819 (condition-case "bad"))
821 (defun test-bad-condition-case2 ()
826 (defun test-bad-condition-case3 ()
830 ((error quit) (message "%s" err))))
835 (fence symbolp &optional form form))
842 (y nil (cons (car x) y))
856 ;;=========================
860 (defun test-window-buffer-change (arg)
863 (save-window-excursion
864 (set-window-buffer (selected-window) (get-buffer "*scratch*"))
865 (get-buffer-window (current-buffer))))
866 (test-window-buffer-change 'test)
869 (defun test-window-buffer-change ()
872 (test-window-buffer-change 1)
877 (def-edebug-spec edebug-forms
880 (def-edebug-spec edebug-form
881 (&or (edebug-function-symbolp edebug-forms)
882 (anonymous-function edebug-forms)
883 (edebug-macro-symbolp
887 (defun test-mapatoms () )
889 (mapatoms (function (lambda (arg)
897 ;; Test embedded &rest
898 (def-edebug-spec symbol-list
899 ([&rest "a" symbolp] form))
902 (symbol-list a b a (+ c d)))
905 (def-edebug-spec group-alternates-test
906 (&or ["foo" "bar"] "baz"))
908 (group-alternates-test foo bar)
909 (group-alternates-test baz )
911 ;;---------------------
914 (dolist (f (list 1 2))
918 (dolist (el (list 'a 'b 'c))
922 ;; (of-type (type (more type)))
924 (def-edebug-spec test-nil
929 ((lambda (arg) arg) two)
933 ;; Dot notation testing
935 (def-edebug-spec test-dot
936 (symbolp . [&or symbolp (stringp)]))
940 (def-edebug-spec test-dot
941 (&or symbolp (test-dot1)))
943 (def-edebug-spec test-dot1
944 (test-dot2 . test-dot2))
946 (def-edebug-spec test-dot2
949 (def-edebug-spec test-dot2
950 ([&or test-dot1 nil]))
952 (def-edebug-spec test-dot1
955 (&or symbolp (test-dot)))
961 (def-edebug-spec edebug-specs
964 (def-edebug-spec edebug-specs1
967 (def-edebug-spec edebug-spec
972 (def-edebug-spec test-not
973 (symbolp . [¬ symbolp form]))
976 ;;--------------------------
977 ;; Loop macro testing
980 (loop-var (((var1 (var2 var4) . (var3 var5)) . var1))
983 (loop-var (var1 var2 . var3))
984 (loop-var (var1 ["bad"] . "bad"))
986 ' (var2 var3 . var4))
988 (loop for ((a . b) (c . d))
989 of-type ((float . float) (integer. integer))
994 collect a-form into var
995 else minimize x ;; of-type some-type
1000 (loop for x from 1 to 9
1002 collect (list x y)))
1005 (loop for i from 10 downto 1 by 3
1010 (loop for item = 1 then (+ item 10)
1015 (loop for z upfrom 2
1017 (loop for n upfrom 3 below (+ z 2) ;; + was log
1022 thereis (= (+ (* x n) ;; * was expt
1027 (loop for name in '(fred sue alice joe june)
1028 as age in '(22 26 19 20 10)
1029 append (list name age) into name-and-age-list
1030 count name into name-count
1031 sum age into total-age
1033 (return (values (round* total-age name-count)
1034 name-and-age-list))))
1037 (loop for x from 0 to 3
1039 if (zerop (mod x 2))
1041 and if (zerop (floor* x 2))
1044 and do (princ " c")))
1048 (loop initially do (message x)
1049 do (dispatch-event event)))
1052 (loop initially do (popup-menu menu) ;; do is an error here.
1053 with event = (make-event)
1054 do (dispatch-event event)))
1056 (defun popup-menu-synchronously (menu)
1057 (loop initially (popup-menu menu)
1058 with event = (make-event)
1059 until (button-release-event-p (next-event event))
1060 do (dispatch-event event)
1061 finally do (deallocate-event event)))
1064 (loop with list = '(1 2 3 4)
1066 sum item into summation
1067 collect (list item)))
1071 (defun test-catch (n)
1075 (test-catch (1- n)))))
1081 (funcall 'throw 'test 'here))
1088 (defun* foo (a &optional b &key c d (e 17)))
1090 (def-edebug-spec test-vector
1095 (test-vector [one]))
1097 [testing one two three]
1098 (testing one two three)
1100 (def-edebug-spec test
1101 (&optional &or ["something" keywordp] symbolp))
1103 (test something :somekey)
1109 (defun find-faq (filename)
1114 (all-faq-a-valid-ftp
1116 (let ((minibuffer-help-form
1118 (let* ((partial (buffer-string))
1119 (soft (intern-soft partial all-faq-known-files)))
1121 (set soft (append (cdr (symbol-value soft))
1122 (list (car (symbol-value soft))))))
1123 (if (and soft (all-faq-a-valid-ftp soft))
1130 (completing-read "What faq? "
1132 (function all-faq-a-valid-ftp)
1134 all-faq-known-files)))
1136 (find-file filename))
1143 (def-edebug-spec test
1144 (&key (bad "one") (good "thing")))
1149 (def-edebug-spec test
1152 (&rest ["one" "two"]))
1156 (progn (message "one" ) )
1158 (progn (message "one" ) )
1163 (mapcar 'test (list 1 2 3))
1164 (defun test (testing) testing)
1166 ;;==================
1171 (test (:constructor construct (args)))
1185 (defadvice foo (before add2 first activate)