Browse Source

Test: Update verify macro to support a custom result behavior

master
Riyyi 3 years ago
parent
commit
91f8253ed5
  1. 4
      test/macro.h
  2. 18
      test/testdotfile.cpp

4
test/macro.h

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

18
test/testdotfile.cpp

@ -24,7 +24,7 @@ const size_t homeDirectorySize = homeDirectory.string().size();
void createTestDotfiles(const std::vector<std::string>& fileNames, const std::vector<std::string>& fileContents, bool asRoot = false) void createTestDotfiles(const std::vector<std::string>& fileNames, const std::vector<std::string>& fileContents, bool asRoot = false)
{ {
VERIFY(fileNames.size() == fileContents.size()); VERIFY(fileNames.size() == fileContents.size(), return);
if (root && !asRoot) { if (root && !asRoot) {
setegid(Machine::the().gid()); setegid(Machine::the().gid());
@ -97,8 +97,8 @@ TEST_CASE(AddDotfiles)
Dotfile::the().add(fileNames); Dotfile::the().add(fileNames);
for (const auto& file : fileNames) { for (const auto& file : fileNames) {
EXPECT(std::filesystem::exists(file)); VERIFY(std::filesystem::exists(file), continue);
EXPECT(std::filesystem::exists(file.substr(homeDirectorySize + 1))); VERIFY(std::filesystem::exists(file.substr(homeDirectorySize + 1)), continue);
Util::File lhs(file); Util::File lhs(file);
Util::File rhs(file.substr(homeDirectorySize + 1)); Util::File rhs(file.substr(homeDirectorySize + 1));
@ -153,8 +153,8 @@ TEST_CASE(PullDotfiles)
Dotfile::the().pull(fileNames); Dotfile::the().pull(fileNames);
for (size_t i = 0; i < fileNames.size(); ++i) { for (size_t i = 0; i < fileNames.size(); ++i) {
EXPECT(std::filesystem::exists(homeFileNames.at(i))); VERIFY(std::filesystem::exists(homeFileNames.at(i)), continue);
EXPECT(std::filesystem::exists(fileNames.at(i))); VERIFY(std::filesystem::exists(fileNames.at(i)), continue);
Util::File lhs(homeFileNames.at(i)); Util::File lhs(homeFileNames.at(i));
Util::File rhs(fileNames.at(i)); Util::File rhs(fileNames.at(i));
@ -186,8 +186,8 @@ TEST_CASE(PushDotfiles)
Dotfile::the().push(fileNames); Dotfile::the().push(fileNames);
for (const auto& file : fileNames) { for (const auto& file : fileNames) {
EXPECT(std::filesystem::exists(file)); VERIFY(std::filesystem::exists(file), continue);
EXPECT(std::filesystem::exists(homeDirectory / file)); VERIFY(std::filesystem::exists(homeDirectory / file), continue);
Util::File lhs(file); Util::File lhs(file);
Util::File rhs(homeDirectory / file); Util::File rhs(homeDirectory / file);
@ -225,7 +225,7 @@ TEST_CASE(PushDotfilesWithExcludePath)
TEST_CASE(AddSystemDotfiles) TEST_CASE(AddSystemDotfiles)
{ {
VERIFY(geteuid() == 0); VERIFY(geteuid() == 0, return);
Dotfile::the().setSystemDirectories({ "/etc", "/usr/lib" }); Dotfile::the().setSystemDirectories({ "/etc", "/usr/lib" });
Dotfile::the().add({ "/etc/group", "/usr/lib/os-release" }); Dotfile::the().add({ "/etc/group", "/usr/lib/os-release" });
@ -240,7 +240,7 @@ TEST_CASE(AddSystemDotfiles)
TEST_CASE(PullSystemDotfiles) TEST_CASE(PullSystemDotfiles)
{ {
VERIFY(geteuid() == 0); VERIFY(geteuid() == 0, return);
createTestDotfiles({ "etc/group" }, { "" }, true); createTestDotfiles({ "etc/group" }, { "" }, true);

Loading…
Cancel
Save