Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statetest: Extract test registration to separate function #514

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ DUP1,4
{\"error\":null,\"gas\":999985,\"gasUsed\":15,\"output\":\"\"}
")


get_property(ALL_TESTS DIRECTORY PROPERTY TESTS)
set_tests_properties(${ALL_TESTS} PROPERTIES ENVIRONMENT LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/integration-%p.profraw)
endif()

add_subdirectory(statetest)

get_property(ALL_TESTS DIRECTORY PROPERTY TESTS)
set_tests_properties(${ALL_TESTS} PROPERTIES ENVIRONMENT LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/integration-%p.profraw)

32 changes: 32 additions & 0 deletions test/integration/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2022 The evmone Authors.
# SPDX-License-Identifier: Apache-2.0

# Integration tests for evmone-statetest.

set(PREFIX ${PREFIX}/statetest)
set(TESTS1 ${CMAKE_CURRENT_SOURCE_DIR}/tests1)

add_test(
NAME ${PREFIX}/missing_arg
COMMAND evmone-statetest
)
set_tests_properties(
${PREFIX}/missing_arg PROPERTIES
PASS_REGULAR_EXPRESSION "Missing argument with the path to the tests directory"
)

add_test(
NAME ${PREFIX}/tests1_list
COMMAND evmone-statetest ${TESTS1} --gtest_list_tests
)
set_tests_properties(
${PREFIX}/tests1_list PROPERTIES
PASS_REGULAR_EXPRESSION [[
B\.
T
SuiteA\.
test1
test2
]]
)
Empty file.
Empty file.
Empty file.
32 changes: 17 additions & 15 deletions test/statetest/statetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@ class StateTest : public testing::Test

void TestBody() final { evmone::test::load_state_test(m_json_test_file); }
};
} // namespace

int main(int argc, char* argv[])
void register_test_files(const fs::path& root_dir)
{
testing::InitGoogleTest(&argc, argv); // Process GoogleTest flags.

if (argc != 2)
{
std::cerr << "Missing argument with the path to the tests directory\n";
return -1;
}

std::vector<fs::path> test_files;
const fs::path root_test_dir{argv[1]};
std::copy_if(fs::recursive_directory_iterator{root_test_dir},
fs::recursive_directory_iterator{}, std::back_inserter(test_files),
[](const fs::directory_entry& entry) {
std::copy_if(fs::recursive_directory_iterator{root_dir}, fs::recursive_directory_iterator{},
std::back_inserter(test_files), [](const fs::directory_entry& entry) {
return entry.is_regular_file() && entry.path().extension() == ".json";
});
std::sort(test_files.begin(), test_files.end());
for (const auto& p : test_files)
{
const auto d = fs::relative(p, root_test_dir);
const auto d = fs::relative(p, root_dir);
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.

if (argc != 2)
{
std::cerr << "Missing argument with the path to the tests directory\n";
return -1;
}

register_test_files(argv[1]);
return RUN_ALL_TESTS();
}