blob: e1216cbe9cd3ad84347ee5f24d76fdfa91371516 [file] [log] [blame]
onqtamcb6a29f2018-08-23 16:24:06 +03001<!DOCTYPE html>
2<html>
3<title>reporters</title>
4<xmp theme="united" style="display:none;">
5
6## Reporters
7
onqtam9639cee2018-10-24 17:46:32 +03008A very sloppy documentation of the partial reporters support.
9
10Example how to define your own reporter:
11
12```
13using namespace doctest;
14
15struct XmlReporter : public IReporter
16{
17 std::ostream& s;
18 std::vector<SubcaseSignature> subcasesStack;
19
20 // caching pointers to objects of these types - safe to do
21 const ContextOptions* opt;
22 const TestCaseData* tc;
23
24 XmlReporter(std::ostream& in)
25 : s(in) {}
26
27 void test_run_start(const ContextOptions& o) override { opt = &o; }
28
29 void test_run_end(const TestRunStats& /*p*/) override {}
30
31 void test_case_start(const TestCaseData& in) override { tc = &in; }
32
33 void test_case_end(const CurrentTestCaseStats& /*st*/) override {}
34
35 void subcase_start(const SubcaseSignature& subc) override { subcasesStack.push_back(subc); }
36
37 void subcase_end(const SubcaseSignature& /*subc*/) override { subcasesStack.pop_back(); }
38
39 void log_assert(const AssertData& /*rb*/) override {}
40
41 void log_message(const MessageData& /*mb*/) override {}
42
43 void test_case_skipped(const TestCaseData& /*in*/) override {}
44};
45
46XmlReporter r(std::cout);
47DOCTEST_REGISTER_REPORTER("xml", 1, r);
48```
49
50Multiple reporters can be used at the same time - just specify them through the ```--reporters=...``` [**command line option**](commandline.html). The number ```1``` in this case is the priority - reporters will be called in the order defined by their priority when a few of them are selected to be used at the same time.
51
52You can list all registered reporters with ```--list-reporters```. There is only 1 implemented reporter in the framework - a console reporter - an xml one is coming in the next version. the reporter interface can also be used for "listening" to events.
53
54Reporters will be fully implemented and more thoroughly documented (with examples) for version 2.1 - [**roadmap**](roadmap.html).
onqtamcb6a29f2018-08-23 16:24:06 +030055
56TODO: think about:
onqtam9639cee2018-10-24 17:46:32 +030057
58- people having to handle locking on their own in the reporters - just like currently in the console reporter...
59 - or log_assert() can be called for reporters (so also for listeners) only when failed or when printing on success!
60 - or it could be a 'policy' for the reporter
onqtamcb6a29f2018-08-23 16:24:06 +030061
62---------------
63
64[Home](readme.html#reference)
65
66<p align="center"><img src="../../scripts/data/logo/icon_2.svg"></p>
67
68
69</xmp>
70<script src="strapdown.js/strapdown.js"></script>
71</html>