(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / emacs-lisp / tcover-unsafep.el
blob4359209b4d4c05ff089ad32124c27df73683eb25
1 ;;;; testcover-unsafep.el -- Use testcover to test unsafep's code coverage
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
5 ;; Author: Jonathan Yavner <jyavner@engineer.com>
6 ;; Maintainer: Jonathan Yavner <jyavner@engineer.com>
7 ;; Keywords: safety lisp utility
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
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.
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
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 (require 'testcover)
28 ;;;These forms are all considered safe
29 (defconst testcover-unsafep-safe
30 '(((lambda (x) (* x 2)) 14)
31 (apply 'cdr (mapcar '(lambda (x) (car x)) y))
32 (cond ((= x 4) 5) (t 27))
33 (condition-case x (car y) (error (car x)))
34 (dolist (x y) (message "here: %s" x))
35 (dotimes (x 14 (* x 2)) (message "here: %d" x))
36 (let (x) (dolist (y '(1 2 3) (1+ y)) (push y x)))
37 (let (x) (apply '(lambda (x) (* x 2)) 14))
38 (let ((x '(2))) (push 1 x) (pop x) (add-to-list 'x 2))
39 (let ((x 1) (y 2)) (setq x (+ x y)))
40 (let ((x 1)) (let ((y (+ x 3))) (* x y)))
41 (let* nil (current-time))
42 (let* ((x 1) (y (+ x 3))) (* x y))
43 (mapcar (lambda (x &optional y &rest z) (setq y (+ x 2)) (* y 3)) '(1 2 3))
44 (mapconcat #'(lambda (var) (propertize var 'face 'bold)) '("1" "2") ", ")
45 (setq buffer-display-count 14 mark-active t)
46 ;;This is not safe if you insert it into a buffer!
47 (propertize "x" 'display '(height (progn (delete-file "x") 1))))
48 "List of forms that `unsafep' should decide are safe.")
50 ;;;These forms are considered unsafe
51 (defconst testcover-unsafep-unsafe
52 '(( (add-to-list x y)
53 . (unquoted x))
54 ( (add-to-list y x)
55 . (unquoted y))
56 ( (add-to-list 'y x)
57 . (global-variable y))
58 ( (not (delete-file "unsafep.el"))
59 . (function delete-file))
60 ( (cond (t (aset local-abbrev-table 0 0)))
61 . (function aset))
62 ( (cond (t (setq unsafep-vars "")))
63 . (risky-local-variable unsafep-vars))
64 ( (condition-case format-alist 1)
65 . (risky-local-variable format-alist))
66 ( (condition-case x 1 (error (setq format-alist "")))
67 . (risky-local-variable format-alist))
68 ( (dolist (x (sort globalvar 'car)) (princ x))
69 . (function sort))
70 ( (dotimes (x 14) (delete-file "x"))
71 . (function delete-file))
72 ( (let ((post-command-hook "/tmp/")) 1)
73 . (risky-local-variable post-command-hook))
74 ( (let ((x (delete-file "x"))) 2)
75 . (function delete-file))
76 ( (let (x) (add-to-list 'x (delete-file "x")))
77 . (function delete-file))
78 ( (let (x) (condition-case y (setq x 1 z 2)))
79 . (global-variable z))
80 ( (let (x) (condition-case z 1 (error (delete-file "x"))))
81 . (function delete-file))
82 ( (let (x) (mapc (lambda (x) (setcar x 1)) '((1 . 2) (3 . 4))))
83 . (function setcar))
84 ( (let (y) (push (delete-file "x") y))
85 . (function delete-file))
86 ( (let* ((x 1)) (setq y 14))
87 . (global-variable y))
88 ( (mapc 'car (list '(1 . 2) (cons 3 4) (kill-buffer "unsafep.el")))
89 . (function kill-buffer))
90 ( (mapcar x y)
91 . (unquoted x))
92 ( (mapcar '(lambda (x) (rename-file x "x")) '("unsafep.el"))
93 . (function rename-file))
94 ( (mapconcat x1 x2 " ")
95 . (unquoted x1))
96 ( (pop format-alist)
97 . (risky-local-variable format-alist))
98 ( (push 1 format-alist)
99 . (risky-local-variable format-alist))
100 ( (setq buffer-display-count (delete-file "x"))
101 . (function delete-file))
102 ;;These are actualy safe (they signal errors)
103 ( (apply '(x) '(1 2 3))
104 . (function (x)))
105 ( (let (((x))) 1)
106 . (variable (x)))
107 ( (let (1) 2)
108 . (variable 1))
110 "A-list of (FORM . REASON)... that`unsafep' should decide are unsafe.")
113 ;;;#########################################################################
114 (defun testcover-unsafep ()
115 "Executes all unsafep tests and displays the coverage results."
116 (interactive)
117 (testcover-unmark-all "unsafep.el")
118 (testcover-start "unsafep.el")
119 (let (save-functions)
120 (dolist (x testcover-unsafep-safe)
121 (if (unsafep x)
122 (error "%S should be safe" x)))
123 (dolist (x testcover-unsafep-unsafe)
124 (if (not (equal (unsafep (car x)) (cdr x)))
125 (error "%S should be unsafe: %s" (car x) (cdr x))))
126 (setq safe-functions t)
127 (if (or (unsafep '(delete-file "x"))
128 (unsafep-function 'delete-file))
129 (error "safe-functions=t should allow delete-file"))
130 (setq safe-functions '(setcar))
131 (if (unsafep '(setcar x 1))
132 (error "safe-functions=(setcar) should allow setcar"))
133 (if (not (unsafep '(setcdr x 1)))
134 (error "safe-functions=(setcar) should not allow setcdr")))
135 (testcover-mark-all "unsafep.el")
136 (testcover-end "unsafep.el")
137 (message "Done"))
139 ;;; arch-tag: a7616c27-1998-47ae-9304-76d1439dbf29
140 ;; testcover-unsafep.el ends here.