home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / 52capi.zip / ASSERT.CH < prev    next >
Text File  |  1993-02-15  |  2KB  |  65 lines

  1. /***
  2. *
  3. *  Assert.ch
  4. *
  5. *  Assertion header file for debugging programs
  6. *
  7. *  Copyright (c) 1993, Computer Associates International Inc.
  8. *  All rights reserved.
  9. *
  10. *  Usage:   ASSERT( <condition> [, <msg>] )
  11. *
  12. *  If <condition> evaluates to true (.T.), ASSERT() does nothing.
  13. *  Otherwise a message is written to STDOUT and the application
  14. *  terminates. If <msg> is specified, it determines the message
  15. *  produced if the assertion fails. Otherwise, the text of the
  16. *  condition itself is output as the message.
  17. *
  18. *  Examples:
  19. *           ASSERT( n > 0 .AND. n < Len(a), "bad array index" )
  20. *           ASSERT( RECCOUNT() <> 0 )
  21. *
  22. *
  23. *  NOTES:
  24. *
  25. *  ASSERT must occur as a statement by itself. The parentheses
  26. *  surrounding the condition and message are required.
  27. *
  28. *  Defining the symbol NDEBUG at compile time (use /dNDEBUG on
  29. *  the compile line) removes all assertions from your program.
  30. *
  31. *  This header file detects the fact that it has been #included
  32. *  more than once in a compile, so it is safe to #include it
  33. *  almost anywhere.
  34. *
  35. *  Refer to Asrtdemo.prg for an example of ASSERT.
  36. *
  37. */
  38.  
  39.  
  40. #ifndef _ASSERT_DEFINED
  41.  
  42. #ifndef NDEBUG
  43.  
  44. #command ASSERT( <exp> [, <msg>] )                                      ;
  45.                                                                         ;
  46.       => IF ( !(<exp>) )                                                ;
  47.        ;   OUTSTD(                                                      ;
  48.                    CHR(13) + CHR(10) + PROCNAME(0) +                    ;
  49.                    "(" + LTRIM(STR(PROCLINE())) + ")" +                 ;
  50.                    "  Assertion failed: " +                             ;
  51.                    IF( <.msg.>, <msg>, <"exp"> )                        ;
  52.                  )                                                      ;
  53.        ;   QUIT                                                         ;
  54.        ; ENDIF
  55.  
  56. #else  // If NDEBUG is definded, ignore all occurences of ASSERT()
  57.  
  58. #command ASSERT( <exp> [, <msg>] )      =>
  59.  
  60. #endif // NDEBUG
  61.  
  62. #define _ASSERT_DEFINED
  63.  
  64. #endif // _ASSERT_DEFINED
  65.