summaryrefslogtreecommitdiffstats
path: root/src/make-tests.sh
blob: b6cf814e70301ddd3220e9686c4f19f6d1d2cb65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh

# Auto generate single AllTests file for CuTest.
# Searches through all *.c files in the current directory.
# Prints to stdout.
# Author: Asim Jalis
# Date: 01/08/2003

# Modified to return non-zero if any test has failed
# Rainer Wichmann, 29. Jan 2006
# ...and to print to stderr if any test has failed
# Rainer Wichmann, 31. Jan 2006

if test $# -eq 0 ; then FILES=*.c ; else FILES=$* ; fi

echo '

/* This is auto-generated code. Edit at your own peril. */

#include "config.h"
#include <stdio.h>
#include "CuTest.h"
'

cat $FILES | grep '^void Test' | 
    sed -e 's/(.*$//' \
        -e 's/$/(CuTest*);/' \
        -e 's/^/extern /'

echo \
'

int RunAllTests(void) 
{
    CuString *output = CuStringNew();
    CuSuite* suite = CuSuiteNew();

'
cat $FILES | grep '^void Test' | 
    sed -e 's/^void //' \
        -e 's/(.*$//' \
        -e 's/^/    SUITE_ADD_TEST(suite, /' \
        -e 's/$/);/'

echo \
'
    CuSuiteRun(suite);
    CuSuiteSummary(suite, output);
    CuSuiteDetails(suite, output);
    if (suite->failCount > 0)
      fprintf(stderr, "%s%c", output->buffer, 0x0A);
    else
      fprintf(stdout, "%s%c", output->buffer, 0x0A);
    return suite->failCount;
}

int main(void)
{
#if !defined(USE_SYSTEM_MALLOC)
    typedef void assert_handler_tp(const char * error, const char *file, int line);
    extern assert_handler_tp *dnmalloc_set_handler(assert_handler_tp *new);
    extern void safe_fatal  (const char * details, const char *f, int l);
#endif
#if !defined(USE_SYSTEM_MALLOC) && defined(USE_MALLOC_LOCK)
    extern int dnmalloc_pthread_init(void);
    dnmalloc_pthread_init();
#endif
#if !defined(USE_SYSTEM_MALLOC)
    (void) dnmalloc_set_handler(safe_fatal);
#endif
    int retval;
    retval = RunAllTests();
    return (retval == 0) ? 0 : 1;
}
'