forked from approvals/ApprovalTests.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionCollectorTests.cpp
More file actions
33 lines (30 loc) · 941 Bytes
/
ExceptionCollectorTests.cpp
File metadata and controls
33 lines (30 loc) · 941 Bytes
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
#include "doctest/doctest.h"
#include "ApprovalTests/Approvals.h"
#include "ApprovalTests/utilities/ExceptionCollector.h"
#include "ApprovalTests/utilities/StringUtils.h"
using namespace ApprovalTests;
TEST_CASE("ExceptionCollector")
{
using namespace ApprovalTests;
Approvals::verifyExceptionMessage([]() {
ExceptionCollector exceptions;
for (int i = 1; i <= 4; ++i)
{
exceptions.gather([&]() {
throw std::runtime_error("error number " + StringUtils::toString(i));
});
}
exceptions.release();
});
}
TEST_CASE("ExceptionCollectorSampleTemplate")
{
// begin-snippet: exception_collector_template
ExceptionCollector exceptions;
for (int i = 1; i <= 4; ++i)
{
exceptions.gather([&]() { /* Code that may throw errors here */ });
}
exceptions.release(); // All errors actually thrown together here
// end-snippet
}