|
17 | 17 | #include <unordered_map> |
18 | 18 | #include <utility> |
19 | 19 | #include <vector> |
| 20 | +#include <cstdlib> |
20 | 21 | #include "GUnit/Detail/FileUtils.h" |
21 | 22 | #include "GUnit/Detail/Preprocessor.h" |
22 | 23 | #include "GUnit/Detail/RegexUtils.h" |
@@ -168,7 +169,8 @@ class Steps { |
168 | 169 | steps.Init(pickles, file); |
169 | 170 | static_cast<TCRTP&>(steps).Run(); |
170 | 171 | if (steps.current_step_ != steps.pickle_steps_.size()) { |
171 | | - throw StepIsNotImplemented{"STEP \"" + steps.not_found_ + "\" not implemented!"}; |
| 172 | + throw StepIsNotImplemented{"STEP \"" + steps.not_found_ + |
| 173 | + "\" not implemented!"}; |
172 | 174 | } |
173 | 175 | std::cout << '\n'; |
174 | 176 | } |
@@ -365,30 +367,40 @@ class Steps { |
365 | 367 | } |
366 | 368 |
|
367 | 369 | void ParseAndRegister(const std::string& name, const std::string& feature) { |
368 | | - const auto content = read_file(feature); |
369 | | - gherkin::parser parser{L"en"}; |
370 | | - gherkin::compiler compiler{feature}; |
371 | | - const auto gherkin_document = parser.parse(content); |
372 | | - const auto pickles = compiler.compile(gherkin_document); |
373 | | - const auto ast = nlohmann::json::parse(compiler.ast(gherkin_document)); |
374 | | - |
375 | | - for (const auto& pickle : pickles) { |
376 | | - const std::string feature_name = ast["document"]["feature"]["name"]; |
377 | | - const auto pickle_json = nlohmann::json::parse(pickle)["pickle"]; |
378 | | - const std::string scenario_name = pickle_json["name"]; |
379 | | - const auto tags = detail::make_tags(pickle_json["tags"]); |
380 | | - const auto disabled = tags.first ? "DISABLED_" : ""; |
381 | | - const auto full_name = feature_name + "." + scenario_name; |
382 | | - |
383 | | - if (PatternMatchesString(name.c_str(), full_name.c_str())) { |
384 | | - info_.feature = feature_name; |
385 | | - |
386 | | - detail::MakeAndRegisterTestInfo( |
387 | | - new TestFactory{*this, pickle, feature}, |
388 | | - disabled + feature_name + tags.second, scenario_name, __FILE__, |
389 | | - __LINE__, |
390 | | - detail::type<decltype(internal::MakeAndRegisterTestInfo)>{}); |
| 370 | + try { |
| 371 | + const auto content = read_file(feature); |
| 372 | + gherkin::parser parser{L"en"}; |
| 373 | + gherkin::compiler compiler{feature}; |
| 374 | + const auto gherkin_document = parser.parse(content); |
| 375 | + const auto pickles = compiler.compile(gherkin_document); |
| 376 | + const auto ast = nlohmann::json::parse(compiler.ast(gherkin_document)); |
| 377 | + |
| 378 | + for (const auto& pickle : pickles) { |
| 379 | + const std::string feature_name = ast["document"]["feature"]["name"]; |
| 380 | + const auto pickle_json = nlohmann::json::parse(pickle)["pickle"]; |
| 381 | + const std::string scenario_name = pickle_json["name"]; |
| 382 | + const auto tags = detail::make_tags(pickle_json["tags"]); |
| 383 | + const auto disabled = tags.first ? "DISABLED_" : ""; |
| 384 | + const auto full_name = feature_name + "." + scenario_name; |
| 385 | + |
| 386 | + if (PatternMatchesString(name.c_str(), full_name.c_str())) { |
| 387 | + info_.feature = feature_name; |
| 388 | + |
| 389 | + detail::MakeAndRegisterTestInfo( |
| 390 | + new TestFactory{*this, pickle, feature}, |
| 391 | + disabled + feature_name + tags.second, scenario_name, __FILE__, |
| 392 | + __LINE__, |
| 393 | + detail::type<decltype(internal::MakeAndRegisterTestInfo)>{}); |
| 394 | + } |
391 | 395 | } |
| 396 | + } catch (const gherkin::v1::parsing_error& err) { |
| 397 | + const auto err_json = nlohmann::json::parse(err.what()); |
| 398 | + const auto line = err_json["source"]["start"]["line"]; |
| 399 | + const auto column = err_json["source"]["start"]["column"]; |
| 400 | + const std::string error = err_json["data"]; |
| 401 | + |
| 402 | + std::cerr << feature << ":" << line << ":" << column << ": error: " << error << std::endl; |
| 403 | + std::exit(-1); |
392 | 404 | } |
393 | 405 | } |
394 | 406 |
|
|
0 commit comments