Show
Ignore:
Timestamp:
09/09/10 22:40:57 (21 months ago)
Author:
westram
Message:
  • unit-test improvements (merged [6757] [6758] [6759] [6760] [6761] [6762] [6764] [6791] [6795] [6798] [6799] [6800] [6801] [6802] [6809] [6810])
    • moved file compare to test_unit.h
    • fake report for skipped tests
    • added templates for char compare
    • perform minihexdump
    • flush output
    • added
      • TEST_ASSERT_FILES_EQUAL__BROKEN
      • TEST_ASSERT_ZERO_OR_SHOW_ERRNO
    • create a fake.patch if there are no changes
    • all code affecting assertions in UNIT_TESTS-mode went to test_global.h
      • overwrites arb_assert()
    • undefine UNIT_TESTS for GDE submakefiles (foreign code there)
    • arb_test::FlushedOutput::errorf raises assertion itself
    • test against I/O errors
    • moved test code
    • refactored message printing
    • unit-tester switches to run directory itself
      • eliminates path hack for valgrind
    • control leak-check by variable
    • added global test-environment (does nothing yet)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ARBDB/arb_assert.h

    r6813 r6816  
    180180 
    181181#if (UNIT_TESTS == 1) 
    182 # if defined(DEVEL_RELEASE) 
    183 #  error Unit testing not allowed in release 
    184 # else 
    185  
    186 #  ifdef __cplusplus 
    187  
    188 #ifndef _CPP_CSTDLIB 
    189 #include <cstdlib> 
    190 #endif 
    191  
    192 namespace arb_test { 
    193     class GlobalTestData { 
    194         GlobalTestData() 
    195             : show_warnings(true), 
    196               assertion_failed(false), 
    197               warnings(0) 
    198         {} 
    199  
    200         static GlobalTestData *instance(bool erase) { 
    201             static GlobalTestData *data = 0; // singleton 
    202             if (erase) { 
    203                 delete data; 
    204                 data = 0; 
    205             } 
    206             else { 
    207                 if (!data) data = new GlobalTestData; 
    208             } 
    209             return data; 
    210         } 
    211  
    212     public: 
    213         bool show_warnings; 
    214         bool assertion_failed; 
    215  
    216         // counters 
    217         size_t warnings; 
    218  
    219         static GlobalTestData& get_instance() { return *instance(false); } 
    220         static void erase_instance() { instance(true); } 
    221     }; 
    222  
    223     inline GlobalTestData& test_data() { return GlobalTestData::get_instance(); } 
    224 }; 
    225  
    226 #   define ASSERTION_HAS_FAILED() arb_test::test_data().assertion_failed = true   
    227  
    228 #  else 
    229 #   define ASSERTION_HAS_FAILED() // impossible in C 
    230 #  endif 
    231  
    232 #  define test_assert(cond)                                     \ 
    233     do {                                                        \ 
    234         if (!(cond)) {                                          \ 
    235             fflush(stdout);                                     \ 
    236             fflush(stderr);                                     \ 
    237             fprintf(stderr, "%s:%i: Assertion '%s' failed\n",   \ 
    238                     __FILE__, __LINE__, #cond);                 \ 
    239             fflush(stderr);                                     \ 
    240             ASSERTION_HAS_FAILED();                             \ 
    241             ARB_SIGSEGV(0);                                     \ 
    242         }                                                       \ 
    243     } while(0) 
    244  
    245 #  if defined(ASSERTION_USED) 
    246 #   undef arb_assert 
    247 #   define arb_assert(cond) test_assert(cond) 
    248 #  endif 
    249  
    250 # endif 
     182#ifndef TEST_GLOBAL_H 
     183#include <test_global.h> // overrides arb_assert()! 
     184#endif 
    251185#endif 
    252186