source: trunk/source/tests/ansi-tests/package-aux.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 4.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Mon Jun 21 20:59:17 2004
4;;;; Contains: Aux. functions for package tests
5
6(in-package :cl-test)
7
8(defmacro test-with-package-iterator (package-list-expr &rest symbol-types)
9  "Build an expression that tests the with-package-iterator form."
10  (let ((name (gensym))
11        (cht-var (gensym))
12        (pkg-list-var (gensym)))
13    `(let ((,cht-var (make-hash-table))
14           (,pkg-list-var ,package-list-expr)
15           (fail-count 0))
16         (with-package-iterator (,name ,pkg-list-var
17                                       ,@(copy-list symbol-types))
18           ;; For each symbol, check that name is returning appropriate
19           ;; things
20           (loop
21             (block fail
22               (multiple-value-bind (more sym access pkg)
23                   (,name)
24                 (unless more (return nil))
25                 (setf (gethash sym ,cht-var) t)  ;; note presence of symbol
26                 ;; Check that its access status is in the list,
27                 ;;  that pkg is a package,
28                 ;;  that the symbol is in the package,
29                 ;;  and that (in the package) it has the correct access type
30                 (unless (member access (quote ,(copy-list symbol-types)))
31                   (unless (> fail-count +fail-count-limit+)
32                     (format t "Bad access type: ~S ==> ~A~%" sym access))
33                   (when (= fail-count +fail-count-limit+)
34                     (format t "Further messages suppressed~%"))
35                   (incf fail-count)
36                   (return-from fail nil))
37                 
38                 (unless (packagep pkg)
39                   (unless (> fail-count +fail-count-limit+)
40                     (format t "Not a package: ~S ==> ~S~%" sym pkg))
41                   (when (= fail-count +fail-count-limit+)
42                     (format t "Further messages suppressed~%"))
43                   (incf fail-count)
44                   (return-from fail nil))
45                 (multiple-value-bind (sym2 access2)
46                     (find-symbol (symbol-name sym) pkg)
47                   (unless (or (eqt sym sym2)
48                               (member sym2 (package-shadowing-symbols pkg)))
49                     (unless (> fail-count +fail-count-limit+)
50                       (format t "Not same symbol: ~S ~S~%" sym sym2))
51                     (when (= fail-count +fail-count-limit+)
52                       (format t "Further messages suppressed~%"))
53                     (incf fail-count)
54                     (return-from fail nil))
55                   (unless  (eqt access access2)
56                     (unless (> fail-count +fail-count-limit+)
57                       (format t "Not same access type: ~S ~S ~S~%"
58                               sym access access2))
59                     (when (= fail-count +fail-count-limit+)
60                       (format t "Further messages suppressed~%"))
61                     (incf fail-count)
62                     (return-from fail nil)))))))
63         ;; now, check that each symbol in each package has
64         ;; been properly found
65         (loop
66             for p in ,pkg-list-var do
67               (block fail
68                 (do-symbols (sym p)
69                   (multiple-value-bind (sym2 access)
70                       (find-symbol (symbol-name sym) p)
71                     (unless (eqt sym sym2)
72                       (unless (> fail-count +fail-count-limit+)
73                         (format t "Not same symbol (2): ~S ~S~%"
74                                 sym sym2))
75                       (when (= fail-count +fail-count-limit+)
76                         (format t "Further messages suppressed~%"))
77                       (incf fail-count)
78                       (return-from fail nil))
79                     (unless (or (not (member access
80                                              (quote ,(copy-list symbol-types))))
81                                 (gethash sym ,cht-var))
82                       (format t "Symbol not found: ~S~%" sym)
83                       (incf fail-count)
84                       (return-from fail nil))))))
85         (or (zerop fail-count) fail-count))))
86
87(defun with-package-iterator-internal (packages)
88  (test-with-package-iterator packages :internal))
89
90(defun with-package-iterator-external (packages)
91  (test-with-package-iterator packages :external))
92
93(defun with-package-iterator-inherited (packages)
94  (test-with-package-iterator packages :inherited))
95
96(defun with-package-iterator-all (packages)
97  (test-with-package-iterator packages :internal :external :inherited))
98
99(defun num-external-symbols-in-package (p)
100  (let ((num 0))
101    (declare (fixnum num))
102    (do-external-symbols (s p num)
103      (declare (ignorable s))                   
104      (incf num))))
105
106(defun external-symbols-in-package (p)
107  (let ((symbols nil))
108    (do-external-symbols (s p)
109      (push s symbols))
110    (sort symbols #'(lambda (s1 s2) (string< (symbol-name s1)
111                                             (symbol-name s2))))))
112
113(defun num-symbols-in-package (p)
114  (let ((num 0))
115    (declare (fixnum num))
116    (do-symbols (s p num)
117      (declare (ignorable s))                   
118      (incf num))))
119
120(defun sort-symbols (sl)
121  (sort (copy-list sl)
122        #'(lambda (x y)
123            (or
124             (string< (symbol-name x)
125                      (symbol-name y))
126             (and (string= (symbol-name x)
127                           (symbol-name y))
128                  (string< (package-name (symbol-package x))
129                           (package-name (symbol-package y))))))))
130
131(defun sort-package-list (x)
132  (sort (copy-list x)
133        #'string<
134        :key #'package-name))
Note: See TracBrowser for help on using the repository browser.