wibble
1.1
Main Page
Namespaces
Classes
Files
File List
File Members
wibble
test-runner.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
#include <
wibble/sys/macros.h
>
3
4
#include <unistd.h>
5
#ifdef POSIX
6
#include <
wibble/sys/pipe.h
>
7
#endif
8
#include <cstdio>
9
10
#define RUN(x, y) x().y()
11
12
struct
RunTest
{
13
const
char
*
name
;
14
void (*
run
)();
15
};
16
17
struct
RunSuite
{
18
const
char
*
name
;
19
RunTest
*
tests
;
20
int
testCount
;
21
22
int
findTest
( std::string
name
) {
23
for
(
int
i = 0; i <
testCount
; ++i )
24
if
(
tests
[i].name == name )
25
return
i;
26
return
-1;
27
}
28
29
};
30
31
struct
RunFeedback
{
32
virtual
void
status
( std::string l ) = 0;
33
virtual
void
waitForAck
() = 0;
34
};
35
36
struct
RunAll
{
37
RunSuite
*
suites
;
38
int
suiteCount
;
39
RunFeedback
*
feedback
;
40
41
RunSuite
*
findSuite
( std::string name ) {
42
for
(
int
i = 0; i <
suiteCount
; ++i )
43
if
(
suites
[i].name == name )
44
return
suites
+ i;
45
return
0;
46
}
47
48
void
runSuite
(
RunSuite
&s,
int
fromTest,
int
suite,
int
suiteCount
)
49
{
50
feedback
->
status
(
wibble::str::fmtf
(
51
"s/s: (%d/%d) %s"
, suite + 1, suiteCount, s.
name
) );
52
for
(
int
i = fromTest; i < s.
testCount
; ++i ) {
53
feedback
->
status
(
wibble::str::fmtf
(
54
"t/s: (%d/%d) %s"
, i, s.
testCount
, s.
tests
[i].
name
) );
55
feedback
->
waitForAck
();
56
s.
tests
[i].
run
();
57
feedback
->
status
( std::string(
"t/d: "
) + s.
tests
[i].
name
);
58
feedback
->
waitForAck
();
59
// exit( 0 ); // TODO make this optional; safety vs
60
// performance tradeoff
61
}
62
feedback
->
status
( std::string(
"s/d: "
) + s.
name
);
63
}
64
65
void
runTest
(
RunSuite
&s,
int
test )
66
{
67
feedback
->
status
( std::string(
"s/s: (1/1) "
) + s.
name
);
68
feedback
->
status
( std::string(
"t/s: (1/1) "
) + s.
tests
[test].
name
);
69
feedback
->
waitForAck
();
70
s.
tests
[test].
run
();
71
feedback
->
status
( std::string(
"t/d: "
) + s.
tests
[test].
name
);
72
feedback
->
waitForAck
();
73
feedback
->
status
( std::string(
"s/d: "
) + s.
name
);
74
}
75
76
void
runFrom
(
int
suite,
int
test )
77
{
78
for
(
int
i = suite; i <
suiteCount
; ++i ) {
79
assert
( suite <= suiteCount );
80
runSuite
(
suites
[i], test, i, suiteCount );
81
test = 0;
82
}
83
}
84
};
Generated on Wed Oct 23 2013 17:14:25 for wibble by
1.8.4