Skip to content

Commit

Permalink
Added proper tests naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
JSzymanskiJS committed Oct 21, 2022
1 parent f2dbcc4 commit be0c533
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
49 changes: 44 additions & 5 deletions test/statetest/statetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,47 @@ class StateTest : public testing::Test
void TestBody() final { evmone::test::load_state_test(m_json_test_file); }
};

void register_test_files(const std::vector<fs::path>& root_test_paths)
std::string longestCommonPath(const std::vector<std::string>& dirs, char separator)
{
auto vsi = dirs.begin();
auto maxCharactersCommon = vsi->length();
std::string compareString = *vsi;
for (vsi = dirs.begin() + 1; vsi != dirs.end(); vsi++)
{
auto p = std::mismatch(compareString.begin(), compareString.end(), vsi->begin());
if ((p.first - compareString.begin()) < (int)maxCharactersCommon)
maxCharactersCommon = p.first - compareString.begin();
}
auto found = compareString.rfind(separator, maxCharactersCommon);
return compareString.substr(0, found);
}

bool decreasing(std::string str, std::string str2)
{
if (str.length() > str2.length())
return 1;
else
return 0;
}

void register_test_files(const std::vector<std::string>& root_test_strings)
{
auto lcp = fs::path(longestCommonPath(root_test_strings, '/'));

std::vector<fs::path> root_test_paths;

for (auto &root_string: root_test_strings)
{
fs::path root_test_path = fs::path(root_string);
if (!root_test_path.has_extension() ||
(root_test_path.has_extension() && root_test_path.extension() == ".json"))
root_test_paths.push_back(root_test_path);
}

for (auto root_dir: root_test_paths)
{
std::vector<fs::path> test_files;
if (root_dir.has_extension() && root_dir.extension() == ".json")
if (root_dir.has_extension())
{
test_files.push_back(root_dir);
}
Expand All @@ -40,14 +75,16 @@ void register_test_files(const std::vector<fs::path>& root_test_paths)
}
for (const auto& p : test_files)
{
const auto d = fs::relative(p, root_dir);
const auto d = fs::relative(p, lcp);
testing::RegisterTest(d.parent_path().string().c_str(), d.stem().string().c_str(), nullptr,
nullptr, p.string().c_str(), 0, [p]() -> testing::Test* { return new StateTest(p); });
}
}
}
} // namespace



int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc, argv); // Process GoogleTest flags.
Expand All @@ -58,13 +95,15 @@ int main(int argc, char* argv[])
return -1;
}

std::vector<fs::path> root_test_paths;
std::vector<std::string> root_test_paths;

for (int i = 1; i < argc; i++)
{
root_test_paths.push_back(fs::path(argv[i]));
root_test_paths.push_back(argv[i]);
}

std::sort(root_test_paths.begin(), root_test_paths.end(), decreasing);

register_test_files(root_test_paths);
return RUN_ALL_TESTS();
}

0 comments on commit be0c533

Please sign in to comment.