apropos.lsp 3.02 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Dec 12 16:17:47 2004
;;;; Contains: Tests for APROPOS

(in-package :cl-test)

(deftest apropos.1
  (loop for n from 10
sds's avatar
sds committed
10 11 12 13
        for x = (coerce (loop repeat n collect (random-from-seq +standard-chars+)) 'string)
        unless (apropos-list x)
        return (with-output-to-string (*standard-output*)
                                      (assert (null (multiple-value-list (apropos x))))))
pfdietz's avatar
pfdietz committed
14 15 16 17
  "")

(deftest apropos.2
  (let ((s (with-output-to-string
sds's avatar
sds committed
18 19
             (*standard-output*)
             (assert (null (multiple-value-list (apropos "CAR")))))))
pfdietz's avatar
pfdietz committed
20 21 22 23 24
    (notnot (search "CAR" s :test #'string-equal)))
  t)

(deftest apropos.3
  (let ((s (with-output-to-string
sds's avatar
sds committed
25 26
             (*standard-output*)
             (assert (null (multiple-value-list (apropos "CAR" (find-package "CL"))))))))
pfdietz's avatar
pfdietz committed
27 28 29 30 31 32 33 34
    (notnot (search "CAR" s :test #'string-equal)))
  t)

(deftest apropos.4
  (let ((result nil))
    (do-special-strings
     (s "CAR" t)
     (setq result (with-output-to-string
sds's avatar
sds committed
35 36
                    (*standard-output*)
                    (assert (null (multiple-value-list (apropos s))))))
pfdietz's avatar
pfdietz committed
37 38 39 40 41
     (assert (search "CAR" result :test #'string-equal))))
  t)

(deftest apropos.5
  (let ((result nil)
sds's avatar
sds committed
42
        (pkg (find-package "COMMON-LISP")))
pfdietz's avatar
pfdietz committed
43 44 45
    (do-special-strings
     (s "APROPOS" t)
     (setq result (with-output-to-string
sds's avatar
sds committed
46 47
                    (*standard-output*)
                    (assert (null (multiple-value-list (apropos s pkg))))))
pfdietz's avatar
pfdietz committed
48 49 50
     (assert (search "APROPOS" result :test #'string-equal))))
  t)

51 52
(deftest apropos.6
  (let ((s (with-output-to-string
sds's avatar
sds committed
53 54
             (*standard-output*)
             (assert (null (multiple-value-list (apropos "CAR" "CL")))))))
55 56 57 58 59
    (notnot (search "CAR" s :test #'string-equal)))
  t)

(deftest apropos.7
  (let ((s (with-output-to-string
sds's avatar
sds committed
60 61
             (*standard-output*)
             (assert (null (multiple-value-list (apropos "CAR" :|CL|)))))))
62 63 64
    (notnot (search "CAR" s :test #'string-equal)))
  t)

pfdietz's avatar
pfdietz committed
65 66
(deftest apropos.8
  (let ((s (with-output-to-string
sds's avatar
sds committed
67 68
             (*standard-output*)
             (assert (null (multiple-value-list (apropos "CAR" nil)))))))
pfdietz's avatar
pfdietz committed
69 70 71
    (notnot (search "CAR" s :test #'string-equal)))
  t)

72 73 74 75
(deftest apropos.9
  (macrolet
   ((%m (z) z))
   (let ((s (with-output-to-string
sds's avatar
sds committed
76 77 78
              (*standard-output*)
              (assert (null (multiple-value-list
                             (apropos (expand-in-current-env (%m "CAR")))))))))
79 80 81 82 83 84 85
     (notnot (search "CAR" s :test #'string-equal))))
  t)

(deftest apropos.10
  (macrolet
   ((%m (z) z))
   (let ((s (with-output-to-string
sds's avatar
sds committed
86 87 88 89
              (*standard-output*)
              (assert (null (multiple-value-list
                             (apropos "CAR"
                                      (expand-in-current-env (%m nil)))))))))
90 91 92
     (notnot (search "CAR" s :test #'string-equal))))
  t)

pfdietz's avatar
pfdietz committed
93 94 95 96 97 98 99 100 101
;;; Error tests

(deftest apropos.error.1
  (signals-error (apropos) program-error)
  t)

(deftest apropos.error.2
  (signals-error (apropos "SJLJALKSJDKLJASKLDJKLAJDLKJA" (find-package "CL") nil) program-error)
  t)