refactor: move setup of chapter 2 tests out of main

This commit is contained in:
Michael Mandl 2023-11-05 12:20:24 +01:00
parent a3c2e3728c
commit 9dbfc54b76
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
15 changed files with 38 additions and 26 deletions

View file

@ -1,5 +1,6 @@
add_library(
chapter_02
src/chapter_2_tests.cpp
src/constexp.cpp
src/if_constexpr.cpp
src/ifswitch.cpp

View file

@ -0,0 +1,5 @@
#include "chapter_interface.h"
#include <memory>
#include <vector>
std::vector<std::unique_ptr<ChapterTest>> chapter_2_tests();

View file

@ -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<std::unique_ptr<ChapterTest>> chapter_2_tests() {
std::vector<std::unique_ptr<ChapterTest>> chapter_2_tests;
chapter_2_tests.emplace_back(std::make_unique<NullTest>());
chapter_2_tests.emplace_back(std::make_unique<IfswitchTest>());
chapter_2_tests.emplace_back(std::make_unique<ConstExpTest>());
chapter_2_tests.emplace_back(std::make_unique<InitListTest>());
chapter_2_tests.emplace_back(std::make_unique<StructuredBindingTest>());
chapter_2_tests.emplace_back(std::make_unique<TypeInferenceTest>());
chapter_2_tests.emplace_back(std::make_unique<IfConstexprTest>());
chapter_2_tests.emplace_back(std::make_unique<RangeBasedForTest>());
chapter_2_tests.emplace_back(std::make_unique<VariadicTemplates>());
chapter_2_tests.emplace_back(std::make_unique<DelegateConstructor>());
chapter_2_tests.emplace_back(std::make_unique<InheritanceConstructor>());
return chapter_2_tests;
}

View file

@ -3,17 +3,7 @@
#include <memory>
#include <vector>
#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<std::unique_ptr<ChapterTest>> chapter_2_tests;
chapter_2_tests.emplace_back(std::make_unique<NullTest>());
chapter_2_tests.emplace_back(std::make_unique<IfswitchTest>());
chapter_2_tests.emplace_back(std::make_unique<ConstExpTest>());
chapter_2_tests.emplace_back(std::make_unique<InitListTest>());
chapter_2_tests.emplace_back(std::make_unique<StructuredBindingTest>());
chapter_2_tests.emplace_back(std::make_unique<TypeInferenceTest>());
chapter_2_tests.emplace_back(std::make_unique<IfConstexprTest>());
chapter_2_tests.emplace_back(std::make_unique<RangeBasedForTest>());
chapter_2_tests.emplace_back(std::make_unique<VariadicTemplates>());
chapter_2_tests.emplace_back(std::make_unique<DelegateConstructor>());
chapter_2_tests.emplace_back(std::make_unique<InheritanceConstructor>());
for (auto &test : chapter_2_tests) {
for (auto &test : chapter_2_tests()) {
std::cout << "\n" << test->name() << ":" << std::endl;
test->run();
}