refactor: move test name into test class
This commit is contained in:
parent
543b4b832a
commit
3c193fc47b
@ -5,4 +5,5 @@
|
|||||||
class ConstExpTest : public ChapterTest {
|
class ConstExpTest : public ChapterTest {
|
||||||
public:
|
public:
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
virtual const char *name() const override { return "Constexpr test"; }
|
||||||
};
|
};
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
class IfswitchTest : public ChapterTest {
|
class IfswitchTest : public ChapterTest {
|
||||||
public:
|
public:
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
virtual const char *name() const override { return "If/switch test"; }
|
||||||
};
|
};
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
class InitListTest : public ChapterTest {
|
class InitListTest : public ChapterTest {
|
||||||
public:
|
public:
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
virtual const char *name() const override { return "Initializer list test"; }
|
||||||
};
|
};
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
class NullTest : public ChapterTest {
|
class NullTest : public ChapterTest {
|
||||||
public:
|
public:
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
virtual const char *name() const override { return "Nullptr test"; }
|
||||||
};
|
};
|
||||||
|
@ -5,4 +5,7 @@
|
|||||||
class StructuredBindingTest : public ChapterTest {
|
class StructuredBindingTest : public ChapterTest {
|
||||||
public:
|
public:
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
virtual const char *name() const override {
|
||||||
|
return "Structured binding test";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,4 +4,5 @@ class ChapterTest {
|
|||||||
public:
|
public:
|
||||||
virtual ~ChapterTest() = default;
|
virtual ~ChapterTest() = default;
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
virtual const char *name() const = 0;
|
||||||
};
|
};
|
||||||
|
23
src/main.cpp
23
src/main.cpp
@ -12,24 +12,19 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n"
|
std::cout << "Running " << PROJECT_NAME << ", version " << VERSION
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
std::vector<std::tuple<const char *, std::unique_ptr<ChapterTest>>>
|
std::vector<std::unique_ptr<ChapterTest>> chapter_2_tests;
|
||||||
chapter_2_tests;
|
|
||||||
|
|
||||||
chapter_2_tests.emplace_back("Nullptr test", std::make_unique<NullTest>());
|
chapter_2_tests.emplace_back(std::make_unique<NullTest>());
|
||||||
chapter_2_tests.emplace_back("If/Switch test",
|
chapter_2_tests.emplace_back(std::make_unique<IfswitchTest>());
|
||||||
std::make_unique<IfswitchTest>());
|
chapter_2_tests.emplace_back(std::make_unique<ConstExpTest>());
|
||||||
chapter_2_tests.emplace_back("Constexpr test",
|
chapter_2_tests.emplace_back(std::make_unique<InitListTest>());
|
||||||
std::make_unique<ConstExpTest>());
|
chapter_2_tests.emplace_back(std::make_unique<StructuredBindingTest>());
|
||||||
chapter_2_tests.emplace_back("Initializer list test",
|
|
||||||
std::make_unique<InitListTest>());
|
|
||||||
chapter_2_tests.emplace_back("Structured binding test",
|
|
||||||
std::make_unique<StructuredBindingTest>());
|
|
||||||
|
|
||||||
for (auto &[test_description, test] : chapter_2_tests) {
|
for (auto &test : chapter_2_tests) {
|
||||||
std::cout << "\n" << test_description << ":" << std::endl;
|
std::cout << "\n" << test->name() << ":" << std::endl;
|
||||||
test->run();
|
test->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user