Skip to content

Instantly share code, notes, and snippets.

@kasajian
Last active October 23, 2020 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasajian/98e5c12539474f48ea8742862662ad09 to your computer and use it in GitHub Desktop.
Save kasajian/98e5c12539474f48ea8742862662ad09 to your computer and use it in GitHub Desktop.
Approval Tests CPP
#include "ApprovalTests.hpp"
#include <iostream>
void TestXyz()
{
try
{
TestName currentTest;
currentTest.setFileName(__FILE__);
currentTest.sections = { "TestXyz" };
ApprovalTestNamer::currentTest(&currentTest);
Approvals::verify("Some\nMulti-line\noutput");
}
catch (const ApprovalException& e)
{
std::cout << e.what() << std::endl;
}
}
int main()
{
TestXyz();
}
#include <codecvt>
#include <string>
#include "ApprovalTests.hpp"
#define APPROVAL_METHOD_START(methodName) \
try \
{ \
TestName currentTest; \
currentTest.setFileName(__FILE__); \
currentTest.sections = { #methodName }; \
ApprovalTestNamer::currentTest(&currentTest);
#define APPROVAL_METHOD_END \
} \
catch (const ApprovalException& e) \
{ \
Assert::Fail( \
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>() \
.from_bytes(e.what()) \
.c_str()); \
}
inline static void ApprovalsVerify(const wchar_t* contents, const Reporter &reporter = DefaultReporter())
{
Approvals::verify(std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().to_bytes(contents), reporter);
}
inline static void ApprovalsVerify(const char* contents, const Reporter &reporter = DefaultReporter())
{
Approvals::verify(contents, reporter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment