From 9dbfc54b76c035df63db71fbb83b5a1f804fd09f Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 5 Nov 2023 12:20:24 +0100 Subject: [PATCH] refactor: move setup of chapter 2 tests out of main --- chapters/chapter_02/CMakeLists.txt | 1 + chapters/chapter_02/include/chapter_2_tests.h | 5 ++++ chapters/chapter_02/src/chapter_2_tests.cpp | 30 +++++++++++++++++++ .../chapter_02/{include => src}/constexp.h | 0 .../{include => src}/delegate_constructor.h | 0 .../{include => src}/if_constexpr.h | 0 .../chapter_02/{include => src}/ifswitch.h | 0 .../inheritance_constructor.h | 0 .../chapter_02/{include => src}/initlist.h | 0 chapters/chapter_02/{include => src}/null.h | 0 .../{include => src}/range_based_for.h | 0 .../{include => src}/structured_binding.h | 0 .../{include => src}/type_inference.h | 0 .../{include => src}/variadic_templates.h | 0 src/main.cpp | 28 ++--------------- 15 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 chapters/chapter_02/include/chapter_2_tests.h create mode 100644 chapters/chapter_02/src/chapter_2_tests.cpp rename chapters/chapter_02/{include => src}/constexp.h (100%) rename chapters/chapter_02/{include => src}/delegate_constructor.h (100%) rename chapters/chapter_02/{include => src}/if_constexpr.h (100%) rename chapters/chapter_02/{include => src}/ifswitch.h (100%) rename chapters/chapter_02/{include => src}/inheritance_constructor.h (100%) rename chapters/chapter_02/{include => src}/initlist.h (100%) rename chapters/chapter_02/{include => src}/null.h (100%) rename chapters/chapter_02/{include => src}/range_based_for.h (100%) rename chapters/chapter_02/{include => src}/structured_binding.h (100%) rename chapters/chapter_02/{include => src}/type_inference.h (100%) rename chapters/chapter_02/{include => src}/variadic_templates.h (100%) diff --git a/chapters/chapter_02/CMakeLists.txt b/chapters/chapter_02/CMakeLists.txt index 666d680..7134a18 100644 --- a/chapters/chapter_02/CMakeLists.txt +++ b/chapters/chapter_02/CMakeLists.txt @@ -1,5 +1,6 @@ add_library( chapter_02 + src/chapter_2_tests.cpp src/constexp.cpp src/if_constexpr.cpp src/ifswitch.cpp diff --git a/chapters/chapter_02/include/chapter_2_tests.h b/chapters/chapter_02/include/chapter_2_tests.h new file mode 100644 index 0000000..7e2c5e3 --- /dev/null +++ b/chapters/chapter_02/include/chapter_2_tests.h @@ -0,0 +1,5 @@ +#include "chapter_interface.h" +#include +#include + +std::vector> chapter_2_tests(); diff --git a/chapters/chapter_02/src/chapter_2_tests.cpp b/chapters/chapter_02/src/chapter_2_tests.cpp new file mode 100644 index 0000000..5b321a7 --- /dev/null +++ b/chapters/chapter_02/src/chapter_2_tests.cpp @@ -0,0 +1,30 @@ +#include "chapter_2_tests.h" +#include "constexp.h" +#include "delegate_constructor.h" +#include "if_constexpr.h" +#include "ifswitch.h" +#include "inheritance_constructor.h" +#include "initlist.h" +#include "null.h" +#include "range_based_for.h" +#include "structured_binding.h" +#include "type_inference.h" +#include "variadic_templates.h" + +std::vector> chapter_2_tests() { + std::vector> chapter_2_tests; + + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); + + return chapter_2_tests; +} diff --git a/chapters/chapter_02/include/constexp.h b/chapters/chapter_02/src/constexp.h similarity index 100% rename from chapters/chapter_02/include/constexp.h rename to chapters/chapter_02/src/constexp.h diff --git a/chapters/chapter_02/include/delegate_constructor.h b/chapters/chapter_02/src/delegate_constructor.h similarity index 100% rename from chapters/chapter_02/include/delegate_constructor.h rename to chapters/chapter_02/src/delegate_constructor.h diff --git a/chapters/chapter_02/include/if_constexpr.h b/chapters/chapter_02/src/if_constexpr.h similarity index 100% rename from chapters/chapter_02/include/if_constexpr.h rename to chapters/chapter_02/src/if_constexpr.h diff --git a/chapters/chapter_02/include/ifswitch.h b/chapters/chapter_02/src/ifswitch.h similarity index 100% rename from chapters/chapter_02/include/ifswitch.h rename to chapters/chapter_02/src/ifswitch.h diff --git a/chapters/chapter_02/include/inheritance_constructor.h b/chapters/chapter_02/src/inheritance_constructor.h similarity index 100% rename from chapters/chapter_02/include/inheritance_constructor.h rename to chapters/chapter_02/src/inheritance_constructor.h diff --git a/chapters/chapter_02/include/initlist.h b/chapters/chapter_02/src/initlist.h similarity index 100% rename from chapters/chapter_02/include/initlist.h rename to chapters/chapter_02/src/initlist.h diff --git a/chapters/chapter_02/include/null.h b/chapters/chapter_02/src/null.h similarity index 100% rename from chapters/chapter_02/include/null.h rename to chapters/chapter_02/src/null.h diff --git a/chapters/chapter_02/include/range_based_for.h b/chapters/chapter_02/src/range_based_for.h similarity index 100% rename from chapters/chapter_02/include/range_based_for.h rename to chapters/chapter_02/src/range_based_for.h diff --git a/chapters/chapter_02/include/structured_binding.h b/chapters/chapter_02/src/structured_binding.h similarity index 100% rename from chapters/chapter_02/include/structured_binding.h rename to chapters/chapter_02/src/structured_binding.h diff --git a/chapters/chapter_02/include/type_inference.h b/chapters/chapter_02/src/type_inference.h similarity index 100% rename from chapters/chapter_02/include/type_inference.h rename to chapters/chapter_02/src/type_inference.h diff --git a/chapters/chapter_02/include/variadic_templates.h b/chapters/chapter_02/src/variadic_templates.h similarity index 100% rename from chapters/chapter_02/include/variadic_templates.h rename to chapters/chapter_02/src/variadic_templates.h diff --git a/src/main.cpp b/src/main.cpp index ba15876..20929f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,17 +3,7 @@ #include #include -#include "constexp.h" -#include "delegate_constructor.h" -#include "if_constexpr.h" -#include "ifswitch.h" -#include "inheritance_constructor.h" -#include "initlist.h" -#include "null.h" -#include "range_based_for.h" -#include "structured_binding.h" -#include "type_inference.h" -#include "variadic_templates.h" +#include "chapter_2_tests.h" #include "version.h" int main(int argc, char **argv) { @@ -21,21 +11,7 @@ int main(int argc, char **argv) { std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << std::endl; - std::vector> chapter_2_tests; - - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - chapter_2_tests.emplace_back(std::make_unique()); - - for (auto &test : chapter_2_tests) { + for (auto &test : chapter_2_tests()) { std::cout << "\n" << test->name() << ":" << std::endl; test->run(); }