Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / emacs-lisp / tcover-unsafep.el
CommitLineData
7ed9159a
JY
1;;;; testcover-unsafep.el -- Use testcover to test unsafep's code coverage
2
8b72699e 3;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
7ed9159a
JY
4
5;; Author: Jonathan Yavner <jyavner@engineer.com>
6;; Maintainer: Jonathan Yavner <jyavner@engineer.com>
7;; Keywords: safety lisp utility
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e0085d62 13;; the Free Software Foundation; either version 3, or (at your option)
7ed9159a
JY
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
7ed9159a
JY
25
26(require 'testcover)
27
dfc9a078
JB
28(defvar safe-functions)
29
7ed9159a
JY
30;;;These forms are all considered safe
31(defconst testcover-unsafep-safe
32 '(((lambda (x) (* x 2)) 14)
33 (apply 'cdr (mapcar '(lambda (x) (car x)) y))
34 (cond ((= x 4) 5) (t 27))
35 (condition-case x (car y) (error (car x)))
36 (dolist (x y) (message "here: %s" x))
37 (dotimes (x 14 (* x 2)) (message "here: %d" x))
38 (let (x) (dolist (y '(1 2 3) (1+ y)) (push y x)))
39 (let (x) (apply '(lambda (x) (* x 2)) 14))
40 (let ((x '(2))) (push 1 x) (pop x) (add-to-list 'x 2))
41 (let ((x 1) (y 2)) (setq x (+ x y)))
42 (let ((x 1)) (let ((y (+ x 3))) (* x y)))
43 (let* nil (current-time))
44 (let* ((x 1) (y (+ x 3))) (* x y))
45 (mapcar (lambda (x &optional y &rest z) (setq y (+ x 2)) (* y 3)) '(1 2 3))
46 (mapconcat #'(lambda (var) (propertize var 'face 'bold)) '("1" "2") ", ")
47 (setq buffer-display-count 14 mark-active t)
48 ;;This is not safe if you insert it into a buffer!
49 (propertize "x" 'display '(height (progn (delete-file "x") 1))))
50 "List of forms that `unsafep' should decide are safe.")
51
52;;;These forms are considered unsafe
53(defconst testcover-unsafep-unsafe
54 '(( (add-to-list x y)
55 . (unquoted x))
56 ( (add-to-list y x)
57 . (unquoted y))
58 ( (add-to-list 'y x)
59 . (global-variable y))
60 ( (not (delete-file "unsafep.el"))
61 . (function delete-file))
62 ( (cond (t (aset local-abbrev-table 0 0)))
63 . (function aset))
64 ( (cond (t (setq unsafep-vars "")))
65 . (risky-local-variable unsafep-vars))
66 ( (condition-case format-alist 1)
67 . (risky-local-variable format-alist))
68 ( (condition-case x 1 (error (setq format-alist "")))
69 . (risky-local-variable format-alist))
70 ( (dolist (x (sort globalvar 'car)) (princ x))
71 . (function sort))
72 ( (dotimes (x 14) (delete-file "x"))
73 . (function delete-file))
74 ( (let ((post-command-hook "/tmp/")) 1)
75 . (risky-local-variable post-command-hook))
76 ( (let ((x (delete-file "x"))) 2)
77 . (function delete-file))
78 ( (let (x) (add-to-list 'x (delete-file "x")))
79 . (function delete-file))
80 ( (let (x) (condition-case y (setq x 1 z 2)))
81 . (global-variable z))
82 ( (let (x) (condition-case z 1 (error (delete-file "x"))))
83 . (function delete-file))
84 ( (let (x) (mapc (lambda (x) (setcar x 1)) '((1 . 2) (3 . 4))))
85 . (function setcar))
86 ( (let (y) (push (delete-file "x") y))
87 . (function delete-file))
88 ( (let* ((x 1)) (setq y 14))
89 . (global-variable y))
90 ( (mapc 'car (list '(1 . 2) (cons 3 4) (kill-buffer "unsafep.el")))
91 . (function kill-buffer))
92 ( (mapcar x y)
93 . (unquoted x))
94 ( (mapcar '(lambda (x) (rename-file x "x")) '("unsafep.el"))
95 . (function rename-file))
96 ( (mapconcat x1 x2 " ")
97 . (unquoted x1))
98 ( (pop format-alist)
99 . (risky-local-variable format-alist))
100 ( (push 1 format-alist)
101 . (risky-local-variable format-alist))
102 ( (setq buffer-display-count (delete-file "x"))
103 . (function delete-file))
104 ;;These are actualy safe (they signal errors)
105 ( (apply '(x) '(1 2 3))
106 . (function (x)))
107 ( (let (((x))) 1)
108 . (variable (x)))
109 ( (let (1) 2)
110 . (variable 1))
111 )
112 "A-list of (FORM . REASON)... that`unsafep' should decide are unsafe.")
113
6d00e226 114(declare-function unsafep-function "unsafep" (fun))
7ed9159a
JY
115
116;;;#########################################################################
117(defun testcover-unsafep ()
118 "Executes all unsafep tests and displays the coverage results."
119 (interactive)
120 (testcover-unmark-all "unsafep.el")
121 (testcover-start "unsafep.el")
122 (let (save-functions)
123 (dolist (x testcover-unsafep-safe)
124 (if (unsafep x)
125 (error "%S should be safe" x)))
126 (dolist (x testcover-unsafep-unsafe)
127 (if (not (equal (unsafep (car x)) (cdr x)))
128 (error "%S should be unsafe: %s" (car x) (cdr x))))
129 (setq safe-functions t)
130 (if (or (unsafep '(delete-file "x"))
131 (unsafep-function 'delete-file))
132 (error "safe-functions=t should allow delete-file"))
133 (setq safe-functions '(setcar))
134 (if (unsafep '(setcar x 1))
135 (error "safe-functions=(setcar) should allow setcar"))
136 (if (not (unsafep '(setcdr x 1)))
137 (error "safe-functions=(setcar) should not allow setcdr")))
138 (testcover-mark-all "unsafep.el")
139 (testcover-end "unsafep.el")
140 (message "Done"))
141
cbee283d 142;; arch-tag: a7616c27-1998-47ae-9304-76d1439dbf29
7ed9159a 143;; testcover-unsafep.el ends here.