home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part02 / co-test.l < prev    next >
Encoding:
Text File  |  1987-07-30  |  5.9 KB  |  215 lines

  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         co-test.l
  5. ; RCS:          $Revision: 1.1 $
  6. ; SCCS:         %A% %G% %U%
  7. ; Description:  Portable Test Macro for Testing COOL
  8. ; Author:       James Kempf, HP/DCC
  9. ; Created:      24-Feb-87
  10. ; Modified:     25-Feb-87 08:45:43 (James Kempf)
  11. ; Language:     Lisp
  12. ; Package:      PCL
  13. ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;
  16. ; Copyright (c) 1987 Hewlett-Packard Corporation. All rights reserved.
  17. ;
  18. ; Use and copying of this software and preparation of derivative works based
  19. ; upon this software are permitted.  Any distribution of this software or
  20. ; derivative works must comply with all applicable United States export
  21. ; control laws.
  22. ; This software is made available AS IS, and Hewlett-Packard Corporation makes
  23. ; no warranty about the software, its performance or its conformity to any
  24. ; specification.
  25. ;
  26. ; Suggestions, comments and requests for improvement may be mailed to
  27. ; aiws@hplabs.HP.COM
  28.  
  29. ;;;-*- Mode:LISP; Package: PCL; Base:10; Syntax:Common-lisp -*-
  30. ;;;
  31. ;;; *************************************************************************
  32. ;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  33. ;;;
  34. ;;; Use and copying of this software and preparation of derivative works
  35. ;;; based upon this software are permitted.  Any distribution of this
  36. ;;; software or derivative works must comply with all applicable United
  37. ;;; States export control laws.
  38. ;;; 
  39. ;;; This software is made available AS IS, and Xerox Corporation makes no
  40. ;;; warranty about the software, its performance or its conformity to any
  41. ;;; specification.
  42. ;;; 
  43. ;;; Any person obtaining a copy of this software is requested to send their
  44. ;;; name and post office or electronic mail address to:
  45. ;;;   CommonLoops Coordinator
  46. ;;;   Xerox Artifical Intelligence Systems
  47. ;;;   2400 Hanover St.
  48. ;;;   Palo Alto, CA 94303
  49. ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  50. ;;;
  51. ;;; Suggestions, comments and requests for improvements are also welcome.
  52. ;;; *************************************************************************
  53. ;;; 
  54. ;;; Testing code. Note: This file is derived from the PCL file test.l and
  55. ;;; removes some of the PCL specific stuff from the test macro.
  56.  
  57. (in-package 'pcl)
  58. (use-package 'lisp)
  59.  
  60. (require "pcl")
  61.  
  62. (export
  63.   '(
  64.     do-test
  65.   )
  66. )
  67.  
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  69. ;        Catching Errors
  70. ;
  71. ; Since CLtL defines no portable way of catching errors, most system
  72. ; implementors have done their own. Certainly it would be possible
  73. ; to code a portable error catcher, but the complexity involved
  74. ; (catching errors at macroexpand time as well, etc.) is considerable.
  75. ; As a stopgap, the *WITHOUT-ERRORS* special is provided for people
  76. ; bringing up COOL on a new system to add their system's special error
  77. ; catching code. It is taken from the original PCL test file.
  78. ;
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80.  
  81. ;;Other info needed for exception handling
  82.  
  83. #+HP (require "exception")
  84.  
  85. (defvar *without-errors*
  86.     (or #+Symbolics #'(lambda (form)
  87.                 `(multiple-value-bind (.values. .errorp.)
  88.                  (si::errset ,form nil)
  89.                    (declare (ignore .values.))
  90.                    .errorp.))
  91.         #+Xerox     #'(lambda (form)
  92.                 `(xcl:condition-case (progn ,form nil)
  93.                    (error () t)))
  94.         
  95.             #+HP    #'(lambda (form)
  96.                 `(extn:when-error 
  97.                    (progn ,form NIL)
  98.                    T
  99.                 )
  100.             )
  101.         nil
  102.         )
  103.  
  104. ) ;defvar
  105.  
  106. ;;without-errors-This macro generates code for error testing
  107.  
  108. (defmacro without-errors (&body body)
  109.  
  110.     (if *without-errors*
  111.       (funcall *without-errors* `(progn ,@body))
  112.       (error "Calling WITHOUT-ERRORS when *without-errors* is nil.")
  113.     )
  114.  
  115.  
  116. ) ;without-errors
  117.  
  118. ;;with-return-value-Set up each form in BODY to match return value
  119.  
  120. (defmacro with-return-value (form return-value)
  121.  
  122.   ;;Note the use of full qualification on EQUALP
  123.   ;;  to avoid problems with redefinition from CO
  124.  
  125.   `(lisp::equalp ',return-value ,form)
  126.  
  127. ) ;with-return-value
  128.  
  129. ;;do-test-Execute BODY according to the options list
  130.  
  131. (defmacro do-test (name&options &body body)
  132.   (let 
  133.     (
  134.       (name (if (listp name&options) (car name&options) name&options))
  135.       (options (if (listp name&options) (cdr name&options) ()))
  136.       (code NIL)
  137.     )
  138.  
  139.     ;;Bind the options from keywords
  140.   
  141.     (keyword-bind 
  142.       (
  143.         (should-error nil)
  144.         (return-value nil)
  145.       )
  146.  
  147.       options
  148.     
  149.       ;;Check if errors should be caught and can be
  150.  
  151.       (cond 
  152.  
  153.         ;;Errors can't be caught in this Lisp, so don't do it
  154.  
  155.         (
  156.           (and should-error (null *without-errors*))
  157.       `(format t
  158.         "~&Skipping testing ~A,~%~
  159.          because can't ignore errors in this Common Lisp."
  160.          ',name
  161.           )
  162.         )
  163.  
  164.         ;;Generate code for test. If the return value was supplied
  165.         ;;  as an option, check if the return values are the same.
  166.         ;;  Note the use of LISP::EQUALP. This is because CommonObjects
  167.         ;;  redefines EQUALP.
  168.  
  169.         (t
  170.       `(progn
  171.         (format t "~&Testing ")
  172.         (format t ,name)
  173.         (format t "... ")
  174.             ,@(dolist (form  body (reverse code))
  175.                 (push
  176.                   `(if
  177.              ,(cond
  178.             (
  179.               should-error
  180.               `(without-errors ,form)
  181.                         )
  182.                         (
  183.                           return-value
  184.                           `(with-return-value ,@form)
  185.                         )
  186.                         (
  187.                          T
  188.                          `(progn ,form)
  189.                         )
  190.                      )
  191.                      (format T "~&OK: ~S~%" ',form)
  192.              (format T "~&FAILED: ~S~%" ',form)
  193.                   )
  194.                   code
  195.  
  196.                ) ;push
  197.             ) ;dolist
  198.  
  199.           ) ;progn
  200.         )
  201.       ) ;cond
  202.  
  203.     ) ;keyword-bind
  204.  
  205.   ) ;let
  206.  
  207. ) ;do-test
  208.  
  209. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  210.  
  211. (provide "co-test")
  212.  
  213.