-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathFileApproverExamples.cpp
More file actions
32 lines (27 loc) · 1005 Bytes
/
FileApproverExamples.cpp
File metadata and controls
32 lines (27 loc) · 1005 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
#include "doctest/doctest.h"
#include "../../DocTest_Tests/reporters/TestReporter.h"
#include "ApprovalTests/core/ApprovalException.h"
#include "ApprovalTests/core/FileApprover.h"
// begin-snippet: create_custom_comparator
class LengthComparator : public ApprovalTests::ApprovalComparator
{
public:
bool contentsAreEquivalent(std::string receivedPath,
std::string approvedPath) const override
{
return ApprovalTests::FileUtils::fileSize(receivedPath) ==
ApprovalTests::FileUtils::fileSize(approvedPath);
}
};
// end-snippet
TEST_CASE("ItUsesCustomComparator")
{
using namespace ApprovalTests;
FileUtils::writeToFile("a.length", "12345");
FileUtils::writeToFile("b.length", "56789");
// begin-snippet: use_custom_comparator
auto disposer = FileApprover::registerComparatorForExtension(
".length", std::make_shared<LengthComparator>());
// end-snippet
FileApprover::verify("a.length", "b.length");
}