|
1 | 1 | #include "cucumber_cpp/library/Application.hpp" |
2 | 2 | #include "cucumber_cpp/library/Context.hpp" |
| 3 | +#include "cucumber_cpp/library/InternalError.hpp" |
3 | 4 | #include "cucumber_cpp/library/StepRegistry.hpp" |
| 5 | +#include "cucumber_cpp/library/cucumber_expression/Errors.hpp" |
4 | 6 | #include "cucumber_cpp/library/engine/ContextManager.hpp" |
5 | 7 | #include "cucumber_cpp/library/engine/FeatureFactory.hpp" |
6 | 8 | #include "cucumber_cpp/library/engine/FeatureInfo.hpp" |
|
17 | 19 | #include <CLI/impl/App_inl.hpp> |
18 | 20 | #include <CLI/impl/Option_inl.hpp> |
19 | 21 | #include <algorithm> |
| 22 | +#include <exception> |
20 | 23 | #include <filesystem> |
| 24 | +#include <format> |
21 | 25 | #include <functional> |
22 | 26 | #include <iostream> |
23 | 27 | #include <iterator> |
@@ -139,7 +143,14 @@ namespace cucumber_cpp::library |
139 | 143 |
|
140 | 144 | runCommand = cli.add_subcommand("run")->parse_complete_callback([this] |
141 | 145 | { |
142 | | - RunFeatures(); |
| 146 | + try |
| 147 | + { |
| 148 | + RunFeatures(); |
| 149 | + } |
| 150 | + catch (std::exception& error) |
| 151 | + { |
| 152 | + std::cerr << error.what(); |
| 153 | + } |
143 | 154 | }); |
144 | 155 |
|
145 | 156 | runCommand->add_option("-t,--tag", options.tags, "Cucumber tag expression"); |
@@ -170,6 +181,24 @@ namespace cucumber_cpp::library |
170 | 181 | { |
171 | 182 | return cli.exit(e); |
172 | 183 | } |
| 184 | + catch (const InternalError& error) |
| 185 | + { |
| 186 | + std::cout << "Internal error:\n\n"; |
| 187 | + std::cout << error.what() << std::endl; |
| 188 | + return GetExitCode(engine::Result::failed); |
| 189 | + } |
| 190 | + catch (const cucumber_expression::Error& error) |
| 191 | + { |
| 192 | + std::cout << "Cucumber Expression error:\n\n"; |
| 193 | + std::cout << error.what() << std::endl; |
| 194 | + return GetExitCode(engine::Result::failed); |
| 195 | + } |
| 196 | + catch (const std::exception& error) |
| 197 | + { |
| 198 | + std::cout << "Generic error:\n\n"; |
| 199 | + std::cout << error.what() << std::endl; |
| 200 | + return GetExitCode(engine::Result::failed); |
| 201 | + } |
173 | 202 |
|
174 | 203 | return GetExitCode(); |
175 | 204 | } |
@@ -227,8 +256,11 @@ namespace cucumber_cpp::library |
227 | 256 |
|
228 | 257 | int Application::GetExitCode() const |
229 | 258 | { |
230 | | - const auto result = static_cast<std::underlying_type_t<engine::Result>>(contextManager.ProgramContext().ExecutionStatus()); |
231 | | - return result - static_cast<std::underlying_type_t<engine::Result>>(engine::Result::passed); |
| 259 | + return GetExitCode(contextManager.ProgramContext().ExecutionStatus()); |
232 | 260 | } |
233 | 261 |
|
| 262 | + int Application::GetExitCode(engine::Result result) const |
| 263 | + { |
| 264 | + return static_cast<std::underlying_type_t<engine::Result>>(result) - static_cast<std::underlying_type_t<engine::Result>>(engine::Result::passed); |
| 265 | + } |
234 | 266 | } |
0 commit comments