Changeset 585

Show
Ignore:
Timestamp:
09/28/07 12:14:38 (1 year ago)
Author:
takkaria
Message:

Generalise the testsuite a bit; patch by Fennec on IRC.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/tests/z-file.c

    r469 r585  
    1414#include <stdio.h> 
    1515#include "../z-file.h" 
    16  
    17 /*** Hacky basic test structure ***/ 
    18  
    19 typedef struct 
    20 
    21         unsigned num_tests; 
    22         unsigned num_tests_failed; 
    23 } test_stats; 
    24  
    25 typedef int (*test_func)(void); 
    26  
    27 void test_run(test_stats *stats, const char *name, test_func tester) 
    28 
    29         stats->num_tests++; 
    30         printf("running test %s... ", name); 
    31  
    32         if ((*tester)() == 0) 
    33         { 
    34                 stats->num_tests_failed++; 
    35                 printf("FAIL\n"); 
    36         } 
    37         else 
    38         { 
    39                 printf("successful\n"); 
    40         } 
    41 
    42  
    43 void test_summarise(test_stats *stats) 
    44 
    45         printf("%d tests\n", stats->num_tests); 
    46         printf("%d failed\n", stats->num_tests_failed); 
    47 
    48  
    49 int test_success(test_stats *stats) 
    50 
    51         return (stats->num_tests_failed) ? 1 : 0; 
    52 
    53  
    54 #define TEST_RUN(stat, test)            test_run(stat, #test, test_##test) 
    55  
    56 #define TEST(x)         static int test_##x(void) { 
    57 #define TEST_END        return 1; } 
    58  
    59 #define FAIL            return 0; 
    60  
    61  
    62  
     16#include "../z-tests.h" 
    6317/*** z-file tests ***/ 
    6418 
     
    356310int main(void) 
    357311{ 
    358         test_stats test = { 0, 0 }
     312        TEST_PLAN(test, 10)
    359313 
    360314        TEST_RUN(&test, file_open); 
     
    370324        TEST_RUN(&test, path_build); 
    371325 
    372         test_summarise(&test); 
    373  
    374         return test_success(&test) ? 0 : 1; 
    375 
     326        TESTS_COMPLETE(test); 
     327
  • trunk/src/tests/z-file.mk

    r469 r585  
    66LDFLAGS = -fprofile-arcs -ftest-coverage 
    77 
    8 OBJS = z-file.o ../z-file.o ../z-virt.o ../z-util.o ../z-form.o  
     8OBJS = z-file.o ../z-tests.o ../z-file.o ../z-virt.o ../z-util.o ../z-form.o  
    99 
    1010$(EXE): $(OBJS)