[USE_MAC_IMAGE_IO] (image_load_image_io):
[emacs.git] / lisp / emacs-lisp / tcover-unsafep.el
blobeb4a3d67c726bd1991e9b5b92fbd6fbb9471a7b2
1 ;;;; testcover-unsafep.el -- Use testcover to test unsafep's code coverage
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 (require 'testcover)
28 (defvar safe-functions)
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.")
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))
112 "A-list of (FORM . REASON)... that`unsafep' should decide are unsafe.")
115 ;;;#########################################################################
116 (defun testcover-unsafep ()
117 "Executes all unsafep tests and displays the coverage results."
118 (interactive)
119 (testcover-unmark-all "unsafep.el")
120 (testcover-start "unsafep.el")
121 (let (save-functions)
122 (dolist (x testcover-unsafep-safe)
123 (if (unsafep x)
124 (error "%S should be safe" x)))
125 (dolist (x testcover-unsafep-unsafe)
126 (if (not (equal (unsafep (car x)) (cdr x)))
127 (error "%S should be unsafe: %s" (car x) (cdr x))))
128 (setq safe-functions t)
129 (if (or (unsafep '(delete-file "x"))
130 (unsafep-function 'delete-file))
131 (error "safe-functions=t should allow delete-file"))
132 (setq safe-functions '(setcar))
133 (if (unsafep '(setcar x 1))
134 (error "safe-functions=(setcar) should allow setcar"))
135 (if (not (unsafep '(setcdr x 1)))
136 (error "safe-functions=(setcar) should not allow setcdr")))
137 (testcover-mark-all "unsafep.el")
138 (testcover-end "unsafep.el")
139 (message "Done"))
141 ;;; arch-tag: a7616c27-1998-47ae-9304-76d1439dbf29
142 ;; testcover-unsafep.el ends here.