From e7a05b3488294a31d3944f05bc8d20696e9f73ff Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 29 Sep 2025 13:34:02 +0800 Subject: [PATCH] refactor: rename testbench to test. - rename testbench to test. - add benchmark for future development. --- CMakeLists.txt | 20 +++++++++++----- COMPILE.md | 6 ++--- benchmark/CMakeLists.txt | 24 +++++++++++++++++++ benchmark/main.cpp | 4 ++++ doc/Doxyfile.in | 2 +- doc/src/arg_parser.dox | 2 +- {testbench => test}/CMakeLists.txt | 16 ++++++------- {testbench => test}/main.cpp | 0 {testbench => test}/main_legacy.cpp | 0 {testbench => test}/shared/literals.cpp | 0 {testbench => test}/shared/literals.hpp | 0 {testbench => test}/yycc/carton/clap.cpp | 0 {testbench => test}/yycc/carton/pycodec.cpp | 0 {testbench => test}/yycc/carton/tabulate.cpp | 0 {testbench => test}/yycc/carton/termcolor.cpp | 0 {testbench => test}/yycc/carton/wcwidth.cpp | 0 {testbench => test}/yycc/constraint.cpp | 0 .../yycc/constraint/builder.cpp | 0 {testbench => test}/yycc/encoding/iconv.cpp | 0 {testbench => test}/yycc/encoding/stl.cpp | 0 {testbench => test}/yycc/encoding/windows.cpp | 0 {testbench => test}/yycc/flag_enum.cpp | 0 .../yycc/macro/compiler_detector.cpp | 0 .../yycc/macro/endian_detector.cpp | 0 .../yycc/macro/os_detector.cpp | 0 .../yycc/macro/ptr_size_detector.cpp | 0 .../yycc/macro/stl_detector.cpp | 0 .../yycc/macro/version_cmp.cpp | 0 {testbench => test}/yycc/num/op.cpp | 0 {testbench => test}/yycc/num/parse.cpp | 0 {testbench => test}/yycc/num/safe_cast.cpp | 0 {testbench => test}/yycc/num/safe_op.cpp | 0 {testbench => test}/yycc/num/stringify.cpp | 0 {testbench => test}/yycc/patch/fopen.cpp | 0 {testbench => test}/yycc/patch/format.cpp | 0 {testbench => test}/yycc/patch/ptr_pad.cpp | 0 {testbench => test}/yycc/patch/stream.cpp | 0 {testbench => test}/yycc/rust/env.cpp | 0 {testbench => test}/yycc/string/op.cpp | 0 .../yycc/string/reinterpret.cpp | 0 {testbench => test}/yycc/windows/com.cpp | 0 {testbench => test}/yycc/windows/console.cpp | 0 {testbench => test}/yycc/windows/dialog.cpp | 0 {testbench => test}/yycc/windows/winfct.cpp | 0 44 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 benchmark/CMakeLists.txt create mode 100644 benchmark/main.cpp rename {testbench => test}/CMakeLists.txt (82%) rename {testbench => test}/main.cpp (100%) rename {testbench => test}/main_legacy.cpp (100%) rename {testbench => test}/shared/literals.cpp (100%) rename {testbench => test}/shared/literals.hpp (100%) rename {testbench => test}/yycc/carton/clap.cpp (100%) rename {testbench => test}/yycc/carton/pycodec.cpp (100%) rename {testbench => test}/yycc/carton/tabulate.cpp (100%) rename {testbench => test}/yycc/carton/termcolor.cpp (100%) rename {testbench => test}/yycc/carton/wcwidth.cpp (100%) rename {testbench => test}/yycc/constraint.cpp (100%) rename {testbench => test}/yycc/constraint/builder.cpp (100%) rename {testbench => test}/yycc/encoding/iconv.cpp (100%) rename {testbench => test}/yycc/encoding/stl.cpp (100%) rename {testbench => test}/yycc/encoding/windows.cpp (100%) rename {testbench => test}/yycc/flag_enum.cpp (100%) rename {testbench => test}/yycc/macro/compiler_detector.cpp (100%) rename {testbench => test}/yycc/macro/endian_detector.cpp (100%) rename {testbench => test}/yycc/macro/os_detector.cpp (100%) rename {testbench => test}/yycc/macro/ptr_size_detector.cpp (100%) rename {testbench => test}/yycc/macro/stl_detector.cpp (100%) rename {testbench => test}/yycc/macro/version_cmp.cpp (100%) rename {testbench => test}/yycc/num/op.cpp (100%) rename {testbench => test}/yycc/num/parse.cpp (100%) rename {testbench => test}/yycc/num/safe_cast.cpp (100%) rename {testbench => test}/yycc/num/safe_op.cpp (100%) rename {testbench => test}/yycc/num/stringify.cpp (100%) rename {testbench => test}/yycc/patch/fopen.cpp (100%) rename {testbench => test}/yycc/patch/format.cpp (100%) rename {testbench => test}/yycc/patch/ptr_pad.cpp (100%) rename {testbench => test}/yycc/patch/stream.cpp (100%) rename {testbench => test}/yycc/rust/env.cpp (100%) rename {testbench => test}/yycc/string/op.cpp (100%) rename {testbench => test}/yycc/string/reinterpret.cpp (100%) rename {testbench => test}/yycc/windows/com.cpp (100%) rename {testbench => test}/yycc/windows/console.cpp (100%) rename {testbench => test}/yycc/windows/dialog.cpp (100%) rename {testbench => test}/yycc/windows/winfct.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64eda3d..0b4c1a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Provide options -option(YYCC_BUILD_TESTBENCH "Build testbench of YYCCommonplace." OFF) +option(YYCC_BUILD_TEST "Build test of YYCCommonplace." OFF) +option(YYCC_BUILD_BENCHMARK "Build benchmark of YYCCommonplace." OFF) option(YYCC_BUILD_DOC "Build document of YYCCommonplace." OFF) option(YYCC_ENFORCE_ICONV "Enforce iconv support for this library (e.g. in MSYS2 environment)." OFF) @@ -26,21 +27,28 @@ set(YYCC_INSTALL_DOC_PATH ${CMAKE_INSTALL_DOCDIR} CACHE PATH "Non-arch doc install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.") # Include dependency. -# GTest is required if we build testbench -if (YYCC_BUILD_TESTBENCH) +# GTest is required if we build test +if (YYCC_BUILD_TEST) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) find_package(GTest REQUIRED) endif () +# Google Benchmark is required if we build benchmark +if (YYCC_BUILD_BENCHMARK) + find_package(benchmark REQUIRED) +endif () # Iconv is required if we are not in Windows or user request it if (YYCC_ENFORCE_ICONV OR (NOT WIN32)) find_package(Iconv REQUIRED) endif () -# Import 3 build targets +# Import 4 build targets add_subdirectory(src) -if (YYCC_BUILD_TESTBENCH) - add_subdirectory(testbench) +if (YYCC_BUILD_TEST) + add_subdirectory(test) +endif () +if (YYCC_BUILD_BENCHMARK) + add_subdirectory(benchmark) endif () if (YYCC_BUILD_DOC) add_subdirectory(doc) diff --git a/COMPILE.md b/COMPILE.md index 4e6704e..a6daa74 100644 --- a/COMPILE.md +++ b/COMPILE.md @@ -11,7 +11,7 @@ It means that it is not stable and work in progress. * CMake 3.23 at least. * The common compiler supporting C++ 23 (GCC / Clang / MSVC). * Iconv (Optional on Windows. Required on other systems). -* [GoogleTest](https://github.com/google/googletest) (Required if you build testbench). +* [GoogleTest](https://github.com/google/googletest) (Required if you build test). * Doxygen (Required if you build documentation). * Python and Astral UV (Required if you use "User Build" method) @@ -24,7 +24,7 @@ It means that it is not stable and work in progress. ### GoogleTest -GoogleTest is required if you need to build testbench. +GoogleTest is required if you need to build test. If you don't need this please skip this chapter. We use GoogleTest v1.17.0. @@ -89,7 +89,7 @@ TODO... There is a list listing all variables you may configure during compiling. -* `YYCC_BUILD_TESTBENCH`: Set it to `ON` to build testbench. `OFF` in default. +* `YYCC_BUILD_TEST`: Set it to `ON` to build test. `OFF` in default. It is useful for the developer of this project. It also suit for the user who has runtime issues on their platforms to check whether this project works as expected. * `YYCC_BUILD_DOC`: Set it to `ON` to build documentation. `OFF` in default. diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 0000000..de1acb8 --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,24 @@ +# Create executable benchmark +add_executable(YYCCBenchmark "") +# Setup test sources +target_sources(YYCCBenchmark +PRIVATE + main.cpp +) +# target_sources(YYCCBenchmark +# PRIVATE +# FILE_SET HEADERS +# FILES +# shared/literals.hpp +# ) +# Setup headers +target_include_directories(YYCCBenchmark +PUBLIC + "${CMAKE_CURRENT_LIST_DIR}" +) +# Setup libraries +target_link_libraries(YYCCBenchmark +PRIVATE + YYCCommonplace + benchmark::benchmark +) diff --git a/benchmark/main.cpp b/benchmark/main.cpp new file mode 100644 index 0000000..1334cc9 --- /dev/null +++ b/benchmark/main.cpp @@ -0,0 +1,4 @@ + +int main(int argc, char* argv[]) { + return 0; +} diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 192f3b5..2dd5581 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -1031,7 +1031,7 @@ EXCLUDE_SYMBOLS = # that contain example code fragments that are included (see the \include # command). -EXAMPLE_PATH = @CMAKE_CURRENT_LIST_DIR@/../testbench +EXAMPLE_PATH = @CMAKE_CURRENT_LIST_DIR@/../test # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and diff --git a/doc/src/arg_parser.dox b/doc/src/arg_parser.dox index d44be68..3d20f15 100644 --- a/doc/src/arg_parser.dox +++ b/doc/src/arg_parser.dox @@ -21,7 +21,7 @@ public: m_StringArgument(YYCC_U8("string"), YYCC::ArgParser::AbstractArgument::NO_SHORT_NAME, nullptr, nullptr, true), m_BoolArgument(nullptr, YYCC_U8_CHAR('b'), nullptr), m_ClampedFloatArgument(YYCC_U8("clamped-float"), YYCC::ArgParser::AbstractArgument::NO_SHORT_NAME, nullptr, nullptr, true, YYCC::Constraints::GetMinMaxRangeConstraint(-1.0f, 1.0f)), - m_OptionContext(YYCC_U8("TestArgParser"), YYCC_U8("This is the testbench of argument parser."), { + m_OptionContext(YYCC_U8("TestArgParser"), YYCC_U8("This is the test of argument parser."), { &m_IntArgument, &m_FloatArgument, &m_StringArgument, &m_BoolArgument, &m_ClampedFloatArgument }) {} diff --git a/testbench/CMakeLists.txt b/test/CMakeLists.txt similarity index 82% rename from testbench/CMakeLists.txt rename to test/CMakeLists.txt index 6da20b3..9470dcb 100644 --- a/testbench/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ -# Create executable testbench -add_executable(YYCCTestbench "") -# Setup testbench sources -target_sources(YYCCTestbench +# Create executable test +add_executable(YYCCTest "") +# Setup test sources +target_sources(YYCCTest PRIVATE main.cpp @@ -42,19 +42,19 @@ PRIVATE yycc/carton/tabulate.cpp yycc/carton/clap.cpp ) -target_sources(YYCCTestbench +target_sources(YYCCTest PRIVATE FILE_SET HEADERS FILES shared/literals.hpp ) # Setup headers -target_include_directories(YYCCTestbench +target_include_directories(YYCCTest PUBLIC "${CMAKE_CURRENT_LIST_DIR}" ) # Setup libraries -target_link_libraries(YYCCTestbench +target_link_libraries(YYCCTest PRIVATE YYCCommonplace GTest::gtest_main @@ -62,4 +62,4 @@ PRIVATE # Discover all test include(GoogleTest) -gtest_discover_tests(YYCCTestbench) +gtest_discover_tests(YYCCTest) diff --git a/testbench/main.cpp b/test/main.cpp similarity index 100% rename from testbench/main.cpp rename to test/main.cpp diff --git a/testbench/main_legacy.cpp b/test/main_legacy.cpp similarity index 100% rename from testbench/main_legacy.cpp rename to test/main_legacy.cpp diff --git a/testbench/shared/literals.cpp b/test/shared/literals.cpp similarity index 100% rename from testbench/shared/literals.cpp rename to test/shared/literals.cpp diff --git a/testbench/shared/literals.hpp b/test/shared/literals.hpp similarity index 100% rename from testbench/shared/literals.hpp rename to test/shared/literals.hpp diff --git a/testbench/yycc/carton/clap.cpp b/test/yycc/carton/clap.cpp similarity index 100% rename from testbench/yycc/carton/clap.cpp rename to test/yycc/carton/clap.cpp diff --git a/testbench/yycc/carton/pycodec.cpp b/test/yycc/carton/pycodec.cpp similarity index 100% rename from testbench/yycc/carton/pycodec.cpp rename to test/yycc/carton/pycodec.cpp diff --git a/testbench/yycc/carton/tabulate.cpp b/test/yycc/carton/tabulate.cpp similarity index 100% rename from testbench/yycc/carton/tabulate.cpp rename to test/yycc/carton/tabulate.cpp diff --git a/testbench/yycc/carton/termcolor.cpp b/test/yycc/carton/termcolor.cpp similarity index 100% rename from testbench/yycc/carton/termcolor.cpp rename to test/yycc/carton/termcolor.cpp diff --git a/testbench/yycc/carton/wcwidth.cpp b/test/yycc/carton/wcwidth.cpp similarity index 100% rename from testbench/yycc/carton/wcwidth.cpp rename to test/yycc/carton/wcwidth.cpp diff --git a/testbench/yycc/constraint.cpp b/test/yycc/constraint.cpp similarity index 100% rename from testbench/yycc/constraint.cpp rename to test/yycc/constraint.cpp diff --git a/testbench/yycc/constraint/builder.cpp b/test/yycc/constraint/builder.cpp similarity index 100% rename from testbench/yycc/constraint/builder.cpp rename to test/yycc/constraint/builder.cpp diff --git a/testbench/yycc/encoding/iconv.cpp b/test/yycc/encoding/iconv.cpp similarity index 100% rename from testbench/yycc/encoding/iconv.cpp rename to test/yycc/encoding/iconv.cpp diff --git a/testbench/yycc/encoding/stl.cpp b/test/yycc/encoding/stl.cpp similarity index 100% rename from testbench/yycc/encoding/stl.cpp rename to test/yycc/encoding/stl.cpp diff --git a/testbench/yycc/encoding/windows.cpp b/test/yycc/encoding/windows.cpp similarity index 100% rename from testbench/yycc/encoding/windows.cpp rename to test/yycc/encoding/windows.cpp diff --git a/testbench/yycc/flag_enum.cpp b/test/yycc/flag_enum.cpp similarity index 100% rename from testbench/yycc/flag_enum.cpp rename to test/yycc/flag_enum.cpp diff --git a/testbench/yycc/macro/compiler_detector.cpp b/test/yycc/macro/compiler_detector.cpp similarity index 100% rename from testbench/yycc/macro/compiler_detector.cpp rename to test/yycc/macro/compiler_detector.cpp diff --git a/testbench/yycc/macro/endian_detector.cpp b/test/yycc/macro/endian_detector.cpp similarity index 100% rename from testbench/yycc/macro/endian_detector.cpp rename to test/yycc/macro/endian_detector.cpp diff --git a/testbench/yycc/macro/os_detector.cpp b/test/yycc/macro/os_detector.cpp similarity index 100% rename from testbench/yycc/macro/os_detector.cpp rename to test/yycc/macro/os_detector.cpp diff --git a/testbench/yycc/macro/ptr_size_detector.cpp b/test/yycc/macro/ptr_size_detector.cpp similarity index 100% rename from testbench/yycc/macro/ptr_size_detector.cpp rename to test/yycc/macro/ptr_size_detector.cpp diff --git a/testbench/yycc/macro/stl_detector.cpp b/test/yycc/macro/stl_detector.cpp similarity index 100% rename from testbench/yycc/macro/stl_detector.cpp rename to test/yycc/macro/stl_detector.cpp diff --git a/testbench/yycc/macro/version_cmp.cpp b/test/yycc/macro/version_cmp.cpp similarity index 100% rename from testbench/yycc/macro/version_cmp.cpp rename to test/yycc/macro/version_cmp.cpp diff --git a/testbench/yycc/num/op.cpp b/test/yycc/num/op.cpp similarity index 100% rename from testbench/yycc/num/op.cpp rename to test/yycc/num/op.cpp diff --git a/testbench/yycc/num/parse.cpp b/test/yycc/num/parse.cpp similarity index 100% rename from testbench/yycc/num/parse.cpp rename to test/yycc/num/parse.cpp diff --git a/testbench/yycc/num/safe_cast.cpp b/test/yycc/num/safe_cast.cpp similarity index 100% rename from testbench/yycc/num/safe_cast.cpp rename to test/yycc/num/safe_cast.cpp diff --git a/testbench/yycc/num/safe_op.cpp b/test/yycc/num/safe_op.cpp similarity index 100% rename from testbench/yycc/num/safe_op.cpp rename to test/yycc/num/safe_op.cpp diff --git a/testbench/yycc/num/stringify.cpp b/test/yycc/num/stringify.cpp similarity index 100% rename from testbench/yycc/num/stringify.cpp rename to test/yycc/num/stringify.cpp diff --git a/testbench/yycc/patch/fopen.cpp b/test/yycc/patch/fopen.cpp similarity index 100% rename from testbench/yycc/patch/fopen.cpp rename to test/yycc/patch/fopen.cpp diff --git a/testbench/yycc/patch/format.cpp b/test/yycc/patch/format.cpp similarity index 100% rename from testbench/yycc/patch/format.cpp rename to test/yycc/patch/format.cpp diff --git a/testbench/yycc/patch/ptr_pad.cpp b/test/yycc/patch/ptr_pad.cpp similarity index 100% rename from testbench/yycc/patch/ptr_pad.cpp rename to test/yycc/patch/ptr_pad.cpp diff --git a/testbench/yycc/patch/stream.cpp b/test/yycc/patch/stream.cpp similarity index 100% rename from testbench/yycc/patch/stream.cpp rename to test/yycc/patch/stream.cpp diff --git a/testbench/yycc/rust/env.cpp b/test/yycc/rust/env.cpp similarity index 100% rename from testbench/yycc/rust/env.cpp rename to test/yycc/rust/env.cpp diff --git a/testbench/yycc/string/op.cpp b/test/yycc/string/op.cpp similarity index 100% rename from testbench/yycc/string/op.cpp rename to test/yycc/string/op.cpp diff --git a/testbench/yycc/string/reinterpret.cpp b/test/yycc/string/reinterpret.cpp similarity index 100% rename from testbench/yycc/string/reinterpret.cpp rename to test/yycc/string/reinterpret.cpp diff --git a/testbench/yycc/windows/com.cpp b/test/yycc/windows/com.cpp similarity index 100% rename from testbench/yycc/windows/com.cpp rename to test/yycc/windows/com.cpp diff --git a/testbench/yycc/windows/console.cpp b/test/yycc/windows/console.cpp similarity index 100% rename from testbench/yycc/windows/console.cpp rename to test/yycc/windows/console.cpp diff --git a/testbench/yycc/windows/dialog.cpp b/test/yycc/windows/dialog.cpp similarity index 100% rename from testbench/yycc/windows/dialog.cpp rename to test/yycc/windows/dialog.cpp diff --git a/testbench/yycc/windows/winfct.cpp b/test/yycc/windows/winfct.cpp similarity index 100% rename from testbench/yycc/windows/winfct.cpp rename to test/yycc/windows/winfct.cpp