-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ExportableFixture for JSON tests exporting (#821)
Extract utils for JSON tests exporting to abstract `ExportableFixture`.
- Loading branch information
Showing
7 changed files
with
85 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2024 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifdef _MSC_VER | ||
// Disable warning C4996: 'getenv': This function or variable may be unsafe. | ||
#define _CRT_SECURE_NO_WARNINGS | ||
#endif | ||
|
||
#include "exportable_fixture.hpp" | ||
#include <filesystem> | ||
#include <regex> | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace evmone::test | ||
{ | ||
namespace | ||
{ | ||
/// Creates the file path for the exported test based on its name. | ||
fs::path get_export_test_path(const testing::TestInfo& test_info, std::string_view export_dir) | ||
{ | ||
const std::string suite_name{test_info.test_suite_name()}; | ||
|
||
const auto stem = fs::path{test_info.file()}.stem().string(); | ||
const std::regex re{suite_name + "_(.*)_test"}; | ||
std::smatch m; | ||
const auto sub_suite_name = std::regex_match(stem, m, re) ? m[1] : std::string{}; | ||
|
||
const auto dir = fs::path{export_dir} / suite_name / sub_suite_name; | ||
|
||
fs::create_directories(dir); | ||
return dir / (std::string{test_info.name()} + ".json"); | ||
} | ||
} // namespace | ||
|
||
ExportableFixture::ExportableFixture() | ||
{ | ||
if (const auto export_dir = std::getenv("EVMONE_EXPORT_TESTS"); export_dir != nullptr) | ||
{ | ||
const auto& test_info = *testing::UnitTest::GetInstance()->current_test_info(); | ||
export_test_name = test_info.name(); | ||
export_file_path = get_export_test_path(test_info, export_dir).string(); | ||
} | ||
} | ||
} // namespace evmone::test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2024 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#pragma once | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace evmone::test | ||
{ | ||
class ExportableFixture : public testing::Test | ||
{ | ||
protected: | ||
std::string_view export_test_name; | ||
std::string export_file_path; | ||
|
||
ExportableFixture(); | ||
}; | ||
} // namespace evmone::test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters