xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
settings.h
Go to the documentation of this file.
1
4#pragma once
5#include "../tunit_export.h"
6#include <chrono>
7#include <cstdlib>
8#include <string>
9
11namespace xtd {
13 namespace tunit {
20 class tunit_export_ settings final {
21 public:
23 settings() = default;
24
26 settings(const settings&) = default;
27 settings& operator=(const settings&) = default;
29
33
36 bool also_run_ignored_tests() const noexcept {return also_run_ignored_tests_;}
37
40 void also_run_ignored_tests(bool also_run_ignored_tests) noexcept {also_run_ignored_tests_ = also_run_ignored_tests;}
41
46 int exit_status() const noexcept {return exit_status_;}
47
52 void exit_status(int exit_status) noexcept {exit_status_ = exit_status;}
53
57 const std::string& filter_tests() const noexcept {return filter_tests_;}
58
62 void filter_tests(const std::string& filter_tests) noexcept {filter_tests_ = filter_tests;}
63
66 bool is_match_test_name(const std::string& test_class_name, const std::string& test_name) const noexcept {return pattern_compare(test_class_name + "." + test_name, filter_tests_);}
67
70 bool list_tests() const noexcept {return list_tests_;}
71
74 void list_tests(bool list_tests) noexcept {list_tests_ = list_tests;}
75
78 bool output_color() const noexcept {return output_color_;}
79
82 void output_color(bool output_color) noexcept {output_color_ = output_color;}
83
86 bool output_xml() const noexcept {return output_xml_;}
87
90 void output_xml(bool output_xml) noexcept {output_xml_ = output_xml;}
91
94 std::string output_xml_path() const noexcept {return output_xml_path_;}
95
98 void output_xml_path(const std::string& output_xml_path) noexcept {output_xml_path_ = output_xml_path;}
99
103 bool shuffle_test() const noexcept {return shuffle_tests_;}
104
108 void shuffle_test(bool shuffle_test) noexcept {shuffle_tests_ = shuffle_test;}
109
113 int random_seed() const noexcept {return random_seed_;}
114
118 void random_seed(int random_seed) noexcept {random_seed_ = random_seed;}
119
123 int repeat_test() const noexcept {return repeat_tests_;}
124
128 void repeat_tests(int repeat_tests) noexcept {repeat_tests_ = repeat_tests;}
129
132 bool show_duration() const noexcept {return show_duration_;}
133
136 void show_duration(bool show_duration) noexcept {show_duration_ = show_duration;}
137
140 std::chrono::time_point<std::chrono::system_clock> end_time() const noexcept {return end_time_;}
141
144 std::chrono::time_point<std::chrono::system_clock> start_time() const noexcept {return start_time_;}
145
146 private:
147 friend class unit_test;
148
149 bool pattern_compare(const std::string& name, const std::string& pattern) const noexcept {
150 if (pattern == "") return name == "";
151 if (name == "") return false;
152 if (pattern == "*" || pattern == "*.*") return true;
153 if (pattern[0] == '*') return pattern_compare(name, pattern.substr(1)) || pattern_compare(name.substr(1), pattern);
154 return ((pattern[0] == '?') || (name[0] == pattern[0])) && pattern_compare(name.substr(1), pattern.substr(1));
155 }
156
157 void end_time(const std::chrono::time_point<std::chrono::system_clock>& end_time) noexcept {start_time_ = end_time;}
158 void start_time(const std::chrono::time_point<std::chrono::system_clock>& start_time) noexcept {start_time_ = start_time;}
159
160 bool also_run_ignored_tests_ = false;
161 std::string filter_tests_ = "*.*";
162 int exit_status_ = EXIT_SUCCESS;
163 bool list_tests_ = false;
164 bool output_color_ = true;
165 bool output_xml_;
166 std::string output_xml_path_ = "tests.xml";
167 bool show_duration_ = true;
168 bool shuffle_tests_ = false;
169 int random_seed_ = 0;
170 int repeat_tests_ = 1;
171 std::chrono::time_point<std::chrono::system_clock> start_time_;
172 std::chrono::time_point<std::chrono::system_clock> end_time_;
173 };
174 }
175}
The settings class contains xtd.tunit settings.
Definition: settings.h:20
void output_color(bool output_color) noexcept
Sets output color.
Definition: settings.h:82
std::string output_xml_path() const noexcept
Gets output xml path.
Definition: settings.h:94
int exit_status() const noexcept
Gets exit status.
Definition: settings.h:46
void random_seed(int random_seed) noexcept
Sets random seed value.
Definition: settings.h:118
std::chrono::time_point< std::chrono::system_clock > end_time() const noexcept
Gets unit test end time.
Definition: settings.h:140
void output_xml_path(const std::string &output_xml_path) noexcept
Sets output xml path.
Definition: settings.h:98
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:66
void list_tests(bool list_tests) noexcept
Sets list tests.
Definition: settings.h:74
void also_run_ignored_tests(bool also_run_ignored_tests) noexcept
Sets also run ignored test.
Definition: settings.h:40
bool shuffle_test() const noexcept
Gets shuffle tests.
Definition: settings.h:103
settings()=default
Creates new instance of settings.
void shuffle_test(bool shuffle_test) noexcept
Sets shuffle tests.
Definition: settings.h:108
bool output_xml() const noexcept
Gets output xml.
Definition: settings.h:86
void output_xml(bool output_xml) noexcept
Sets output xml.
Definition: settings.h:90
std::chrono::time_point< std::chrono::system_clock > start_time() const noexcept
Gets unit test start time.
Definition: settings.h:144
bool show_duration() const noexcept
Gets if show duration for each test.
Definition: settings.h:132
static xtd::tunit::settings & default_settings() noexcept
Get default settings instance.
bool output_color() const noexcept
Gets output color.
Definition: settings.h:78
void show_duration(bool show_duration) noexcept
Sets if show duration for each test.
Definition: settings.h:136
void repeat_tests(int repeat_tests) noexcept
Sets repeat tests count.
Definition: settings.h:128
const std::string & filter_tests() const noexcept
Gets filter tests.
Definition: settings.h:57
int random_seed() const noexcept
Gets random seed value.
Definition: settings.h:113
bool list_tests() const noexcept
Gets list tests.
Definition: settings.h:70
int repeat_test() const noexcept
Gets repeat tests count.
Definition: settings.h:123
void exit_status(int exit_status) noexcept
Sets exit status.
Definition: settings.h:52
void filter_tests(const std::string &filter_tests) noexcept
Sets filter tests.
Definition: settings.h:62
The template class.
Definition: unit_test.h:32
#define tunit_export_
Define shared library export.
Definition: tunit_export.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17