11#pragma once
2+ #include < map>
3+ #include < set>
24#include < iostream>
35#include < cassert>
46#include < sstream>
@@ -56,7 +58,13 @@ namespace kaguya_test_util
5658 typedef std::map<std::string, TestFunctionType> TestFunctionMapType;
5759
5860 TestFunctionMapType test_functions_;
61+
62+ std::vector<std::string> test_set_;
5963 public:
64+ void set_test_set (std::vector<std::string> container)
65+ {
66+ test_set_ = container;
67+ }
6068 static TestRunner& instance ()
6169 {
6270 static TestRunner ins;
@@ -66,6 +74,29 @@ namespace kaguya_test_util
6674 {
6775 throw std::runtime_error (std::string (message));
6876 }
77+ bool is_name_execute (const std::string& name)const
78+ {
79+ if (test_set_.empty ()) { return true ; }
80+ for (std::vector<std::string>::const_iterator it = test_set_.begin (); it != test_set_.end (); ++it)
81+ {
82+ if (name.find (*it) != std::string::npos)
83+ {
84+ return true ;
85+ }
86+ }
87+
88+ return false ;
89+ }
90+ TestFunctionMapType tests ()
91+ {
92+ TestFunctionMapType tests;
93+ for (TestFunctionMapType::const_iterator it = test_functions_.begin (); it != test_functions_.end (); ++it)
94+ {
95+ if (!is_name_execute (it->first )) { continue ; }
96+ tests.insert (*it);
97+ }
98+ return tests;
99+ }
69100
70101 void addTest (const std::string& name, TestFunctionType function)
71102 {
@@ -74,19 +105,21 @@ namespace kaguya_test_util
74105
75106 bool execute ()
76107 {
108+ TestFunctionMapType test_function = tests ();
77109 bool fail = false ;
78- size_t testcount = test_functions_ .size ();
110+ size_t testcount = test_function .size ();
79111 size_t testindex = 1 ;
80112
81113 std::vector<std::string> pass_tests;
82114 std::vector<std::string> fail_tests;
83- for (TestFunctionMapType::const_iterator it = test_functions_ .begin (); it != test_functions_ .end (); ++it, ++testindex)
115+ for (TestFunctionMapType::const_iterator it = test_function .begin (); it != test_function .end (); ++it, ++testindex)
84116 {
117+ const std::string& test_name = it->first ;
118+
85119 kaguya::State state;
86120
87121 state.setErrorHandler (test_error_handler);
88122
89- const std::string& test_name = it->first ;
90123
91124 std::cout << test_name << " (" << testindex << " /" << testcount << " ) ..." ;
92125
0 commit comments