From eb4822b44b96a385d3a5b2225046f87b38a4ee77 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 24 Jan 2022 14:44:04 +0100 Subject: [PATCH] Test: Add macro that bails function if the condition fails --- test/macro.h | 8 ++++++++ test/testdotfile.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/macro.h b/test/macro.h index 8da47d1..e38a92b 100644 --- a/test/macro.h +++ b/test/macro.h @@ -4,6 +4,14 @@ #include // fprintf #include // 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", \ diff --git a/test/testdotfile.cpp b/test/testdotfile.cpp index c4498a2..aab50af 100644 --- a/test/testdotfile.cpp +++ b/test/testdotfile.cpp @@ -23,7 +23,7 @@ const size_t homeDirectorySize = homeDirectory.size(); void createTestDotfiles(const std::vector& fileNames, const std::vector& 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);