Browse Source

Test: Add macro that bails function if the condition fails

master
Riyyi 3 years ago
parent
commit
eb4822b44b
  1. 8
      test/macro.h
  2. 2
      test/testdotfile.cpp

8
test/macro.h

@ -4,6 +4,14 @@
#include <cstdio> // fprintf
#include <iostream> // cerr
#define VERIFY(x) \
if (!(x)) { \
fprintf(stderr, " \033[31;1mFAIL:\033[0m %s:%d: VERIFY(%s) failed\n", \
__FILE__, __LINE__, #x); \
Test::TestSuite::the().currentTestCaseFailed(); \
return; \
}
#define EXPECT(x) \
if (!(x)) { \
fprintf(stderr, " \033[31;1mFAIL:\033[0m %s:%d: EXPECT(%s) failed\n", \

2
test/testdotfile.cpp

@ -23,7 +23,7 @@ const size_t homeDirectorySize = homeDirectory.size();
void createTestDotfiles(const std::vector<std::string>& fileNames, const std::vector<std::string>& fileContents)
{
EXPECT_EQ(fileNames.size(), fileContents.size());
VERIFY(fileNames.size() == fileContents.size());
for (size_t i = 0; i < fileNames.size(); ++i) {
auto fileName = fileNames.at(i);

Loading…
Cancel
Save