ExecutionModel.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_TESTING__TEST_RUNNER_EXECUTION_MODEL
18 #define COM_BORA_SOFTWARE__BALAU_TESTING__TEST_RUNNER_EXECUTION_MODEL
19 
21 #include <Balau/Util/Strings.hpp>
22 
23 namespace Balau::Testing {
24 
32 enum ExecutionModel : unsigned int {
42 
56 
70 
84 };
85 
91 template <typename AllocatorT>
93  switch (model) {
94  case SingleThreaded: return "SingleThreaded";
95  case WorkerThreads: return "WorkerThreads";
96  case WorkerProcesses: return "WorkerProcesses";
97  case ProcessPerTest: return "ProcessPerTest";
98  default: ThrowBalauException(Exception::BugException, "Unknown execution model: " + ::toString<AllocatorT>(static_cast<int>(model)));
99  }
100 }
101 
107 inline std::string toString(ExecutionModel model) {
108  switch (model) {
109  case SingleThreaded: return "SingleThreaded";
110  case WorkerThreads: return "WorkerThreads";
111  case WorkerProcesses: return "WorkerProcesses";
112  case ProcessPerTest: return "ProcessPerTest";
113  default: ThrowBalauException(Exception::BugException, "Unknown execution model: " + ::toString(static_cast<int>(model)));
114  }
115 }
116 
123 inline void fromString(ExecutionModel & model, const std::string & value) {
124  if (Util::Strings::equalsIgnoreCase(value, "SingleThreaded")) {
125  model = SingleThreaded;
126  } else if (Util::Strings::equalsIgnoreCase(value, "WorkerThreads")) {
127  model = WorkerThreads;
128  } else if (Util::Strings::equalsIgnoreCase(value, "WorkerProcesses")) {
129  model = WorkerProcesses;
130  } else if (Util::Strings::equalsIgnoreCase(value, "ProcessPerTest")) {
131  model = ProcessPerTest;
132  } else {
133  ThrowBalauException(Exception::CommandlineException, "Unknown execution model: " + value);
134  }
135 }
136 
140 inline bool isExecutionModel(std::string_view value) {
141  return Util::Strings::equalsIgnoreCase(value, "SingleThreaded")
142  || Util::Strings::equalsIgnoreCase(value, "WorkerThreads")
143  || Util::Strings::equalsIgnoreCase(value, "WorkerProcesses")
144  || Util::Strings::equalsIgnoreCase(value, "ProcessPerTest");
145 }
146 
147 } // namespace Balau::Testing
148 
149 #endif // COM_BORA_SOFTWARE__BALAU_TESTING__TEST_RUNNER_EXECUTION_MODEL
Run all tests in a single thread.
Definition: ExecutionModel.hpp:41
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
Base class of command line exception classes.
Definition: CommandLineExceptions.hpp:27
Run tests in a set of worker processes.
Definition: ExecutionModel.hpp:69
Thrown when a bug is encountered (mainly unimplemented switch cases).
Definition: BalauException.hpp:178
Utilities for strings.
Run all tests in a single process.
Definition: ExecutionModel.hpp:55
bool isExecutionModel(std::string_view value)
Returns true if the supplied string represents a valid execution model (the case is ignored)...
Definition: ExecutionModel.hpp:140
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
The test runner and test assertion functions.
Definition: Assertions.hpp:23
static bool equalsIgnoreCase(const StringT< CharT, T ... > &lhs, const SubstrT &rhs)
Ignoring case, is the first string equal to the second string?
Definition: Strings.hpp:272
ExecutionModel
The type of execution model to be used by the test runner.
Definition: ExecutionModel.hpp:32
void fromString(ExecutionModel &model, const std::string &value)
Obtain the execution model from a string.
Definition: ExecutionModel.hpp:123
Balau::U8String< AllocatorT > toString(ExecutionModel model)
Print the execution model value as a UTF-8 string.
Definition: ExecutionModel.hpp:92
Balau exceptions for the command line parser.
Run each test in a separate worker process.
Definition: ExecutionModel.hpp:83