onqtam | cb6a29f | 2018-08-23 16:24:06 +0300 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <title>reporters</title> |
| 4 | <xmp theme="united" style="display:none;"> |
| 5 | |
| 6 | ## Reporters |
| 7 | |
onqtam | 9639cee | 2018-10-24 17:46:32 +0300 | [diff] [blame^] | 8 | A very sloppy documentation of the partial reporters support. |
| 9 | |
| 10 | Example how to define your own reporter: |
| 11 | |
| 12 | ``` |
| 13 | using namespace doctest; |
| 14 | |
| 15 | struct 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 = ∈ } |
| 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 | |
| 46 | XmlReporter r(std::cout); |
| 47 | DOCTEST_REGISTER_REPORTER("xml", 1, r); |
| 48 | ``` |
| 49 | |
| 50 | Multiple 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 | |
| 52 | You 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 | |
| 54 | Reporters will be fully implemented and more thoroughly documented (with examples) for version 2.1 - [**roadmap**](roadmap.html). |
onqtam | cb6a29f | 2018-08-23 16:24:06 +0300 | [diff] [blame] | 55 | |
| 56 | TODO: think about: |
onqtam | 9639cee | 2018-10-24 17:46:32 +0300 | [diff] [blame^] | 57 | |
| 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 |
onqtam | cb6a29f | 2018-08-23 16:24:06 +0300 | [diff] [blame] | 61 | |
| 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> |