Skip to content

Commit

Permalink
Merge pull request #514 from ethereum/statetest_refactor
Browse files Browse the repository at this point in the history
statetest: Extract test registration to separate function
  • Loading branch information
chfast authored Oct 20, 2022
2 parents 38c5bb2 + b033cbd commit 4351c41
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
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();
}

0 comments on commit 4351c41

Please sign in to comment.