annotate tests/automated/byte-compiler-tests.el @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
1 ;; Copyright (C) 1998 Free Software Foundation, Inc.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
2
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
3 ;; Author: Martin Buchholz <martin@xemacs.org>
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
4 ;; Maintainer: Martin Buchholz <martin@xemacs.org>
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
5 ;; Created: 1998
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
6 ;; Keywords: tests
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
7
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
9
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
13 ;; any later version.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
14
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
18 ;; General Public License for more details.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
19
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
24
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
25 ;;; Synched up with: Not in FSF.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
26
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
27 ;;; Commentary:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
28
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
29 ;;; Test byte-compiler functionality
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
30 ;;; See test-harness.el
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
31
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
32 (condition-case err
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
33 (require 'test-harness)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
34 (file-error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
35 (when (and (boundp 'load-file-name) (stringp load-file-name))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
36 (push (file-name-directory load-file-name) load-path)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
37 (require 'test-harness))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
38
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
39 (require 'bytecomp)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
40
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
41 ;; test constant symbol warnings
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
42 (defmacro check-byte-compiler-message (message-regexp &rest body)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
43 `(Check-Message ,message-regexp (byte-compile '(lambda () ,@body))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
44
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
45 (check-byte-compiler-message "Attempt to set non-symbol" (setq 1 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
46 (check-byte-compiler-message "Attempt to set constant symbol" (setq t 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
47 (check-byte-compiler-message "Attempt to set constant symbol" (setq nil 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
48 (check-byte-compiler-message "^$" (defconst :foo 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
49
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
50 (check-byte-compiler-message "Attempt to let-bind non-symbol" (let ((1 'x)) 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
51 (check-byte-compiler-message "Attempt to let-bind constant symbol" (let ((t 'x)) (foo)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
52 (check-byte-compiler-message "Attempt to let-bind constant symbol" (let ((nil 'x)) (foo)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
53 (check-byte-compiler-message "Attempt to let-bind constant symbol" (let ((:foo 'x)) (foo)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
54
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
55
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
56 (check-byte-compiler-message "bound but not referenced" (let ((foo 'x)) 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
57 (Assert (not (boundp 'free-variable)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
58 (Assert (boundp 'byte-compile-warnings))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
59 (check-byte-compiler-message "assignment to free variable" (setq free-variable 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
60 (check-byte-compiler-message "reference to free variable" (car free-variable))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
61 (check-byte-compiler-message "called with 2 args, but requires 1" (car 'x 'y))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
62
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
63 (check-byte-compiler-message "^$" (setq :foo 1))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
64 (let ((fun '(lambda () (setq :foo 1))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
65 (fset 'test-byte-compiler-fun fun))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
66 (Check-Error setting-constant (test-byte-compiler-fun))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
67 (byte-compile 'test-byte-compiler-fun)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
68 (Check-Error setting-constant (test-byte-compiler-fun))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
69
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
70 (eval-when-compile (defvar setq-test-foo nil) (defvar setq-test-bar nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
71 (progn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
72 (check-byte-compiler-message "set called with 1 arg, but requires 2" (setq setq-test-foo))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
73 (check-byte-compiler-message "set called with 1 arg, but requires 2" (setq setq-test-foo 1 setq-test-bar))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
74 (check-byte-compiler-message "set-default called with 1 arg, but requires 2" (setq-default setq-test-foo))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
75 (check-byte-compiler-message "set-default called with 1 arg, but requires 2" (setq-default setq-test-foo 1 setq-test-bar))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
76 )
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
77
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
78 ;;-----------------------------------------------------
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
79 ;; let, let*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
80 ;;-----------------------------------------------------
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
81
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
82 ;; Test interpreted and compiled lisp separately here
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
83 (check-byte-compiler-message "malformed let binding" (let ((x 1 2)) 3))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
84 (check-byte-compiler-message "malformed let binding" (let* ((x 1 2)) 3))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
85
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
86 (Check-Error-Message
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
87 error "`let' bindings can have only one value-form"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
88 (eval '(let ((x 1 2)) 3)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
89
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
90 (Check-Error-Message
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
91 error "`let' bindings can have only one value-form"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
92 (eval '(let* ((x 1 2)) 3)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents:
diff changeset
93
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
94 (defmacro before-and-after-compile-equal (&rest form)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
95 `(Assert (equal (funcall (quote (lambda () ,@form)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
96 (funcall (byte-compile (quote (lambda () ,@form)))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
97
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
98 (defvar simplyamarker (point-min-marker))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
99
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
100 ;; The byte optimizer must be careful with +/- with a single argument.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
101
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
102 (before-and-after-compile-equal (+))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
103 (before-and-after-compile-equal (+ 2 2))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
104 (before-and-after-compile-equal (+ 2 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
105 (before-and-after-compile-equal (+ 1 2))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
106 ;; (+ 1) is OK. but (+1) signals an error.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
107 (before-and-after-compile-equal (+ 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
108 (before-and-after-compile-equal (+ 3))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
109 (before-and-after-compile-equal (+ simplyamarker 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
110 ;; The optimization (+ m) --> m is invalid when m is a marker.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
111 ;; Currently the following test fails - controversial.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
112 ;; (before-and-after-compile-equal (+ simplyamarker))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
113 ;; Same tests for minus.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
114 (before-and-after-compile-equal (- 2 2))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
115 (before-and-after-compile-equal (- 2 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
116 (before-and-after-compile-equal (- 1 2))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
117 (before-and-after-compile-equal (- 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
118 (before-and-after-compile-equal (- 3))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
119 (before-and-after-compile-equal (- simplyamarker 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
120 (before-and-after-compile-equal (- simplyamarker))