-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathtest_main.cpp
76 lines (61 loc) · 2.13 KB
/
test_main.cpp
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
76
#include <chrono>
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
using std::string;
using std::chrono::steady_clock;
using std::chrono::milliseconds;
using std::chrono::duration_cast;
using Catch::ConsoleReporter;
using Catch::ReporterConfig;
using Catch::ReporterPreferences;
using Catch::TestCaseInfo;
using Catch::TestCaseStats;
using Catch::Totals;
using Catch::Session;
std::vector<std::string> KAFKA_TOPICS = {KAFKA_TOPIC_NAMES};
namespace cppkafka {
class InstantTestReporter : public ConsoleReporter {
public:
using ClockType = steady_clock;
InstantTestReporter(const ReporterConfig& config)
: ConsoleReporter(config) {
}
static string getDescription() {
return "Reports the tests' progress as they run";
}
ReporterPreferences getPreferences() const override {
ReporterPreferences output;
output.shouldRedirectStdOut = false;
return output;
}
void testCaseStarting(const TestCaseInfo& info) override {
ConsoleReporter::testCaseStarting(info);
stream << "Running test \"" << info.name << "\" @ " << info.lineInfo << "\n";
test_start_ts_ = ClockType::now();
}
void testCaseEnded(const TestCaseStats& stats) override {
const Totals& totals = stats.totals;
const size_t totalTestCases = totals.assertions.passed + totals.assertions.failed;
const auto elapsed = ClockType::now() - test_start_ts_;
stream << "Done. " << totals.assertions.passed << "/" << totalTestCases
<< " assertions succeeded in " << duration_cast<milliseconds>(elapsed).count()
<< "ms\n";
}
private:
ClockType::time_point test_start_ts_;
};
CATCH_REGISTER_REPORTER("instant", InstantTestReporter)
} // cppkafka
int main(int argc, char* argv[]) {
Session session;
int returnCode = session.applyCommandLine( argc, argv );
if (returnCode != 0) {
return returnCode;
}
if (session.configData().reporterNames.empty()) {
// Set our reporter as the default one
session.configData().reporterNames.emplace_back("instant");
}
int numFailed = session.run();
return numFailed;
}