aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/unit++/tester.cc
blob: f4b65acd5b9142b2c5138c8e9321fcb49ee6ec67 (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
// Copyright (C) 2001 Claus Dr�by
// Terms of use are in the file COPYING
#include <typeinfo>
#include <iostream>
#include "tester.h"
using namespace std;

using namespace unitpp;

void tester::summary()
{
	os << "Tests [Ok-Fail-Error]: [" << n_test.n_ok() << '-'
	<< n_test.n_fail() << '-' << n_test.n_err() << "]\n";
}
void tester::visit(test& t)
{
	try {
		t();
		n_test.add_ok();
		write(t);
	} catch (assertion_error& e) {
		n_test.add_fail();
		write(t, e);
	} catch (exception& e) {
		n_test.add_err();
		write(t, e);
	} catch (...) {
		n_test.add_err();
		write(t, 0);
	}
}

void tester::visit(suite& t)
{
	if (verbose)
		os << "****** " << t.name() << " ******" << endl;
	accu.push(n_test);
}

void tester::visit(suite& , int)
{
	res_cnt r(accu.top());
	accu.pop();
	if (n_test.n_err() != r.n_err())
		n_suite.add_err();
	else if (n_test.n_fail() != r.n_fail())
		n_suite.add_fail();
	else
		n_suite.add_ok();
}
void tester::write(test& t)
{
	if (verbose)
		disp(t, "OK");
}
void tester::disp(test& t, const string& status)
{
	os << status << ": " << t.name() << endl;
}
void tester::write(test& t, assertion_error& e)
{
	disp(t, "FAIL");
	os << e << '\n';
}
void tester::write(test& t, std::exception& e)
{
	disp(t, "ERROR");
	os << "     : [" << typeid(e).name() << "] " << e.what() << '\n';
}
void tester::write(test& t, int )
{
	disp(t, "ERROR");
	os << "     : " << "unknown exception" << '\n';
}