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
31 lines (28 loc) · 930 Bytes
/
Copy pathExceptionCollectorTests.cpp
File metadata and controls
31 lines (28 loc) · 930 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
#include "doctest.h"
#include "ApprovalTests/Approvals.h"
#include "ApprovalTests/writers/StringWriter.h"
#include "ApprovalTests/utilities/ExceptionCollector.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
}