tunit - Reference Guide  1.0.0
Modern c++17 unit testing framework on Windows, macOS, Linux, iOS and android.
settings.h
Go to the documentation of this file.
1 #pragma once
4 #include <chrono>
5 #include <cstdlib>
6 #include <string>
7 
9 namespace tunit {
11  class settings final {
12  public:
14  settings() = default;
15 
17  settings(const settings&) = default;
18  settings& operator=(const settings&) = default;
20 
23  static tunit::settings& default_settings() noexcept {
25  return settings;
26  }
27 
30  bool also_run_ignored_tests() const noexcept {return this->also_run_ignored_tests_;}
31 
34  void also_run_ignored_tests(bool also_run_ignored_tests) noexcept {this->also_run_ignored_tests_ = also_run_ignored_tests;}
35 
40  int exit_status() const noexcept {return this->exit_status_;}
41 
46  void exit_status(int exit_status) noexcept {this->exit_status_ = exit_status;}
47 
51  const std::string& filter_tests() const noexcept {return this->filter_tests_;}
52 
56  void filter_tests(const std::string& filter_tests) noexcept {this->filter_tests_ = filter_tests;}
57 
60  bool is_match_test_name(const std::string& test_class_name, const std::string& test_name) const noexcept {return this->pattern_compare(test_class_name + "." + test_name, this->filter_tests_);}
61 
64  bool list_tests() const noexcept {return this->list_tests_;}
65 
68  void list_tests(bool list_tests) noexcept {this->list_tests_ = list_tests;}
69 
72  bool output_color() const noexcept {return this->output_color_;}
73 
76  void output_color(bool output_color) noexcept {this->output_color_ = output_color;}
77 
80  bool output_xml() const noexcept {return this->output_xml_;}
81 
84  void output_xml(bool output_xml) noexcept {this->output_xml_ = output_xml;}
85 
88  std::string output_xml_path() const noexcept {return this->output_xml_path_;}
89 
92  void output_xml_path(const std::string& output_xml_path) noexcept {this->output_xml_path_ = output_xml_path;}
93 
97  bool shuffle_test() const noexcept {return this->shuffle_tests_;}
98 
102  void shuffle_test(bool shuffle_test) noexcept {this->shuffle_tests_ = shuffle_test;}
103 
107  int random_seed() const noexcept {return this->random_seed_;}
108 
112  void random_seed(int random_seed) noexcept {this->random_seed_ = random_seed;}
113 
117  int repeaat_test() const noexcept {return this->repeat_tests_;}
118 
122  void repeat_tests(int repeat_tests) noexcept {this->repeat_tests_ = repeat_tests;}
123 
126  bool show_duration() const noexcept {return this->show_duration_;}
127 
130  void show_duration(bool show_duration) noexcept {this->show_duration_ = show_duration;}
131 
134  std::chrono::time_point<std::chrono::system_clock> end_time() const noexcept {return this->end_time_;}
135 
138  std::chrono::time_point<std::chrono::system_clock> start_time() const noexcept {return this->start_time_;}
139 
140  private:
141  friend class unit_test;
142 
143  bool pattern_compare(const std::string& name, const std::string& pattern) const noexcept {
144  if (pattern == "") return name == "";
145  if (name == "") return false;
146  if (pattern == "*" || pattern == "*.*") return true;
147  if (pattern[0] == '*') return this->pattern_compare(name, pattern.substr(1)) || this->pattern_compare(name.substr(1), pattern);
148  return ((pattern[0] == '?') || (name[0] == pattern[0])) && this->pattern_compare(name.substr(1), pattern.substr(1));
149  }
150 
151  void end_time(const std::chrono::time_point<std::chrono::system_clock>& end_time) noexcept {this->start_time_ = end_time;}
152  void start_time(const std::chrono::time_point<std::chrono::system_clock>& start_time) noexcept {this->start_time_ = start_time;}
153 
154  bool also_run_ignored_tests_ = false;
155  std::string filter_tests_ = "*.*";
156  int exit_status_ = EXIT_SUCCESS;
157  bool list_tests_ = false;
158  bool output_color_ = true;
159  bool output_xml_;
160  std::string output_xml_path_ = "tests.xml";
161  bool show_duration_ = true;
162  bool shuffle_tests_ = false;
163  int random_seed_ = 0;
164  int repeat_tests_ = 1;
165  std::chrono::time_point<std::chrono::system_clock> start_time_;
166  std::chrono::time_point<std::chrono::system_clock> end_time_;
167  };
168 }
bool is_match_test_name(const std::string &test_class_name, const std::string &test_name) const noexcept
Return true if a specified test class name and specified test name match with the current filter test...
Definition: settings.h:60
int repeaat_test() const noexcept
Gets repeat tests count.
Definition: settings.h:117
static tunit::settings & default_settings() noexcept
Get default settings intance.
Definition: settings.h:23
settings()=default
Creates new instance of settings.
int exit_status() const noexcept
Gets exit status.
Definition: settings.h:40
std::chrono::time_point< std::chrono::system_clock > end_time() const noexcept
Gets unit test end time.
Definition: settings.h:134
void shuffle_test(bool shuffle_test) noexcept
Sets shuffle tests.
Definition: settings.h:102
The template class.
Definition: unit_test.h:23
void show_duration(bool show_duration) noexcept
Sets if show duration for each test.
Definition: settings.h:130
bool output_color() const noexcept
Gets output color.
Definition: settings.h:72
void repeat_tests(int repeat_tests) noexcept
Sets repeat tests count.
Definition: settings.h:122
std::chrono::time_point< std::chrono::system_clock > start_time() const noexcept
Gets unit test start time.
Definition: settings.h:138
bool also_run_ignored_tests() const noexcept
Gets also run ignored test.
Definition: settings.h:30
void output_xml_path(const std::string &output_xml_path) noexcept
Sets output xml path.
Definition: settings.h:92
void list_tests(bool list_tests) noexcept
Sets list tests.
Definition: settings.h:68
void output_color(bool output_color) noexcept
Sets output color.
Definition: settings.h:76
void output_xml(bool output_xml) noexcept
Sets output xml.
Definition: settings.h:84
bool output_xml() const noexcept
Gets output xml.
Definition: settings.h:80
The tunit namespace contains a unit test library.
Definition: abort_error.h:8
void also_run_ignored_tests(bool also_run_ignored_tests) noexcept
Sets also run ignored test.
Definition: settings.h:34
bool show_duration() const noexcept
Gets if show duration for each test.
Definition: settings.h:126
void exit_status(int exit_status) noexcept
Sets exit status.
Definition: settings.h:46
bool shuffle_test() const noexcept
Gets shuffle tests.
Definition: settings.h:97
std::string output_xml_path() const noexcept
Gets output xml path.
Definition: settings.h:88
The settings class contains tunit settings.
Definition: settings.h:11
void filter_tests(const std::string &filter_tests) noexcept
Sets filter tests.
Definition: settings.h:56
const std::string & filter_tests() const noexcept
Gets filter tests.
Definition: settings.h:51
int random_seed() const noexcept
Gets random seed value.
Definition: settings.h:107
void random_seed(int random_seed) noexcept
Sets random seed value.
Definition: settings.h:112
bool list_tests() const noexcept
Gets list tests.
Definition: settings.h:64