home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 6.ddi / SAMPLE.LIF / ASSERT.CH < prev    next >
Encoding:
Text File  |  1991-04-14  |  2.0 KB  |  62 lines

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