From f8af3f786bfd672acdd8408d37ed16608b93cd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Sun, 17 Dec 2023 20:05:42 +0100 Subject: [PATCH 1/3] adjust clang-format file to mostly used style --- .clang-format | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index 5b6e7ada..21f29137 100644 --- a/.clang-format +++ b/.clang-format @@ -1,15 +1,18 @@ --- -Language: Cpp +Language: Cpp AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent AlignEscapedNewlinesLeft: true -AllowShortFunctionsOnASingleLine: Empty +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false BreakBeforeBinaryOperators: All BreakBeforeBraces: Attach -ColumnLimit: 100 -ConstructorInitializerAllOnOneLineOrOnePerLine: true +BreakConstructorInitializers: AfterColon +ColumnLimit: 100 +FixNamespaceComments: true IncludeCategories: # The autodetect header should always be included last - Regex: '^$' @@ -18,14 +21,19 @@ IncludeCategories: Priority: 1 - Regex: '.*' Priority: 2 -IndentWidth: 4 +IndentPPDirectives: BeforeHash +IndentWidth: 4 NamespaceIndentation: None +PackConstructorInitializers: Never PenaltyBreakString: 1000 PenaltyExcessCharacter: 10000 +PenaltyReturnTypeOnItsOwnLine: 1000 PointerAlignment: Left -SortIncludes: false +ShortNamespaceLines: 200 +SortIncludes: false +SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements -Standard: Cpp03 +Standard: Cpp11 ... From 4e60652b97c98b9b929e0fb6396f3d74ae39e211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Sun, 17 Dec 2023 22:11:25 +0100 Subject: [PATCH 2/3] auto format all files --- examples/Calc/src/Calculator.cpp | 5 +- .../step_definitions/CalculatorQtSteps.cpp | 23 +- examples/CalcQt/src/CalcQt.cpp | 2 +- examples/CalcQt/src/CalculatorWidget.cpp | 51 +-- .../features/step_definitions/TableSteps.cpp | 9 +- .../features/step_definitions/TagSteps.cpp | 11 +- .../step_definitions/RpnCalculatorSteps.cpp | 29 +- features/support/HelperFunctions.hpp | 35 +- features/support/RpnCalculator.cpp | 1 - include/cucumber-cpp/defs.hpp | 4 +- .../cucumber-cpp/internal/ContextManager.hpp | 15 +- .../cucumber-cpp/internal/CukeCommands.hpp | 10 +- include/cucumber-cpp/internal/CukeEngine.hpp | 28 +- .../cucumber-cpp/internal/CukeEngineImpl.hpp | 14 +- .../internal/RegistrationMacros.hpp | 38 +-- include/cucumber-cpp/internal/Scenario.hpp | 3 +- include/cucumber-cpp/internal/Table.hpp | 9 +- .../connectors/wire/ProtocolHandler.hpp | 2 +- .../internal/connectors/wire/WireProtocol.hpp | 22 +- .../connectors/wire/WireProtocolCommands.hpp | 22 +- .../internal/connectors/wire/WireServer.hpp | 42 +-- .../internal/drivers/QtTestDriver.hpp | 8 +- .../cucumber-cpp/internal/hook/HookMacros.hpp | 168 +++++----- .../internal/hook/HookRegistrar.hpp | 101 +++--- include/cucumber-cpp/internal/hook/Tag.hpp | 16 +- .../cucumber-cpp/internal/step/StepMacros.hpp | 34 +- .../internal/step/StepManager.hpp | 98 +++--- .../internal/utils/IndexSequence.hpp | 48 ++- include/cucumber-cpp/internal/utils/Regex.hpp | 13 +- src/ContextManager.cpp | 1 - src/CukeCommands.cpp | 37 ++- src/CukeEngine.cpp | 25 +- src/CukeEngineImpl.cpp | 46 +-- src/HookRegistrar.cpp | 43 ++- src/Regex.cpp | 17 +- src/Scenario.cpp | 6 +- src/StepManager.cpp | 44 ++- src/Table.cpp | 6 +- src/Tag.cpp | 26 +- src/connectors/wire/WireProtocol.cpp | 309 +++++++++--------- src/connectors/wire/WireProtocolCommands.cpp | 24 +- src/connectors/wire/WireServer.cpp | 27 +- src/drivers/BoostDriver.cpp | 66 ++-- src/drivers/GTestDriver.cpp | 6 +- src/drivers/QtTestDriver.cpp | 10 +- src/main.cpp | 35 +- tests/integration/ContextHandlingTest.cpp | 5 +- tests/integration/HookRegistrationTest.cpp | 81 +++-- tests/integration/StepRegistrationTest.cpp | 17 +- .../TaggedHookRegistrationTest.cpp | 52 ++- tests/integration/WireProtocolTest.cpp | 182 ++++++----- tests/integration/WireServerTest.cpp | 45 +-- tests/integration/drivers/BoostDriverTest.cpp | 20 +- tests/integration/drivers/GTestDriverTest.cpp | 6 +- .../integration/drivers/QtTestDriverTest.cpp | 5 +- tests/unit/ContextManagerTest.cpp | 7 +- tests/unit/CukeCommandsTest.cpp | 26 +- tests/unit/RegexTest.cpp | 3 +- tests/unit/StepCallChainTest.cpp | 48 +-- tests/unit/StepManagerTest.cpp | 37 ++- tests/unit/TableTest.cpp | 34 +- tests/unit/TagTest.cpp | 1 - tests/utils/CukeCommandsFixture.hpp | 10 +- tests/utils/DriverTestRunner.hpp | 38 ++- tests/utils/HookRegistrationFixture.hpp | 22 +- tests/utils/StepManagerTestDouble.hpp | 50 ++- 66 files changed, 1221 insertions(+), 1057 deletions(-) diff --git a/examples/Calc/src/Calculator.cpp b/examples/Calc/src/Calculator.cpp index 704b476b..292f7e8e 100644 --- a/examples/Calc/src/Calculator.cpp +++ b/examples/Calc/src/Calculator.cpp @@ -7,7 +7,7 @@ void Calculator::push(double n) { double Calculator::add() { double result = 0; - for(std::list::const_iterator i = values.begin(); i != values.end(); ++i) { + for (std::list::const_iterator i = values.begin(); i != values.end(); ++i) { result += *i; } return result; @@ -15,7 +15,7 @@ double Calculator::add() { double Calculator::divide() { double result = std::numeric_limits::quiet_NaN(); - for(std::list::const_iterator i = values.begin(); i != values.end(); ++i) { + for (std::list::const_iterator i = values.begin(); i != values.end(); ++i) { if (i == values.begin()) { result = *i; } else { @@ -24,4 +24,3 @@ double Calculator::divide() { } return result; } - diff --git a/examples/CalcQt/features/step_definitions/CalculatorQtSteps.cpp b/examples/CalcQt/features/step_definitions/CalculatorQtSteps.cpp index 33fcf4ad..f7cda931 100644 --- a/examples/CalcQt/features/step_definitions/CalculatorQtSteps.cpp +++ b/examples/CalcQt/features/step_definitions/CalculatorQtSteps.cpp @@ -8,10 +8,10 @@ /// Helper class to ensure that QApplication gets destroyed before main() returns /// and that CalculatorWidget gets destroyed before QApplication gets destroyed. struct CalculatorCtx { - CalculatorCtx() - : argc(0) - , app(argc, NULL) - {} + CalculatorCtx() : + argc(0), + app(argc, NULL) { + } int argc; QApplication app; @@ -21,16 +21,23 @@ struct CalculatorCtx { static int milliseconds = -1; int millisecondsToWait() { - if (milliseconds < 0) - { + if (milliseconds < 0) { char* envVariable = getenv("CALCQT_STEP_DELAY"); milliseconds = (0 != envVariable) ? atoi(envVariable) : 0; } return milliseconds; } -std::istream& operator>> (std::istream& in, QString& val) { std::string s; in >> s; val = s.c_str(); return in; } -std::ostream& operator<< (std::ostream& out, const QString& val) { out << val.toLatin1().data(); return out; } +std::istream& operator>>(std::istream& in, QString& val) { + std::string s; + in >> s; + val = s.c_str(); + return in; +} +std::ostream& operator<<(std::ostream& out, const QString& val) { + out << val.toLatin1().data(); + return out; +} GIVEN("^I just turned on the calculator$") { cucumber::ScenarioScope ctx; diff --git a/examples/CalcQt/src/CalcQt.cpp b/examples/CalcQt/src/CalcQt.cpp index b8fb8398..42552ee4 100644 --- a/examples/CalcQt/src/CalcQt.cpp +++ b/examples/CalcQt/src/CalcQt.cpp @@ -2,7 +2,7 @@ #include "CalculatorWidget.h" -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { QApplication app(argc, argv); app.setApplicationName("Qt Calculator"); CalculatorWidget widget; diff --git a/examples/CalcQt/src/CalculatorWidget.cpp b/examples/CalcQt/src/CalculatorWidget.cpp index e25c9642..3d559351 100644 --- a/examples/CalcQt/src/CalculatorWidget.cpp +++ b/examples/CalcQt/src/CalculatorWidget.cpp @@ -6,8 +6,9 @@ #include #include -CalculatorWidget::CalculatorWidget(QWidget *parent) : QWidget(parent) { - QGridLayout *layout = new QGridLayout(this); +CalculatorWidget::CalculatorWidget(QWidget* parent) : + QWidget(parent) { + QGridLayout* layout = new QGridLayout(this); layout->setSizeConstraint(QLayout::SetFixedSize); setLayout(layout); @@ -24,16 +25,16 @@ CalculatorWidget::CalculatorWidget(QWidget *parent) : QWidget(parent) { displayLabel->setSizePolicy(policy); signalMapper = new QSignalMapper(this); - QPushButton *button = new QPushButton(QString::number(0), this); + QPushButton* button = new QPushButton(QString::number(0), this); QObject::connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); signalMapper->setMapping(button, 0); layout->addWidget(button, 4, 1); digitButtons.push_back(button); for (unsigned int i = 1; i < 10; ++i) { - QPushButton *button = new QPushButton(QString::number(i), this); + QPushButton* button = new QPushButton(QString::number(i), this); QObject::connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); signalMapper->setMapping(button, i); - layout->addWidget(button, 1+(9-i)/3, (i-1)%3); + layout->addWidget(button, 1 + (9 - i) / 3, (i - 1) % 3); digitButtons.push_back(button); } QObject::connect(signalMapper, SIGNAL(mapped(int)), SLOT(buttonClicked(int))); @@ -63,8 +64,12 @@ int CalculatorWidget::calculate(const QString& expression) { while ((pos = regexp.indexIn(expression, pos)) != -1) { int value = regexp.cap(1).toInt(); switch (operation) { - case '+': result += value; break; - case '-': result -= value; break; + case '+': + result += value; + break; + case '-': + result -= value; + break; } pos += regexp.matchedLength(); if (pos < expression.length()) { @@ -78,21 +83,27 @@ QString CalculatorWidget::display() { return displayLabel->text(); } -void CalculatorWidget::keyPressEvent(QKeyEvent *event) { +void CalculatorWidget::keyPressEvent(QKeyEvent* event) { keyclickedButton = 0; int key = event->key(); if (key >= Qt::Key_0 && key <= Qt::Key_9) { keyclickedButton = digitButtons[key - Qt::Key_0]; - } - else { - switch(key) - { - case Qt::Key_Plus: keyclickedButton = additionButton; break; - case Qt::Key_Minus: keyclickedButton = subtractionButton; break; + } else { + switch (key) { + case Qt::Key_Plus: + keyclickedButton = additionButton; + break; + case Qt::Key_Minus: + keyclickedButton = subtractionButton; + break; case Qt::Key_Return: case Qt::Key_Enter: - case Qt::Key_Equal: keyclickedButton = calculateButton; break; - case Qt::Key_Escape: keyclickedButton = clearButton; break; + case Qt::Key_Equal: + keyclickedButton = calculateButton; + break; + case Qt::Key_Escape: + keyclickedButton = clearButton; + break; } } if (0 != keyclickedButton) { @@ -101,7 +112,7 @@ void CalculatorWidget::keyPressEvent(QKeyEvent *event) { } } -void CalculatorWidget::keyReleaseEvent(QKeyEvent *event) { +void CalculatorWidget::keyReleaseEvent(QKeyEvent* event) { Q_UNUSED(event) if (0 != keyclickedButton) { keyclickedButton->setDown(false); @@ -110,11 +121,11 @@ void CalculatorWidget::keyReleaseEvent(QKeyEvent *event) { } void CalculatorWidget::addButtonClicked() { - displayLabel->setText(displayLabel->text()+"+"); + displayLabel->setText(displayLabel->text() + "+"); } void CalculatorWidget::buttonClicked(int index) { - displayLabel->setText(displayLabel->text()+QString::number(index)); + displayLabel->setText(displayLabel->text() + QString::number(index)); } void CalculatorWidget::calculateButtonClicked() { @@ -126,5 +137,5 @@ void CalculatorWidget::clearButtonClicked() { } void CalculatorWidget::subtractButtonClicked() { - displayLabel->setText(displayLabel->text()+"-"); + displayLabel->setText(displayLabel->text() + "-"); } diff --git a/examples/FeatureShowcase/features/step_definitions/TableSteps.cpp b/examples/FeatureShowcase/features/step_definitions/TableSteps.cpp index 7265ecc4..1eb4c85a 100644 --- a/examples/FeatureShowcase/features/step_definitions/TableSteps.cpp +++ b/examples/FeatureShowcase/features/step_definitions/TableSteps.cpp @@ -10,10 +10,12 @@ class ActiveActors { public: typedef std::string actor_name_type; typedef unsigned short actor_year_type; + private: typedef std::map actors_type; actors_type actors; + public: void addActor(const actor_name_type name, const actor_year_type year) { actors[name] = year; @@ -27,7 +29,7 @@ class ActiveActors { actors_type::iterator it = actors.begin(); actor_name_type name = it->first; actor_year_type year = it->second; - while(++it != actors.end()) { + while (++it != actors.end()) { actor_year_type currentYear = it->second; if (year > currentYear) { name = it->first; @@ -41,11 +43,12 @@ GIVEN("^the following actors are still active") { TABLE_PARAM(actorsParam); ScenarioScope context; - const table_hashes_type & actors = actorsParam.hashes(); + const table_hashes_type& actors = actorsParam.hashes(); for (table_hashes_type::const_iterator ait = actors.begin(); ait != actors.end(); ++ait) { std::string name(ait->at("name")); std::string yearString(ait->at("born")); - const ActiveActors::actor_year_type year = ::cucumber::internal::fromString(yearString); + const ActiveActors::actor_year_type year + = ::cucumber::internal::fromString(yearString); context->addActor(name, year); } } diff --git a/examples/FeatureShowcase/features/step_definitions/TagSteps.cpp b/examples/FeatureShowcase/features/step_definitions/TagSteps.cpp index e4c8e996..69fa89a1 100644 --- a/examples/FeatureShowcase/features/step_definitions/TagSteps.cpp +++ b/examples/FeatureShowcase/features/step_definitions/TagSteps.cpp @@ -3,17 +3,15 @@ #include -using std::string; using std::cout; using std::endl; +using std::string; -BEFORE_ALL() -{ +BEFORE_ALL() { cout << "-------------------- (Before all scenarios)" << endl; } -AFTER_ALL() -{ +AFTER_ALL() { cout << "-------------------- (After all scenarios)" << endl; } @@ -21,7 +19,7 @@ BEFORE() { cout << "-------------------- (Before any scenario)" << endl; } -BEFORE("@foo,@bar","@baz") { +BEFORE("@foo,@bar", "@baz") { cout << "Before scenario (\"@foo,@baz\",\"@bar\")" << endl; } @@ -43,7 +41,6 @@ AFTER("@gherkin") { cout << "After scenario (\"@gherkin\")" << endl; } - /* * CUKE_STEP_ is used just because the feature does not convey any * business value. It should NEVER be used in real step definitions! diff --git a/features/step_definitions/RpnCalculatorSteps.cpp b/features/step_definitions/RpnCalculatorSteps.cpp index fed2f651..688b7801 100644 --- a/features/step_definitions/RpnCalculatorSteps.cpp +++ b/features/step_definitions/RpnCalculatorSteps.cpp @@ -3,27 +3,27 @@ #include #include -using std::string; using cucumber::ScenarioScope; +using std::string; namespace { - bool isCloseEnough(double value, double expected) { - return (std::abs(value - expected) > 0.00001); - } +bool isCloseEnough(double value, double expected) { + return (std::abs(value - expected) > 0.00001); +} - void verifyEqual(double value, double expected) { - if (isCloseEnough(value, expected)) { - throw (boost::format("Value %1% not equal to %2%") % value % expected).str(); - } +void verifyEqual(double value, double expected) { + if (isCloseEnough(value, expected)) { + throw(boost::format("Value %1% not equal to %2%") % value % expected).str(); } +} - void verifyNotEqual(double value, double expected) { - if (!isCloseEnough(value, expected)) { - throw (boost::format("Value %1% equal to %2%") % value % expected).str(); - } +void verifyNotEqual(double value, double expected) { + if (!isCloseEnough(value, expected)) { + throw(boost::format("Value %1% equal to %2%") % value % expected).str(); } } +} GIVEN("^a calculator") { // nothing to do @@ -72,9 +72,9 @@ WHEN("^the calculator adds up the following numbers:$") { ScenarioScope calc; vector numbers; - boost::split(numbers, numberString,boost::is_any_of("\n")); + boost::split(numbers, numberString, boost::is_any_of("\n")); - for (size_t i=0; i < numbers.size(); ++i) { + for (size_t i = 0; i < numbers.size(); ++i) { calc->push(numbers[i]); if (i != 0) { calc->push("+"); @@ -100,4 +100,3 @@ THEN("^the calculator does not return ([\\d\\.]+)$") { ScenarioScope calc; verifyNotEqual(calc->value(), expected); } - diff --git a/features/support/HelperFunctions.hpp b/features/support/HelperFunctions.hpp index bf1cd2f4..59dcb4f2 100644 --- a/features/support/HelperFunctions.hpp +++ b/features/support/HelperFunctions.hpp @@ -4,25 +4,25 @@ #include #include -template -void writeToFile(const char *filename, T content) { - using namespace::std; - ofstream file; - file.open(filename, ios::out | ios::trunc); - file << content; - file.close(); +template +void writeToFile(const char* filename, T content) { + using namespace ::std; + ofstream file; + file.open(filename, ios::out | ios::trunc); + file << content; + file.close(); } -void logCycleEvent(const char *name, const char *log, const char *separator) { - using namespace::std; - ofstream file; - file.open(log, ios::out | ios::app); - file << separator << name; - file.close(); +void logCycleEvent(const char* name, const char* log, const char* separator) { + using namespace ::std; + ofstream file; + file.open(log, ios::out | ios::app); + file << separator << name; + file.close(); } -void logTableAsHashes(const cucumber::internal::Table & table, const char *log) { - using namespace::std; +void logTableAsHashes(const cucumber::internal::Table& table, const char* log) { + using namespace ::std; typedef cucumber::internal::Table::hashes_type hashes_type; typedef cucumber::internal::Table::hash_row_type hash_row_type; @@ -30,7 +30,7 @@ void logTableAsHashes(const cucumber::internal::Table & table, const char *log) file.open(log, ios::out | ios::trunc); file << "["; - const hashes_type & hashes = table.hashes(); + const hashes_type& hashes = table.hashes(); for (hashes_type::const_iterator tit = hashes.begin(); tit != hashes.end(); ++tit) { if (tit != hashes.begin()) { file << ","; @@ -42,11 +42,10 @@ void logTableAsHashes(const cucumber::internal::Table & table, const char *log) } file << "\"" << rit->first << "\":\"" << rit->second << "\""; } - file << "}"; + file << "}"; } file << "]"; file.close(); } #endif /* _FEATURES_HELPER_FUNCTIONS */ - diff --git a/features/support/RpnCalculator.cpp b/features/support/RpnCalculator.cpp index f9aba645..8eeb27f6 100644 --- a/features/support/RpnCalculator.cpp +++ b/features/support/RpnCalculator.cpp @@ -45,4 +45,3 @@ class RpnCalculator { stack.push_back(v); } }; - diff --git a/include/cucumber-cpp/defs.hpp b/include/cucumber-cpp/defs.hpp index 08c56c9d..2273b592 100644 --- a/include/cucumber-cpp/defs.hpp +++ b/include/cucumber-cpp/defs.hpp @@ -1,7 +1,9 @@ #ifdef __GNUC__ #warning "Use of defs.hpp is deprecated, please use either autodetect.hpp or generic.hpp" #else - #pragma message( "Use of defs.hpp is deprecated, please use either autodetect.hpp or generic.hpp" ) + #pragma message( \ + "Use of defs.hpp is deprecated, please use either autodetect.hpp or generic.hpp" \ + ) #endif #include "internal/defs.hpp" #ifndef STEP_INHERITANCE diff --git a/include/cucumber-cpp/internal/ContextManager.hpp b/include/cucumber-cpp/internal/ContextManager.hpp index a24abcb1..9a37643e 100644 --- a/include/cucumber-cpp/internal/ContextManager.hpp +++ b/include/cucumber-cpp/internal/ContextManager.hpp @@ -11,12 +11,13 @@ namespace cucumber { namespace internal { -typedef std::vector > contexts_type; +typedef std::vector> contexts_type; class CUCUMBER_CPP_EXPORT ContextManager { public: void purgeContexts(); - template std::weak_ptr addContext(); + template + std::weak_ptr addContext(); protected: static contexts_type contexts; @@ -26,7 +27,7 @@ template std::weak_ptr ContextManager::addContext() { std::shared_ptr shared(std::make_shared()); contexts.push_back(shared); - return std::weak_ptr (shared); + return std::weak_ptr(shared); } } @@ -51,10 +52,10 @@ std::weak_ptr ScenarioScope::contextReference; template ScenarioScope::ScenarioScope() { - if (contextReference.expired()) { - contextReference = contextManager.addContext (); - } - context = contextReference.lock(); + if (contextReference.expired()) { + contextReference = contextManager.addContext(); + } + context = contextReference.lock(); } template diff --git a/include/cucumber-cpp/internal/CukeCommands.hpp b/include/cucumber-cpp/internal/CukeCommands.hpp index 662285e6..25aea407 100644 --- a/include/cucumber-cpp/internal/CukeCommands.hpp +++ b/include/cucumber-cpp/internal/CukeCommands.hpp @@ -21,18 +21,18 @@ namespace internal { */ class CUCUMBER_CPP_EXPORT CukeCommands { public: - CukeCommands(); - virtual ~CukeCommands(); + CukeCommands(); + virtual ~CukeCommands(); void beginScenario(const TagExpression::tag_list& tags = TagExpression::tag_list()); void endScenario(); const std::string snippetText(const std::string stepKeyword, const std::string stepName) const; MatchResult stepMatches(const std::string description) const; - InvokeResult invoke(step_id_type id, const InvokeArgs * pArgs); + InvokeResult invoke(step_id_type id, const InvokeArgs* pArgs); protected: - const std::string escapeRegex(const std::string regex) const; - const std::string escapeCString(const std::string str) const; + const std::string escapeRegex(const std::string regex) const; + const std::string escapeCString(const std::string str) const; private: ContextManager contextManager; diff --git a/include/cucumber-cpp/internal/CukeEngine.hpp b/include/cucumber-cpp/internal/CukeEngine.hpp index c8e0e7bc..cc240c11 100644 --- a/include/cucumber-cpp/internal/CukeEngine.hpp +++ b/include/cucumber-cpp/internal/CukeEngine.hpp @@ -31,8 +31,8 @@ class CUCUMBER_CPP_EXPORT InvokeException { const std::string message; public: - InvokeException(const std::string & message); - InvokeException(const InvokeException &rhs); + InvokeException(const std::string& message); + InvokeException(const InvokeException& rhs); const std::string getMessage() const; @@ -44,16 +44,16 @@ class CUCUMBER_CPP_EXPORT InvokeFailureException : public InvokeException { const std::string exceptionType; public: - InvokeFailureException(const std::string & message, const std::string & exceptionType); - InvokeFailureException(const InvokeFailureException &rhs); + InvokeFailureException(const std::string& message, const std::string& exceptionType); + InvokeFailureException(const InvokeFailureException& rhs); const std::string getExceptionType() const; }; class CUCUMBER_CPP_EXPORT PendingStepException : public InvokeException { public: - PendingStepException(const std::string & message); - PendingStepException(const PendingStepException &rhs); + PendingStepException(const std::string& message); + PendingStepException(const PendingStepException& rhs); }; /** @@ -66,6 +66,7 @@ class CukeEngine { private: typedef std::vector string_array; typedef boost::multi_array string_2d_array; + public: typedef string_array tags_type; typedef string_array invoke_args_type; @@ -74,29 +75,34 @@ class CukeEngine { /** * Finds steps whose regexp match some text. */ - virtual std::vector stepMatches(const std::string & name) const = 0; + virtual std::vector stepMatches(const std::string& name) const = 0; /** * Starts a scenario. */ - virtual void beginScenario(const tags_type & tags) = 0; + virtual void beginScenario(const tags_type& tags) = 0; /** * Invokes a step passing arguments to it. * * @throws InvokeException if the test fails or it is pending */ - virtual void invokeStep(const std::string & id, const invoke_args_type & args, const invoke_table_type & tableArg) = 0; + virtual void invokeStep( + const std::string& id, const invoke_args_type& args, const invoke_table_type& tableArg + ) = 0; /** * Ends a scenario. */ - virtual void endScenario(const tags_type & tags) = 0; + virtual void endScenario(const tags_type& tags) = 0; /** * Returns the step definition for a pending step. */ - virtual std::string snippetText(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) const = 0; + virtual std::string snippetText( + const std::string& keyword, const std::string& name, const std::string& multilineArgClass + ) const + = 0; CUCUMBER_CPP_EXPORT CukeEngine(); CUCUMBER_CPP_EXPORT virtual ~CukeEngine() = default; diff --git a/include/cucumber-cpp/internal/CukeEngineImpl.hpp b/include/cucumber-cpp/internal/CukeEngineImpl.hpp index a7b6f0d8..8b70ebeb 100644 --- a/include/cucumber-cpp/internal/CukeEngineImpl.hpp +++ b/include/cucumber-cpp/internal/CukeEngineImpl.hpp @@ -19,11 +19,15 @@ class CUCUMBER_CPP_EXPORT CukeEngineImpl : public CukeEngine { CukeCommands cukeCommands; public: - std::vector stepMatches(const std::string & name) const override; - void beginScenario(const tags_type & tags) override; - void invokeStep(const std::string & id, const invoke_args_type & args, const invoke_table_type & tableArg) override; - void endScenario(const tags_type & tags) override; - std::string snippetText(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) const override; + std::vector stepMatches(const std::string& name) const override; + void beginScenario(const tags_type& tags) override; + void invokeStep( + const std::string& id, const invoke_args_type& args, const invoke_table_type& tableArg + ) override; + void endScenario(const tags_type& tags) override; + std::string snippetText( + const std::string& keyword, const std::string& name, const std::string& multilineArgClass + ) const override; }; } diff --git a/include/cucumber-cpp/internal/RegistrationMacros.hpp b/include/cucumber-cpp/internal/RegistrationMacros.hpp index 676891dc..1759a66c 100644 --- a/include/cucumber-cpp/internal/RegistrationMacros.hpp +++ b/include/cucumber-cpp/internal/RegistrationMacros.hpp @@ -2,9 +2,9 @@ #define CUKE_REGISTRATIONMACROS_HPP_ #if __cplusplus >= 201103L -#define CUKE_OVERRIDE override + #define CUKE_OVERRIDE override #else -#define CUKE_OVERRIDE + #define CUKE_OVERRIDE #endif // ************************************************************************** // @@ -12,33 +12,31 @@ // ************************************************************************** // #ifndef CUKE_OBJECT_PREFIX -#define CUKE_OBJECT_PREFIX CukeObject + #define CUKE_OBJECT_PREFIX CukeObject #endif #ifdef __COUNTER__ -#define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __COUNTER__) + #define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __COUNTER__) #else -// Use a counter to be incremented every time cucumber-cpp is included -// in case this does not suffice (possible with multiple files only) -#define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __LINE__) + // Use a counter to be incremented every time cucumber-cpp is included + // in case this does not suffice (possible with multiple files only) + #define CUKE_GEN_OBJECT_NAME_ BOOST_JOIN(CUKE_OBJECT_PREFIX, __LINE__) #endif // ************************************************************************** // // ************** CUKE OBJECTS ************** // // ************************************************************************** // -#define CUKE_OBJECT_(class_name, parent_class, registration_fn, args) \ -class class_name : public parent_class { \ -public: \ - void body() CUKE_OVERRIDE { \ - return invokeWithArgs(*this, &class_name::bodyWithArgs); \ - } \ - void bodyWithArgs args; \ -private: \ - static const int cukeRegId; \ -}; \ -const int class_name ::cukeRegId = registration_fn ; \ -void class_name ::bodyWithArgs args \ -/**/ +#define CUKE_OBJECT_(class_name, parent_class, registration_fn, args) \ + class class_name : public parent_class { \ + public: \ + void body() CUKE_OVERRIDE { return invokeWithArgs(*this, &class_name::bodyWithArgs); } \ + void bodyWithArgs args; \ + \ + private: \ + static const int cukeRegId; \ + }; \ + const int class_name ::cukeRegId = registration_fn; \ + void class_name ::bodyWithArgs args /**/ #endif /* CUKE_REGISTRATIONMACROS_HPP_ */ diff --git a/include/cucumber-cpp/internal/Scenario.hpp b/include/cucumber-cpp/internal/Scenario.hpp index 17fb62ba..8dd726cf 100644 --- a/include/cucumber-cpp/internal/Scenario.hpp +++ b/include/cucumber-cpp/internal/Scenario.hpp @@ -10,7 +10,8 @@ class Scenario { public: Scenario(const TagExpression::tag_list& tags = TagExpression::tag_list()); - const TagExpression::tag_list & getTags(); + const TagExpression::tag_list& getTags(); + private: const TagExpression::tag_list tags; }; diff --git a/include/cucumber-cpp/internal/Table.hpp b/include/cucumber-cpp/internal/Table.hpp index a7a70bdb..7a424826 100644 --- a/include/cucumber-cpp/internal/Table.hpp +++ b/include/cucumber-cpp/internal/Table.hpp @@ -14,8 +14,9 @@ namespace internal { class CUCUMBER_CPP_EXPORT Table { private: typedef std::vector basic_type; + public: - typedef std::map hash_row_type; + typedef std::map hash_row_type; typedef basic_type columns_type; typedef basic_type row_type; typedef std::vector hashes_type; @@ -35,11 +36,11 @@ class CUCUMBER_CPP_EXPORT Table { * @throws std::range_error * @throws std::runtime_error */ - void addRow(const row_type &row); - const hashes_type & hashes() const; + void addRow(const row_type& row); + const hashes_type& hashes() const; private: - hash_row_type buildHashRow(const row_type &row); + hash_row_type buildHashRow(const row_type& row); columns_type columns; hashes_type rows; diff --git a/include/cucumber-cpp/internal/connectors/wire/ProtocolHandler.hpp b/include/cucumber-cpp/internal/connectors/wire/ProtocolHandler.hpp index 16c29b59..db529e15 100644 --- a/include/cucumber-cpp/internal/connectors/wire/ProtocolHandler.hpp +++ b/include/cucumber-cpp/internal/connectors/wire/ProtocolHandler.hpp @@ -11,7 +11,7 @@ namespace internal { */ class ProtocolHandler { public: - virtual std::string handle(const std::string &request) const = 0; + virtual std::string handle(const std::string& request) const = 0; virtual ~ProtocolHandler() = default; }; diff --git a/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp b/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp index 7ead98d0..1941ac83 100644 --- a/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp +++ b/include/cucumber-cpp/internal/connectors/wire/WireProtocol.hpp @@ -18,7 +18,7 @@ class WireResponseVisitor; class CUCUMBER_CPP_EXPORT WireResponse { public: - WireResponse() {}; + WireResponse(){}; virtual void accept(WireResponseVisitor& visitor) const = 0; @@ -35,7 +35,7 @@ class CUCUMBER_CPP_EXPORT FailureResponse : public WireResponse { const std::string message, exceptionType; public: - FailureResponse(const std::string & message = "", const std::string & exceptionType = ""); + FailureResponse(const std::string& message = "", const std::string& exceptionType = ""); const std::string getMessage() const; const std::string getExceptionType() const; @@ -48,7 +48,7 @@ class CUCUMBER_CPP_EXPORT PendingResponse : public WireResponse { const std::string message; public: - PendingResponse(const std::string & message); + PendingResponse(const std::string& message); const std::string getMessage() const; @@ -60,7 +60,7 @@ class CUCUMBER_CPP_EXPORT StepMatchesResponse : public WireResponse { const std::vector matchingSteps; public: - StepMatchesResponse(const std::vector & matchingSteps); + StepMatchesResponse(const std::vector& matchingSteps); const std::vector& getMatchingSteps() const; void accept(WireResponseVisitor& visitor) const override; @@ -71,7 +71,7 @@ class CUCUMBER_CPP_EXPORT SnippetTextResponse : public WireResponse { const std::string stepSnippet; public: - SnippetTextResponse(const std::string & stepSnippet); + SnippetTextResponse(const std::string& stepSnippet); const std::string getStepSnippet() const; @@ -89,7 +89,6 @@ class CUCUMBER_CPP_EXPORT WireResponseVisitor { virtual ~WireResponseVisitor() = default; }; - /** * Wire protocol request command. */ @@ -109,10 +108,10 @@ class CUCUMBER_CPP_EXPORT WireCommand { class CUCUMBER_CPP_EXPORT WireMessageCodecException : public std::exception { private: - const char *description; + const char* description; public: - WireMessageCodecException(const char *description) : + WireMessageCodecException(const char* description) : description(description) { } @@ -121,7 +120,6 @@ class CUCUMBER_CPP_EXPORT WireMessageCodecException : public std::exception { } }; - /** * Transforms wire messages into commands and responses to messages. */ @@ -136,7 +134,7 @@ class CUCUMBER_CPP_EXPORT WireMessageCodec { * * @throws WireMessageCodecException */ - virtual std::shared_ptr decode(const std::string &request) const = 0; + virtual std::shared_ptr decode(const std::string& request) const = 0; /** * Encodes a response to wire format. @@ -156,7 +154,7 @@ class CUCUMBER_CPP_EXPORT WireMessageCodec { class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec { public: JsonSpiritWireMessageCodec() = default; - std::shared_ptr decode(const std::string &request) const override; + std::shared_ptr decode(const std::string& request) const override; const std::string encode(const WireResponse& response) const override; }; @@ -172,7 +170,7 @@ class CUCUMBER_CPP_EXPORT WireProtocolHandler : public ProtocolHandler { public: WireProtocolHandler(const WireMessageCodec& codec, CukeEngine& engine); - std::string handle(const std::string &request) const override; + std::string handle(const std::string& request) const override; }; } diff --git a/include/cucumber-cpp/internal/connectors/wire/WireProtocolCommands.hpp b/include/cucumber-cpp/internal/connectors/wire/WireProtocolCommands.hpp index 9cc09e5f..fbf8348e 100644 --- a/include/cucumber-cpp/internal/connectors/wire/WireProtocolCommands.hpp +++ b/include/cucumber-cpp/internal/connectors/wire/WireProtocolCommands.hpp @@ -14,7 +14,6 @@ class ScenarioCommand : public WireCommand { ScenarioCommand(const CukeEngine::tags_type& tags); }; - class BeginScenarioCommand : public ScenarioCommand { public: BeginScenarioCommand(const CukeEngine::tags_type& tags); @@ -22,7 +21,6 @@ class BeginScenarioCommand : public ScenarioCommand { std::shared_ptr run(CukeEngine& engine) const override; }; - class EndScenarioCommand : public ScenarioCommand { public: EndScenarioCommand(const CukeEngine::tags_type& tags); @@ -30,18 +28,16 @@ class EndScenarioCommand : public ScenarioCommand { std::shared_ptr run(CukeEngine& engine) const override; }; - class StepMatchesCommand : public WireCommand { private: const std::string stepName; public: - StepMatchesCommand(const std::string & stepName); + StepMatchesCommand(const std::string& stepName); std::shared_ptr run(CukeEngine& engine) const override; }; - class InvokeCommand : public WireCommand { private: const std::string stepId; @@ -49,27 +45,27 @@ class InvokeCommand : public WireCommand { const CukeEngine::invoke_table_type tableArg; public: - InvokeCommand(const std::string & stepId, - const CukeEngine::invoke_args_type& args, - const CukeEngine::invoke_table_type& tableArg); + InvokeCommand( + const std::string& stepId, + const CukeEngine::invoke_args_type& args, + const CukeEngine::invoke_table_type& tableArg + ); std::shared_ptr run(CukeEngine& engine) const override; }; - class SnippetTextCommand : public WireCommand { private: std::string keyword, name, multilineArgClass; public: - SnippetTextCommand(const std::string & keyword, - const std::string & name, - const std::string & multilineArgClass); + SnippetTextCommand( + const std::string& keyword, const std::string& name, const std::string& multilineArgClass + ); std::shared_ptr run(CukeEngine& engine) const override; }; - class FailingCommand : public WireCommand { public: std::shared_ptr run(CukeEngine& engine) const override; diff --git a/include/cucumber-cpp/internal/connectors/wire/WireServer.hpp b/include/cucumber-cpp/internal/connectors/wire/WireServer.hpp index f6d4e801..bd2a579b 100644 --- a/include/cucumber-cpp/internal/connectors/wire/WireServer.hpp +++ b/include/cucumber-cpp/internal/connectors/wire/WireServer.hpp @@ -17,9 +17,9 @@ namespace internal { class CUCUMBER_CPP_EXPORT SocketServer { public: /** - * Constructor for DI - */ - SocketServer(const ProtocolHandler *protocolHandler); + * Constructor for DI + */ + SocketServer(const ProtocolHandler* protocolHandler); virtual ~SocketServer() = default; /** @@ -28,23 +28,27 @@ class CUCUMBER_CPP_EXPORT SocketServer { virtual void acceptOnce() = 0; protected: - const ProtocolHandler *protocolHandler; + const ProtocolHandler* protocolHandler; boost::asio::io_service ios; #if BOOST_VERSION <= 106500 - template - void doListen(boost::asio::basic_socket_acceptor& acceptor, - const typename Protocol::endpoint& endpoint); - template + template + void doListen( + boost::asio::basic_socket_acceptor& acceptor, + const typename Protocol::endpoint& endpoint + ); + template void doAcceptOnce(boost::asio::basic_socket_acceptor& acceptor); #else - template - void doListen(boost::asio::basic_socket_acceptor& acceptor, - const typename Protocol::endpoint& endpoint); - template + template + void doListen( + boost::asio::basic_socket_acceptor& acceptor, + const typename Protocol::endpoint& endpoint + ); + template void doAcceptOnce(boost::asio::basic_socket_acceptor& acceptor); #endif - void processStream(std::iostream &stream); + void processStream(std::iostream& stream); }; /** @@ -58,9 +62,9 @@ class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer { typedef unsigned short port_type; /** - * Constructor for DI - */ - TCPSocketServer(const ProtocolHandler *protocolHandler); + * Constructor for DI + */ + TCPSocketServer(const ProtocolHandler* protocolHandler); /** * Bind and listen to a TCP port @@ -94,9 +98,9 @@ class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer { class CUCUMBER_CPP_EXPORT UnixSocketServer : public SocketServer { public: /** - * Constructor for DI - */ - UnixSocketServer(const ProtocolHandler *protocolHandler); + * Constructor for DI + */ + UnixSocketServer(const ProtocolHandler* protocolHandler); /** * Bind and listen on a local stream socket diff --git a/include/cucumber-cpp/internal/drivers/QtTestDriver.hpp b/include/cucumber-cpp/internal/drivers/QtTestDriver.hpp index 1e2f3360..b1c73167 100644 --- a/include/cucumber-cpp/internal/drivers/QtTestDriver.hpp +++ b/include/cucumber-cpp/internal/drivers/QtTestDriver.hpp @@ -12,7 +12,9 @@ class CUCUMBER_CPP_EXPORT QtTestStep : public BasicStep { friend class QtTestObject; public: - QtTestStep() : BasicStep() {} + QtTestStep() : + BasicStep() { + } protected: const InvokeResult invokeStepBody() override; @@ -23,7 +25,9 @@ class CUCUMBER_CPP_EXPORT QtTestStep : public BasicStep { class QtTestObject : public QObject { Q_OBJECT public: - QtTestObject(QtTestStep* qtTestStep) : step(qtTestStep) {} + QtTestObject(QtTestStep* qtTestStep) : + step(qtTestStep) { + } protected: QtTestStep* step; diff --git a/include/cucumber-cpp/internal/hook/HookMacros.hpp b/include/cucumber-cpp/internal/hook/HookMacros.hpp index cc89408b..be8f56ff 100644 --- a/include/cucumber-cpp/internal/hook/HookMacros.hpp +++ b/include/cucumber-cpp/internal/hook/HookMacros.hpp @@ -7,127 +7,117 @@ // ************** BEFORE HOOK ************** // // ************************************************************************** // -#define BEFORE(...) \ -BEFORE_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ -/**/ - -#define BEFORE_WITH_NAME_(step_name, tag_expression) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::BeforeHook, \ - BEFORE_HOOK_REGISTRATION_(step_name, tag_expression), \ - () \ -) \ -/**/ - -#define BEFORE_HOOK_REGISTRATION_(step_name, tag_expression) \ -::cucumber::internal::registerBeforeHook(tag_expression) \ -/**/ +#define BEFORE(...) \ + BEFORE_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ + /**/ + +#define BEFORE_WITH_NAME_(step_name, tag_expression) \ + CUKE_OBJECT_( \ + step_name, \ + ::cucumber::internal::BeforeHook, \ + BEFORE_HOOK_REGISTRATION_(step_name, tag_expression), \ + () \ + ) \ + /**/ + +#define BEFORE_HOOK_REGISTRATION_(step_name, tag_expression) \ + ::cucumber::internal::registerBeforeHook(tag_expression) /**/ // ************************************************************************** // // ************** AROUND_STEP HOOK ************** // // ************************************************************************** // -#define AROUND_STEP(...) \ -AROUND_STEP_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ -/**/ +#define AROUND_STEP(...) \ + AROUND_STEP_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ + /**/ -#define AROUND_STEP_WITH_NAME_(step_name, tag_expression) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::AroundStepHook, \ - AROUND_STEP_HOOK_REGISTRATION_(step_name, tag_expression), \ - () \ -) \ -/**/ +#define AROUND_STEP_WITH_NAME_(step_name, tag_expression) \ + CUKE_OBJECT_( \ + step_name, \ + ::cucumber::internal::AroundStepHook, \ + AROUND_STEP_HOOK_REGISTRATION_(step_name, tag_expression), \ + () \ + ) \ + /**/ -#define AROUND_STEP_HOOK_REGISTRATION_(step_name, tag_expression) \ -::cucumber::internal::registerAroundStepHook(tag_expression) \ -/**/ +#define AROUND_STEP_HOOK_REGISTRATION_(step_name, tag_expression) \ + ::cucumber::internal::registerAroundStepHook(tag_expression) /**/ // ************************************************************************** // // ************** AFTER_STEP HOOK ************** // // ************************************************************************** // -#define AFTER_STEP(...) \ -AFTER_STEP_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ -/**/ +#define AFTER_STEP(...) \ + AFTER_STEP_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ + /**/ -#define AFTER_STEP_WITH_NAME_(step_name, tag_expression) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::AfterStepHook, \ - AFTER_STEP_HOOK_REGISTRATION_(step_name, tag_expression), \ - () \ -) \ -/**/ - -#define AFTER_STEP_HOOK_REGISTRATION_(step_name, tag_expression) \ -::cucumber::internal::registerAfterStepHook(tag_expression) \ -/**/ +#define AFTER_STEP_WITH_NAME_(step_name, tag_expression) \ + CUKE_OBJECT_( \ + step_name, \ + ::cucumber::internal::AfterStepHook, \ + AFTER_STEP_HOOK_REGISTRATION_(step_name, tag_expression), \ + () \ + ) \ + /**/ +#define AFTER_STEP_HOOK_REGISTRATION_(step_name, tag_expression) \ + ::cucumber::internal::registerAfterStepHook(tag_expression) /**/ // ************************************************************************** // // ************** AFTER HOOK ************** // // ************************************************************************** // -#define AFTER(...) \ -AFTER_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ -/**/ +#define AFTER(...) \ + AFTER_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, "" #__VA_ARGS__) \ + /**/ -#define AFTER_WITH_NAME_(step_name, tag_expression) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::AfterHook, \ - AFTER_HOOK_REGISTRATION_(step_name, tag_expression), \ - () \ -) \ -/**/ +#define AFTER_WITH_NAME_(step_name, tag_expression) \ + CUKE_OBJECT_( \ + step_name, \ + ::cucumber::internal::AfterHook, \ + AFTER_HOOK_REGISTRATION_(step_name, tag_expression), \ + () \ + ) \ + /**/ -#define AFTER_HOOK_REGISTRATION_(step_name, tag_expression) \ -::cucumber::internal::registerAfterHook(tag_expression) \ -/**/ +#define AFTER_HOOK_REGISTRATION_(step_name, tag_expression) \ + ::cucumber::internal::registerAfterHook(tag_expression) /**/ // ************************************************************************** // // ************** BEFORE_ALL HOOK ************** // // ************************************************************************** // -#define BEFORE_ALL() \ -BEFORE_ALL_WITH_NAME_(CUKE_GEN_OBJECT_NAME_) \ -/**/ +#define BEFORE_ALL() \ + BEFORE_ALL_WITH_NAME_(CUKE_GEN_OBJECT_NAME_) \ + /**/ -#define BEFORE_ALL_WITH_NAME_(step_name) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::BeforeAllHook, \ - BEFORE_ALL_HOOK_REGISTRATION_(step_name), \ - () \ -) \ -/**/ +#define BEFORE_ALL_WITH_NAME_(step_name) \ + CUKE_OBJECT_( \ + step_name, \ + ::cucumber::internal::BeforeAllHook, \ + BEFORE_ALL_HOOK_REGISTRATION_(step_name), \ + () \ + ) \ + /**/ -#define BEFORE_ALL_HOOK_REGISTRATION_(step_name) \ -::cucumber::internal::registerBeforeAllHook() \ -/**/ +#define BEFORE_ALL_HOOK_REGISTRATION_(step_name) \ + ::cucumber::internal::registerBeforeAllHook() /**/ // ************************************************************************** // // ************** AFTER_ALL HOOK ************** // // ************************************************************************** // -#define AFTER_ALL() \ -AFTER_ALL_WITH_NAME_(CUKE_GEN_OBJECT_NAME_) \ -/**/ - -#define AFTER_ALL_WITH_NAME_(step_name) \ -CUKE_OBJECT_( \ - step_name, \ - ::cucumber::internal::AfterAllHook, \ - AFTER_ALL_HOOK_REGISTRATION_(step_name), \ - () \ -) \ -/**/ - -#define AFTER_ALL_HOOK_REGISTRATION_(step_name) \ -::cucumber::internal::registerAfterAllHook() \ -/**/ +#define AFTER_ALL() \ + AFTER_ALL_WITH_NAME_(CUKE_GEN_OBJECT_NAME_) \ + /**/ + +#define AFTER_ALL_WITH_NAME_(step_name) \ + CUKE_OBJECT_( \ + step_name, ::cucumber::internal::AfterAllHook, AFTER_ALL_HOOK_REGISTRATION_(step_name), () \ + ) \ + /**/ + +#define AFTER_ALL_HOOK_REGISTRATION_(step_name) \ + ::cucumber::internal::registerAfterAllHook() /**/ #endif /* CUKE_HOOKMACROS_HPP_ */ diff --git a/include/cucumber-cpp/internal/hook/HookRegistrar.hpp b/include/cucumber-cpp/internal/hook/HookRegistrar.hpp index 91a37d9a..adafccc3 100644 --- a/include/cucumber-cpp/internal/hook/HookRegistrar.hpp +++ b/include/cucumber-cpp/internal/hook/HookRegistrar.hpp @@ -23,17 +23,19 @@ class CUCUMBER_CPP_EXPORT Hook { public: virtual ~Hook() = default; - void setTags(const std::string &csvTagNotation); - virtual void invokeHook(Scenario *scenario, CallableStep *step); + void setTags(const std::string& csvTagNotation); + virtual void invokeHook(Scenario* scenario, CallableStep* step); virtual void skipHook(); virtual void body() = 0; + protected: - bool tagsMatch(Scenario *scenario); + bool tagsMatch(Scenario* scenario); - template - static R invokeWithArgs(Derived& that, R (Derived::* f)()) { + template + static R invokeWithArgs(Derived& that, R (Derived::*f)()) { return (that.*f)(); } + private: AndTagExpression tagExpression; }; @@ -42,10 +44,11 @@ class CUCUMBER_CPP_EXPORT BeforeHook : public Hook {}; class CUCUMBER_CPP_EXPORT AroundStepHook : public Hook { public: - void invokeHook(Scenario *scenario, CallableStep *step) override; + void invokeHook(Scenario* scenario, CallableStep* step) override; void skipHook() override; + protected: - CallableStep *step; + CallableStep* step; }; class CUCUMBER_CPP_EXPORT AfterStepHook : public Hook {}; @@ -54,7 +57,7 @@ class CUCUMBER_CPP_EXPORT AfterHook : public Hook {}; class CUCUMBER_CPP_EXPORT UnconditionalHook : public Hook { public: - void invokeHook(Scenario *scenario, CallableStep *step) override; + void invokeHook(Scenario* scenario, CallableStep* step) override; }; class CUCUMBER_CPP_EXPORT BeforeAllHook : public UnconditionalHook {}; @@ -63,20 +66,22 @@ class CUCUMBER_CPP_EXPORT AfterAllHook : public UnconditionalHook {}; class CUCUMBER_CPP_EXPORT HookRegistrar { public: - typedef std::list< std::shared_ptr > hook_list_type; - typedef std::list< std::shared_ptr > aroundhook_list_type; + typedef std::list> hook_list_type; + typedef std::list> aroundhook_list_type; static void addBeforeHook(std::shared_ptr afterHook); - static void execBeforeHooks(Scenario *scenario); + static void execBeforeHooks(Scenario* scenario); static void addAroundStepHook(std::shared_ptr aroundStepHook); - static InvokeResult execStepChain(Scenario *scenario, const StepInfo* stepInfo, const InvokeArgs *pArgs); + static InvokeResult execStepChain( + Scenario* scenario, const StepInfo* stepInfo, const InvokeArgs* pArgs + ); static void addAfterStepHook(std::shared_ptr afterStepHook); - static void execAfterStepHooks(Scenario *scenario); + static void execAfterStepHooks(Scenario* scenario); static void addAfterHook(std::shared_ptr afterHook); - static void execAfterHooks(Scenario *scenario); + static void execAfterHooks(Scenario* scenario); static void addBeforeAllHook(std::shared_ptr beforeAllHook); static void execBeforeAllHooks(); @@ -85,7 +90,7 @@ class CUCUMBER_CPP_EXPORT HookRegistrar { static void execAfterAllHooks(); private: - static void execHooks(HookRegistrar::hook_list_type &hookList, Scenario *scenario); + static void execHooks(HookRegistrar::hook_list_type& hookList, Scenario* scenario); protected: static hook_list_type& beforeAllHooks(); @@ -106,15 +111,21 @@ class CUCUMBER_CPP_EXPORT HookRegistrar { class CUCUMBER_CPP_EXPORT StepCallChain { public: - StepCallChain(Scenario *scenario, const StepInfo* stepInfo, const InvokeArgs *pStepArgs, HookRegistrar::aroundhook_list_type &aroundHooks); + StepCallChain( + Scenario* scenario, + const StepInfo* stepInfo, + const InvokeArgs* pStepArgs, + HookRegistrar::aroundhook_list_type& aroundHooks + ); InvokeResult exec(); void execNext(); + private: void execStep(); - Scenario *scenario; + Scenario* scenario; const StepInfo* stepInfo; - const InvokeArgs *pStepArgs; + const InvokeArgs* pStepArgs; HookRegistrar::aroundhook_list_type::iterator nextHook; HookRegistrar::aroundhook_list_type::iterator hookEnd; @@ -123,55 +134,55 @@ class CUCUMBER_CPP_EXPORT StepCallChain { class CUCUMBER_CPP_EXPORT CallableStepChain : public CallableStep { public: - CallableStepChain(StepCallChain *scc); + CallableStepChain(StepCallChain* scc); void call() override; + private: - StepCallChain *scc; + StepCallChain* scc; }; - template -static int registerBeforeHook(const std::string &csvTagNotation) { - std::shared_ptr hook(std::make_shared()); - hook->setTags(csvTagNotation); - HookRegistrar::addBeforeHook(hook); - return 0; // We are not interested in the ID at this time +static int registerBeforeHook(const std::string& csvTagNotation) { + std::shared_ptr hook(std::make_shared()); + hook->setTags(csvTagNotation); + HookRegistrar::addBeforeHook(hook); + return 0; // We are not interested in the ID at this time } template -static int registerAroundStepHook(const std::string &csvTagNotation) { - std::shared_ptr hook(std::make_shared()); - hook->setTags(csvTagNotation); - HookRegistrar::addAroundStepHook(hook); - return 0; +static int registerAroundStepHook(const std::string& csvTagNotation) { + std::shared_ptr hook(std::make_shared()); + hook->setTags(csvTagNotation); + HookRegistrar::addAroundStepHook(hook); + return 0; } template -static int registerAfterStepHook(const std::string &csvTagNotation) { - std::shared_ptr hook(std::make_shared()); - hook->setTags(csvTagNotation); - HookRegistrar::addAfterStepHook(hook); - return 0; +static int registerAfterStepHook(const std::string& csvTagNotation) { + std::shared_ptr hook(std::make_shared()); + hook->setTags(csvTagNotation); + HookRegistrar::addAfterStepHook(hook); + return 0; } template -static int registerAfterHook(const std::string &csvTagNotation) { - std::shared_ptr hook(std::make_shared()); - hook->setTags(csvTagNotation); - HookRegistrar::addAfterHook(hook); - return 0; +static int registerAfterHook(const std::string& csvTagNotation) { + std::shared_ptr hook(std::make_shared()); + hook->setTags(csvTagNotation); + HookRegistrar::addAfterHook(hook); + return 0; } template static int registerBeforeAllHook() { - HookRegistrar::addBeforeAllHook(std::make_shared()); - return 0; + HookRegistrar::addBeforeAllHook(std::make_shared()); + return 0; } template static int registerAfterAllHook() { - HookRegistrar::addAfterAllHook(std::make_shared()); - return 0; + HookRegistrar::addAfterAllHook(std::make_shared()); + return 0; } } diff --git a/include/cucumber-cpp/internal/hook/Tag.hpp b/include/cucumber-cpp/internal/hook/Tag.hpp index ce57d642..b765207a 100644 --- a/include/cucumber-cpp/internal/hook/Tag.hpp +++ b/include/cucumber-cpp/internal/hook/Tag.hpp @@ -15,33 +15,33 @@ class CUCUMBER_CPP_EXPORT TagExpression { typedef std::vector tag_list; virtual ~TagExpression() = default; - virtual bool matches(const tag_list &tags) const = 0; + virtual bool matches(const tag_list& tags) const = 0; }; class CUCUMBER_CPP_EXPORT OrTagExpression : public TagExpression { public: - OrTagExpression(const std::string &csvTagNotation); - bool matches(const tag_list &tags) const override; + OrTagExpression(const std::string& csvTagNotation); + bool matches(const tag_list& tags) const override; private: - bool orTagMatchesTagList(const std::string ¤tOrTag, const tag_list &tags) const; + bool orTagMatchesTagList(const std::string& currentOrTag, const tag_list& tags) const; tag_list orTags; - static Regex & csvTagNotationRegex(); + static Regex& csvTagNotationRegex(); }; class CUCUMBER_CPP_EXPORT AndTagExpression : public TagExpression { public: AndTagExpression() = default; - AndTagExpression(const std::string &csvTagNotation); - bool matches(const tag_list &tags) const override; + AndTagExpression(const std::string& csvTagNotation); + bool matches(const tag_list& tags) const override; private: typedef std::vector or_expressions_type; or_expressions_type orExpressions; - static Regex & csvTagNotationRegex(); + static Regex& csvTagNotationRegex(); }; } diff --git a/include/cucumber-cpp/internal/step/StepMacros.hpp b/include/cucumber-cpp/internal/step/StepMacros.hpp index 9fc0d83a..c406ff6c 100644 --- a/include/cucumber-cpp/internal/step/StepMacros.hpp +++ b/include/cucumber-cpp/internal/step/StepMacros.hpp @@ -10,26 +10,25 @@ #define CUKE_STEP_GET_MATCHER_(step_matcher, ...) step_matcher #define CUKE_STEP_GET_ARGS_(step_matcher, args, ...) args -#define CUKE_STEP_(...) \ - CUKE_STEP_WITH_NAME_(CUKE_GEN_OBJECT_NAME_, \ - CUKE_STEP_GET_MATCHER_(__VA_ARGS__, ()), \ - CUKE_STEP_GET_ARGS_(__VA_ARGS__, (), ())) \ -/**/ +#define CUKE_STEP_(...) \ + CUKE_STEP_WITH_NAME_( \ + CUKE_GEN_OBJECT_NAME_, \ + CUKE_STEP_GET_MATCHER_(__VA_ARGS__, ()), \ + CUKE_STEP_GET_ARGS_(__VA_ARGS__, (), ()) \ + ) \ + /**/ #define CUKE_STEP_WITH_NAME_(step_name, step_matcher, args) \ -CUKE_OBJECT_( \ - step_name, \ - STEP_INHERITANCE(step_name), \ - CUKE_STEP_REGISTRATION_(step_name, step_matcher), \ - args \ -) \ -/**/ + CUKE_OBJECT_( \ + step_name, \ + STEP_INHERITANCE(step_name), \ + CUKE_STEP_REGISTRATION_(step_name, step_matcher), \ + args \ + ) \ + /**/ #define CUKE_STEP_REGISTRATION_(step_name, step_matcher) \ -::cucumber::internal::registerStep< step_name >( \ - step_matcher, __FILE__, __LINE__ \ -) \ -/**/ + ::cucumber::internal::registerStep(step_matcher, __FILE__, __LINE__) /**/ // ************************************************************************** // // ************** GIVEN/WHEN/THEN ************** // @@ -44,7 +43,6 @@ ::cucumber::internal::registerStep< step_name >( \ // ************************************************************************** // #define REGEX_PARAM(type, name) const type name(getInvokeArg()) -#define TABLE_PARAM(name) const ::cucumber::internal::Table & name = \ - getArgs()->getTableArg() +#define TABLE_PARAM(name) const ::cucumber::internal::Table& name = getArgs()->getTableArg() #endif /* CUKE_STEPMACROS_HPP_ */ diff --git a/include/cucumber-cpp/internal/step/StepManager.hpp b/include/cucumber-cpp/internal/step/StepManager.hpp index f414e523..25f2d616 100644 --- a/include/cucumber-cpp/internal/step/StepManager.hpp +++ b/include/cucumber-cpp/internal/step/StepManager.hpp @@ -30,7 +30,7 @@ class CUCUMBER_CPP_EXPORT SingleStepMatch { public: typedef RegexMatch::submatches_type submatches_type; - operator const void *() const; + operator const void*() const; std::shared_ptr stepInfo; submatches_type submatches; @@ -54,16 +54,19 @@ class CUCUMBER_CPP_EXPORT MatchResult { class CUCUMBER_CPP_EXPORT InvokeArgs { typedef std::vector args_type; + public: typedef args_type::size_type size_type; - + InvokeArgs() = default; - + void addArg(const std::string arg); - Table & getVariableTableArg(); + Table& getVariableTableArg(); + + template + T getInvokeArg(size_type i) const; + const Table& getTableArg() const; - template T getInvokeArg(size_type i) const; - const Table & getTableArg() const; private: Table tableArg; args_type args; @@ -80,35 +83,37 @@ class CUCUMBER_CPP_EXPORT InvokeResult { InvokeResultType type; std::string description; - InvokeResult(const InvokeResultType type, const char *description); + InvokeResult(const InvokeResultType type, const char* description); + public: InvokeResult(); - InvokeResult(const InvokeResult &ir); - InvokeResult& operator= (const InvokeResult& rhs); + InvokeResult(const InvokeResult& ir); + InvokeResult& operator=(const InvokeResult& rhs); static InvokeResult success(); - static InvokeResult failure(const char *description); - static InvokeResult failure(const std::string &description); - static InvokeResult pending(const char *description); + static InvokeResult failure(const char* description); + static InvokeResult failure(const std::string& description); + static InvokeResult pending(const char* description); bool isSuccess() const; bool isPending() const; InvokeResultType getType() const; - const std::string &getDescription() const; + const std::string& getDescription() const; }; class CUCUMBER_CPP_EXPORT StepInfo : public std::enable_shared_from_this { public: - StepInfo(const std::string &stepMatcher, const std::string source); + StepInfo(const std::string& stepMatcher, const std::string source); virtual ~StepInfo() = default; - SingleStepMatch matches(const std::string &stepDescription) const; - virtual InvokeResult invokeStep(const InvokeArgs * pArgs) const = 0; + SingleStepMatch matches(const std::string& stepDescription) const; + virtual InvokeResult invokeStep(const InvokeArgs* pArgs) const = 0; step_id_type id; Regex regex; const std::string source; + private: // Shut up MSVC warning C4512: assignment operator could not be generated StepInfo& operator=(const StepInfo& other); @@ -118,7 +123,7 @@ class CUCUMBER_CPP_EXPORT BasicStep { public: virtual ~BasicStep() = default; - InvokeResult invoke(const InvokeArgs *pArgs); + InvokeResult invoke(const InvokeArgs* pArgs); protected: typedef const Table table_type; @@ -127,33 +132,29 @@ class CUCUMBER_CPP_EXPORT BasicStep { virtual const InvokeResult invokeStepBody() = 0; virtual void body() = 0; - void pending(const char *description); + void pending(const char* description); void pending(); - template const T getInvokeArg(); - const InvokeArgs *getArgs(); + template + const T getInvokeArg(); + const InvokeArgs* getArgs(); #ifdef BOOST_NO_VARIADIC_TEMPLATES // Special case for zero arguments, only thing we bother to support on C++98 - template - static R invokeWithArgs(Derived& that, R (Derived::* f)()) { + template + static R invokeWithArgs(Derived& that, R (Derived::*f)()) { return (that.*f)(); } #else - template - static R invokeWithIndexedArgs(Derived& that, R (Derived::* f)(Args...), index_sequence) { - return (that.*f)( - that.pArgs->template getInvokeArg::type>(N)... - ); + template + static R invokeWithIndexedArgs(Derived& that, R (Derived::*f)(Args...), index_sequence) { + return (that.*f)(that.pArgs->template getInvokeArg::type>(N)...); } - template - static R invokeWithArgs(Derived& that, R (Derived::* f)(Args...)) { + template + static R invokeWithArgs(Derived& that, R (Derived::*f)(Args...)) { that.currentArgIndex = sizeof...(Args); - return invokeWithIndexedArgs( - that, - f, - index_sequence_for{}); + return invokeWithIndexedArgs(that, f, index_sequence_for{}); } #endif @@ -161,27 +162,27 @@ class CUCUMBER_CPP_EXPORT BasicStep { // FIXME: awful hack because of Boost::Test InvokeResult currentResult; - const InvokeArgs *pArgs; + const InvokeArgs* pArgs; InvokeArgs::size_type currentArgIndex; }; - template class StepInvoker : public StepInfo { public: - StepInvoker(const std::string &stepMatcher, const std::string source); + StepInvoker(const std::string& stepMatcher, const std::string source); - InvokeResult invokeStep(const InvokeArgs *args) const override; + InvokeResult invokeStep(const InvokeArgs* args) const override; }; class CUCUMBER_CPP_EXPORT StepManager { protected: - typedef std::map > steps_type; + typedef std::map> steps_type; public: static step_id_type addStep(std::shared_ptr stepInfo); - static MatchResult stepMatches(const std::string &stepDescription); + static MatchResult stepMatches(const std::string& stepDescription); static const StepInfo* getStep(step_id_type id); + protected: static steps_type& steps(); @@ -194,8 +195,7 @@ class CUCUMBER_CPP_EXPORT StepManager { ; }; - -static inline std::string toSourceString(const char *filePath, const int line) { +static inline std::string toSourceString(const char* filePath, const int line) { using namespace std; stringstream s; string file(filePath); @@ -203,15 +203,17 @@ static inline std::string toSourceString(const char *filePath, const int line) { if (pos == string::npos) { s << file; } else { - s << file.substr(++pos); + s << file.substr(++pos); } s << ":" << line; return s.str(); } template -static int registerStep(const std::string &stepMatcher, const char *file, const int line) { - return StepManager::addStep(std::make_shared< StepInvoker >(stepMatcher, toSourceString(file, line))); +static int registerStep(const std::string& stepMatcher, const char* file, const int line) { + return StepManager::addStep( + std::make_shared>(stepMatcher, toSourceString(file, line)) + ); } template @@ -237,7 +239,6 @@ std::string toString(T arg) { return s.str(); } - template T InvokeArgs::getInvokeArg(size_type i) const { if (i >= args.size()) { @@ -246,25 +247,22 @@ T InvokeArgs::getInvokeArg(size_type i) const { return fromString(args.at(i)); } - template const T BasicStep::getInvokeArg() { return pArgs->getInvokeArg(currentArgIndex++); } - template -StepInvoker::StepInvoker(const std::string &stepMatcher, const std::string source) : +StepInvoker::StepInvoker(const std::string& stepMatcher, const std::string source) : StepInfo(stepMatcher, source) { } template -InvokeResult StepInvoker::invokeStep(const InvokeArgs *pArgs) const { +InvokeResult StepInvoker::invokeStep(const InvokeArgs* pArgs) const { T t; return t.invoke(pArgs); } - } } diff --git a/include/cucumber-cpp/internal/utils/IndexSequence.hpp b/include/cucumber-cpp/internal/utils/IndexSequence.hpp index e7828699..6909235d 100644 --- a/include/cucumber-cpp/internal/utils/IndexSequence.hpp +++ b/include/cucumber-cpp/internal/utils/IndexSequence.hpp @@ -5,52 +5,46 @@ #ifndef BOOST_NO_VARIADIC_TEMPLATES -#if __cplusplus < 201402L && !(_MSC_VER > 1800) - #include // for std::size_t -#else - #include -#endif + #if __cplusplus < 201402L && !(_MSC_VER > 1800) + #include // for std::size_t + #else + #include + #endif namespace cucumber { namespace internal { -#if __cplusplus < 201402L && !(_MSC_VER > 1800) + #if __cplusplus < 201402L && !(_MSC_VER > 1800) // Based on https://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence -template +template struct index_sequence { typedef index_sequence type; }; -template +template struct concat_index_sequence; -template -struct concat_index_sequence< - index_sequence - , index_sequence - > : public index_sequence< - N1... - , (sizeof...(N1) + N2)... - > { -}; +template +struct concat_index_sequence, index_sequence> + : public index_sequence {}; -template +template struct make_index_sequence : public concat_index_sequence< - typename make_index_sequence< N/2>::type - , typename make_index_sequence::type - > { -}; + typename make_index_sequence::type, + typename make_index_sequence::type> {}; -template <> struct make_index_sequence<0> : public index_sequence< > {}; -template <> struct make_index_sequence<1> : public index_sequence<0> {}; +template<> +struct make_index_sequence<0> : public index_sequence<> {}; +template<> +struct make_index_sequence<1> : public index_sequence<0> {}; -template +template using index_sequence_for = make_index_sequence; -#else + #else using ::std::index_sequence; using ::std::index_sequence_for; -#endif + #endif } } diff --git a/include/cucumber-cpp/internal/utils/Regex.hpp b/include/cucumber-cpp/internal/utils/Regex.hpp index a0be106d..729067fb 100644 --- a/include/cucumber-cpp/internal/utils/Regex.hpp +++ b/include/cucumber-cpp/internal/utils/Regex.hpp @@ -14,7 +14,6 @@ struct RegexSubmatch { std::ptrdiff_t position; }; - class RegexMatch { public: typedef std::vector submatches_type; @@ -22,7 +21,7 @@ class RegexMatch { virtual ~RegexMatch() = default; bool matches(); - const submatches_type & getSubmatches(); + const submatches_type& getSubmatches(); protected: bool regexMatched; @@ -31,15 +30,14 @@ class RegexMatch { class FindRegexMatch : public RegexMatch { public: - FindRegexMatch(const std::regex ®exImpl, const std::string &expression); + FindRegexMatch(const std::regex& regexImpl, const std::string& expression); }; class FindAllRegexMatch : public RegexMatch { public: - FindAllRegexMatch(const std::regex ®exImpl, const std::string &expression); + FindAllRegexMatch(const std::regex& regexImpl, const std::string& expression); }; - class Regex { private: std::regex regexImpl; @@ -48,8 +46,8 @@ class Regex { public: Regex(std::string expr); - std::shared_ptr find(const std::string &expression) const; - std::shared_ptr findAll(const std::string &expression) const; + std::shared_ptr find(const std::string& expression) const; + std::shared_ptr findAll(const std::string& expression) const; std::string str() const; }; @@ -58,4 +56,3 @@ class Regex { } #endif /* CUKE_REGEX_HPP_ */ - diff --git a/src/ContextManager.cpp b/src/ContextManager.cpp index f9b09bad..4d7b8606 100644 --- a/src/ContextManager.cpp +++ b/src/ContextManager.cpp @@ -11,4 +11,3 @@ void ContextManager::purgeContexts() { } } - diff --git a/src/CukeCommands.cpp b/src/CukeCommands.cpp index 03dc7a6c..15267475 100644 --- a/src/CukeCommands.cpp +++ b/src/CukeCommands.cpp @@ -8,7 +8,8 @@ namespace internal { std::shared_ptr CukeCommands::currentScenario; -CukeCommands::CukeCommands() : hasStarted(false) { +CukeCommands::CukeCommands() : + hasStarted(false) { } CukeCommands::~CukeCommands() { @@ -33,32 +34,44 @@ void CukeCommands::endScenario() { currentScenario.reset(); } -const std::string CukeCommands::snippetText(const std::string stepKeyword, const std::string stepName) const { +const std::string CukeCommands::snippetText( + const std::string stepKeyword, const std::string stepName +) const { std::stringstream text; std::string stepKeywordUpperCase; - std::transform(stepKeyword.begin(), stepKeyword.end(), std::back_inserter(stepKeywordUpperCase), ::toupper); - text << stepKeywordUpperCase - << "(\"" - << escapeCString("^" + escapeRegex(stepName) + "$") - << "\") {\n" - << " pending();\n" - << "}\n"; + std::transform( + stepKeyword.begin(), stepKeyword.end(), std::back_inserter(stepKeywordUpperCase), ::toupper + ); + text << stepKeywordUpperCase << "(\"" << escapeCString("^" + escapeRegex(stepName) + "$") + << "\") {\n" + << " pending();\n" + << "}\n"; return text.str(); } const std::string CukeCommands::escapeRegex(const std::string reg) const { - return regex_replace(reg, std::regex("[\\|\\(\\)\\[\\]\\{\\}\\^\\$\\*\\+\\?\\.\\\\]"), "\\\\&", std::regex_constants::match_default | std::regex_constants::format_sed); + return regex_replace( + reg, + std::regex("[\\|\\(\\)\\[\\]\\{\\}\\^\\$\\*\\+\\?\\.\\\\]"), + "\\\\&", + std::regex_constants::match_default | std::regex_constants::format_sed + ); } const std::string CukeCommands::escapeCString(const std::string str) const { - return regex_replace(str, std::regex("[\"\\\\]"), "\\\\&", std::regex_constants::match_default | std::regex_constants::format_sed); + return regex_replace( + str, + std::regex("[\"\\\\]"), + "\\\\&", + std::regex_constants::match_default | std::regex_constants::format_sed + ); } MatchResult CukeCommands::stepMatches(const std::string description) const { return StepManager::stepMatches(description); } -InvokeResult CukeCommands::invoke(step_id_type id, const InvokeArgs *pArgs) { +InvokeResult CukeCommands::invoke(step_id_type id, const InvokeArgs* pArgs) { const StepInfo* const stepInfo = StepManager::getStep(id); InvokeResult result = HookRegistrar::execStepChain(currentScenario.get(), stepInfo, pArgs); HookRegistrar::execAfterStepHooks(currentScenario.get()); diff --git a/src/CukeEngine.cpp b/src/CukeEngine.cpp index 34eda122..d67cb97a 100644 --- a/src/CukeEngine.cpp +++ b/src/CukeEngine.cpp @@ -3,11 +3,11 @@ namespace cucumber { namespace internal { -InvokeException::InvokeException(const std::string & message) : +InvokeException::InvokeException(const std::string& message) : message(message) { } -InvokeException::InvokeException(const InvokeException &rhs) : +InvokeException::InvokeException(const InvokeException& rhs) : message(rhs.message) { } @@ -15,13 +15,14 @@ const std::string InvokeException::getMessage() const { return message; } - -InvokeFailureException::InvokeFailureException(const std::string & message, const std::string & exceptionType) : - InvokeException(message), - exceptionType(exceptionType) { +InvokeFailureException::InvokeFailureException( + const std::string& message, const std::string& exceptionType +) : + InvokeException(message), + exceptionType(exceptionType) { } -InvokeFailureException::InvokeFailureException(const InvokeFailureException &rhs) : +InvokeFailureException::InvokeFailureException(const InvokeFailureException& rhs) : InvokeException(rhs), exceptionType(rhs.exceptionType) { } @@ -30,16 +31,16 @@ const std::string InvokeFailureException::getExceptionType() const { return exceptionType; } - -PendingStepException::PendingStepException(const std::string & message) : - InvokeException(message) { +PendingStepException::PendingStepException(const std::string& message) : + InvokeException(message) { } -PendingStepException::PendingStepException(const PendingStepException &rhs) : +PendingStepException::PendingStepException(const PendingStepException& rhs) : InvokeException(rhs) { } -CukeEngine::CukeEngine() {} +CukeEngine::CukeEngine() { +} } } diff --git a/src/CukeEngineImpl.cpp b/src/CukeEngineImpl.cpp index 0932b7a0..c06a4e6c 100644 --- a/src/CukeEngineImpl.cpp +++ b/src/CukeEngineImpl.cpp @@ -1,34 +1,33 @@ #include "cucumber-cpp/internal/CukeEngineImpl.hpp" - namespace cucumber { namespace internal { namespace { - std::string convertId(step_id_type id) { - std::stringstream ss; - ss << id; - return ss.str(); - } +std::string convertId(step_id_type id) { + std::stringstream ss; + ss << id; + return ss.str(); +} - step_id_type convertId(const std::string & stringid) { - std::stringstream ss(stringid); - step_id_type id; - ss >> id; - return id; - } +step_id_type convertId(const std::string& stringid) { + std::stringstream ss(stringid); + step_id_type id; + ss >> id; + return id; +} } -std::vector CukeEngineImpl::stepMatches(const std::string & name) const { +std::vector CukeEngineImpl::stepMatches(const std::string& name) const { std::vector engineResult; MatchResult commandResult = cukeCommands.stepMatches(name); - for(const SingleStepMatch & commandMatch : commandResult.getResultSet()) { + for (const SingleStepMatch& commandMatch : commandResult.getResultSet()) { StepMatch engineMatch; engineMatch.id = convertId(commandMatch.stepInfo->id); engineMatch.source = commandMatch.stepInfo->source; engineMatch.regexp = commandMatch.stepInfo->regex.str(); - for(const RegexSubmatch & commandMatchArg : commandMatch.submatches) { + for (const RegexSubmatch& commandMatchArg : commandMatch.submatches) { StepMatchArg engineMatchArg; engineMatchArg.value = commandMatchArg.value; engineMatchArg.position = commandMatchArg.position; @@ -39,21 +38,23 @@ std::vector CukeEngineImpl::stepMatches(const std::string & name) con return engineResult; } -void CukeEngineImpl::beginScenario(const tags_type & tags) { +void CukeEngineImpl::beginScenario(const tags_type& tags) { cukeCommands.beginScenario(tags); } -void CukeEngineImpl::invokeStep(const std::string & id, const invoke_args_type & args, const invoke_table_type & tableArg) { +void CukeEngineImpl::invokeStep( + const std::string& id, const invoke_args_type& args, const invoke_table_type& tableArg +) { typedef invoke_table_type::index table_index; InvokeArgs commandArgs; try { - for(const std::string & a : args) { + for (const std::string& a : args) { commandArgs.addArg(a); } if (tableArg.shape()[0] > 1 && tableArg.shape()[1] > 0) { - Table & commandTableArg = commandArgs.getVariableTableArg(); + Table& commandTableArg = commandArgs.getVariableTableArg(); for (table_index j = 0; j < table_index(tableArg.shape()[1]); ++j) { commandTableArg.addColumn(tableArg[0][j]); } @@ -86,14 +87,15 @@ void CukeEngineImpl::invokeStep(const std::string & id, const invoke_args_type & } } -void CukeEngineImpl::endScenario(const tags_type & /*tags*/) { +void CukeEngineImpl::endScenario(const tags_type& /*tags*/) { cukeCommands.endScenario(); } -std::string CukeEngineImpl::snippetText(const std::string & keyword, const std::string & name, const std::string & /*multilineArgClass*/) const { +std::string CukeEngineImpl::snippetText( + const std::string& keyword, const std::string& name, const std::string& /*multilineArgClass*/ +) const { return cukeCommands.snippetText(keyword, name); } - } } diff --git a/src/HookRegistrar.cpp b/src/HookRegistrar.cpp index 71ac9951..e07ef683 100644 --- a/src/HookRegistrar.cpp +++ b/src/HookRegistrar.cpp @@ -4,7 +4,7 @@ namespace cucumber { namespace internal { -void Hook::invokeHook(Scenario *scenario, CallableStep *) { +void Hook::invokeHook(Scenario* scenario, CallableStep*) { if (tagsMatch(scenario)) { body(); } else { @@ -15,15 +15,15 @@ void Hook::invokeHook(Scenario *scenario, CallableStep *) { void Hook::skipHook() { } -void Hook::setTags(const std::string &csvTagNotation) { +void Hook::setTags(const std::string& csvTagNotation) { tagExpression = AndTagExpression(csvTagNotation); } -bool Hook::tagsMatch(Scenario *scenario) { +bool Hook::tagsMatch(Scenario* scenario) { return !scenario || tagExpression.matches(scenario->getTags()); } -void AroundStepHook::invokeHook(Scenario *scenario, CallableStep *step) { +void AroundStepHook::invokeHook(Scenario* scenario, CallableStep* step) { this->step = step; Hook::invokeHook(scenario, NULL); } @@ -32,7 +32,7 @@ void AroundStepHook::skipHook() { step->call(); } -void UnconditionalHook::invokeHook(Scenario*, CallableStep *) { +void UnconditionalHook::invokeHook(Scenario*, CallableStep*) { body(); } @@ -45,11 +45,10 @@ HookRegistrar::hook_list_type& HookRegistrar::beforeHooks() { return beforeHooks; } -void HookRegistrar::execBeforeHooks(Scenario *scenario) { +void HookRegistrar::execBeforeHooks(Scenario* scenario) { execHooks(beforeHooks(), scenario); } - void HookRegistrar::addAroundStepHook(std::shared_ptr aroundStepHook) { aroundStepHooks().push_front(aroundStepHook); } @@ -59,7 +58,9 @@ HookRegistrar::aroundhook_list_type& HookRegistrar::aroundStepHooks() { return aroundStepHooks; } -InvokeResult HookRegistrar::execStepChain(Scenario *scenario, const StepInfo* const stepInfo, const InvokeArgs *pArgs) { +InvokeResult HookRegistrar::execStepChain( + Scenario* scenario, const StepInfo* const stepInfo, const InvokeArgs* pArgs +) { StepCallChain scc(scenario, stepInfo, pArgs, aroundStepHooks()); return scc.exec(); } @@ -73,11 +74,10 @@ HookRegistrar::hook_list_type& HookRegistrar::afterStepHooks() { return afterStepHooks; } -void HookRegistrar::execAfterStepHooks(Scenario *scenario) { +void HookRegistrar::execAfterStepHooks(Scenario* scenario) { execHooks(afterStepHooks(), scenario); } - void HookRegistrar::addAfterHook(std::shared_ptr afterHook) { afterHooks().push_front(afterHook); } @@ -87,13 +87,13 @@ HookRegistrar::hook_list_type& HookRegistrar::afterHooks() { return afterHooks; } -void HookRegistrar::execAfterHooks(Scenario *scenario) { +void HookRegistrar::execAfterHooks(Scenario* scenario) { execHooks(afterHooks(), scenario); } - -void HookRegistrar::execHooks(HookRegistrar::hook_list_type &hookList, Scenario *scenario) { - for (HookRegistrar::hook_list_type::iterator hook = hookList.begin(); hook != hookList.end(); ++hook) { +void HookRegistrar::execHooks(HookRegistrar::hook_list_type& hookList, Scenario* scenario) { + for (HookRegistrar::hook_list_type::iterator hook = hookList.begin(); hook != hookList.end(); + ++hook) { (*hook)->invokeHook(scenario, NULL); } } @@ -124,17 +124,15 @@ void HookRegistrar::execAfterAllHooks() { execHooks(afterAllHooks(), NULL); } - StepCallChain::StepCallChain( - Scenario *scenario, + Scenario* scenario, const StepInfo* const stepInfo, - const InvokeArgs *pStepArgs, - HookRegistrar::aroundhook_list_type &aroundHooks + const InvokeArgs* pStepArgs, + HookRegistrar::aroundhook_list_type& aroundHooks ) : scenario(scenario), stepInfo(stepInfo), - pStepArgs(pStepArgs) -{ + pStepArgs(pStepArgs) { nextHook = aroundHooks.begin(); hookEnd = aroundHooks.end(); } @@ -160,12 +158,13 @@ void StepCallChain::execStep() { } } -CallableStepChain::CallableStepChain(StepCallChain* scc) : scc(scc) {} +CallableStepChain::CallableStepChain(StepCallChain* scc) : + scc(scc) { +} void CallableStepChain::call() { scc->execNext(); } - } } diff --git a/src/Regex.cpp b/src/Regex.cpp index d07dddd1..19a9a9d5 100644 --- a/src/Regex.cpp +++ b/src/Regex.cpp @@ -14,7 +14,7 @@ bool RegexMatch::matches() { return regexMatched; } -const RegexMatch::submatches_type & RegexMatch::getSubmatches() { +const RegexMatch::submatches_type& RegexMatch::getSubmatches() { return submatches; } @@ -22,7 +22,7 @@ std::string Regex::str() const { return regexString; } -std::shared_ptr Regex::find(const std::string &expression) const { +std::shared_ptr Regex::find(const std::string& expression) const { return std::make_shared(regexImpl, expression); } @@ -31,8 +31,9 @@ bool isUtf8CodeUnitStartOfCodepoint(unsigned int i) { return (i & 0xc0) != 0x80; } -std::ptrdiff_t utf8CodepointOffset(const std::string& expression, - const std::string::const_iterator& it) { +std::ptrdiff_t utf8CodepointOffset( + const std::string& expression, const std::string::const_iterator& it +) { return count_if(expression.begin(), it, &isUtf8CodeUnitStartOfCodepoint); } } // namespace @@ -56,12 +57,14 @@ FindRegexMatch::FindRegexMatch(const std::regex& regexImpl, const std::string& e } } -std::shared_ptr Regex::findAll(const std::string &expression) const { +std::shared_ptr Regex::findAll(const std::string& expression) const { return std::make_shared(regexImpl, expression); } -FindAllRegexMatch::FindAllRegexMatch(const std::regex ®exImpl, const std::string &expression) { - std::sregex_token_iterator i(expression.begin(), expression.end(), regexImpl, 1, std::regex_constants::match_continuous); +FindAllRegexMatch::FindAllRegexMatch(const std::regex& regexImpl, const std::string& expression) { + std::sregex_token_iterator i( + expression.begin(), expression.end(), regexImpl, 1, std::regex_constants::match_continuous + ); const std::sregex_token_iterator end; for (; i != end; ++i) { RegexSubmatch s = {*i, -1}; diff --git a/src/Scenario.cpp b/src/Scenario.cpp index 677aa8c4..f69f34b5 100644 --- a/src/Scenario.cpp +++ b/src/Scenario.cpp @@ -3,9 +3,11 @@ namespace cucumber { namespace internal { -Scenario::Scenario(const TagExpression::tag_list& tags) : tags(tags) {} +Scenario::Scenario(const TagExpression::tag_list& tags) : + tags(tags) { +} -const TagExpression::tag_list & Scenario::getTags() { +const TagExpression::tag_list& Scenario::getTags() { return tags; } diff --git a/src/StepManager.cpp b/src/StepManager.cpp index fbf99c5f..b1b7932c 100644 --- a/src/StepManager.cpp +++ b/src/StepManager.cpp @@ -3,15 +3,14 @@ namespace cucumber { namespace internal { - -StepInfo::StepInfo(const std::string &stepMatcher, const std::string source) : +StepInfo::StepInfo(const std::string& stepMatcher, const std::string source) : regex(stepMatcher), source(source) { static step_id_type currentId = 0; id = ++currentId; } -SingleStepMatch StepInfo::matches(const std::string &stepDescription) const { +SingleStepMatch StepInfo::matches(const std::string& stepDescription) const { SingleStepMatch stepMatch; std::shared_ptr regexMatch(regex.find(stepDescription)); if (regexMatch->matches()) { @@ -21,7 +20,7 @@ SingleStepMatch StepInfo::matches(const std::string &stepDescription) const { return stepMatch; } -SingleStepMatch::operator const void *() const { +SingleStepMatch::operator const void*() const { return stepInfo.get(); } @@ -37,35 +36,35 @@ void MatchResult::addMatch(SingleStepMatch match) { resultSet.push_back(match); } - void InvokeArgs::addArg(const std::string arg) { args.push_back(arg); } -const Table & InvokeArgs::getTableArg() const { +const Table& InvokeArgs::getTableArg() const { return tableArg; } -Table & InvokeArgs::getVariableTableArg() { +Table& InvokeArgs::getVariableTableArg() { return tableArg; } - -InvokeResult::InvokeResult(const InvokeResultType type, const char *description) : +InvokeResult::InvokeResult(const InvokeResultType type, const char* description) : type(type) { - if (description) { this->description = description; }; + if (description) { + this->description = description; + }; } InvokeResult::InvokeResult() : type(FAILURE) { } -InvokeResult::InvokeResult(const InvokeResult &ir) : +InvokeResult::InvokeResult(const InvokeResult& ir) : type(ir.type), description(ir.description) { } -InvokeResult& InvokeResult::operator= (const InvokeResult &rhs) { +InvokeResult& InvokeResult::operator=(const InvokeResult& rhs) { this->type = rhs.type; this->description = rhs.description; return *this; @@ -75,15 +74,15 @@ InvokeResult InvokeResult::success() { return InvokeResult(SUCCESS, 0); } -InvokeResult InvokeResult::failure(const char *description) { +InvokeResult InvokeResult::failure(const char* description) { return InvokeResult(FAILURE, description); } -InvokeResult InvokeResult::failure(const std::string &description) { +InvokeResult InvokeResult::failure(const std::string& description) { return InvokeResult(FAILURE, description.c_str()); } -InvokeResult InvokeResult::pending(const char *description) { +InvokeResult InvokeResult::pending(const char* description) { return InvokeResult(PENDING, description); } @@ -99,16 +98,15 @@ InvokeResultType InvokeResult::getType() const { return type; } -const std::string &InvokeResult::getDescription() const { +const std::string& InvokeResult::getDescription() const { return description; } - step_id_type StepManager::addStep(std::shared_ptr stepInfo) { return steps().insert(std::make_pair(stepInfo->id, stepInfo)).first->first; } -MatchResult StepManager::stepMatches(const std::string &stepDescription) { +MatchResult StepManager::stepMatches(const std::string& stepDescription) { MatchResult matchResult; for (steps_type::iterator iter = steps().begin(); iter != steps().end(); ++iter) { const std::shared_ptr& stepInfo = iter->second; @@ -137,8 +135,7 @@ StepManager::steps_type& StepManager::steps() { return steps; } - -InvokeResult BasicStep::invoke(const InvokeArgs *pArgs) { +InvokeResult BasicStep::invoke(const InvokeArgs* pArgs) { this->pArgs = pArgs; currentArgIndex = 0; currentResult = InvokeResult::success(); @@ -153,7 +150,7 @@ InvokeResult BasicStep::invoke(const InvokeArgs *pArgs) { return InvokeResult::failure(ex.what()); } catch (const std::string& ex) { return InvokeResult::failure(ex); - } catch (const char *ex) { + } catch (const char* ex) { return InvokeResult::failure(ex); } catch (...) { // Cucumber needs a description here @@ -165,14 +162,13 @@ void BasicStep::pending() { pending(0); } -void BasicStep::pending(const char *description) { +void BasicStep::pending(const char* description) { currentResult = InvokeResult::pending(description); } -const InvokeArgs *BasicStep::getArgs() { +const InvokeArgs* BasicStep::getArgs() { return pArgs; } } } - diff --git a/src/Table.cpp b/src/Table.cpp index 75826fff..7464bccc 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -11,7 +11,7 @@ void Table::addColumn(const std::string column) { } } -void Table::addRow(const row_type &row) { +void Table::addRow(const row_type& row) { const basic_type::size_type colSize = columns.size(); if (colSize == 0) { throw std::runtime_error("No column defined yet"); @@ -22,7 +22,7 @@ void Table::addRow(const row_type &row) { } } -Table::hash_row_type Table::buildHashRow(const row_type &row) { +Table::hash_row_type Table::buildHashRow(const row_type& row) { hash_row_type hashRow; for (columns_type::size_type i = 0; i < columns.size(); ++i) { hashRow[columns[i]] = row[i]; @@ -30,7 +30,7 @@ Table::hash_row_type Table::buildHashRow(const row_type &row) { return hashRow; } -const Table::hashes_type & Table::hashes() const { +const Table::hashes_type& Table::hashes() const { return rows; } diff --git a/src/Tag.cpp b/src/Tag.cpp index c8a8bf26..73ca102b 100644 --- a/src/Tag.cpp +++ b/src/Tag.cpp @@ -4,45 +4,48 @@ namespace cucumber { namespace internal { -Regex & AndTagExpression::csvTagNotationRegex() { +Regex& AndTagExpression::csvTagNotationRegex() { static Regex r("\\s*\"([^\"]+)\"\\s*(?:,|$)"); return r; } -AndTagExpression::AndTagExpression(const std::string &csvTagNotation) { +AndTagExpression::AndTagExpression(const std::string& csvTagNotation) { const std::shared_ptr match(csvTagNotationRegex().findAll(csvTagNotation)); const RegexMatch::submatches_type submatches = match->getSubmatches(); orExpressions.reserve(submatches.size()); - for (RegexMatch::submatches_type::const_iterator i = submatches.begin(); i != submatches.end(); ++i) { + for (RegexMatch::submatches_type::const_iterator i = submatches.begin(); i != submatches.end(); + ++i) { const std::string orCsvTagNotation = i->value; orExpressions.push_back(OrTagExpression(orCsvTagNotation)); } } -bool AndTagExpression::matches(const tag_list &tags) const { +bool AndTagExpression::matches(const tag_list& tags) const { bool match = true; - for (or_expressions_type::const_iterator i = orExpressions.begin(); i != orExpressions.end() && match; ++i) { + for (or_expressions_type::const_iterator i = orExpressions.begin(); + i != orExpressions.end() && match; + ++i) { match &= i->matches(tags); } return match; } - -Regex & OrTagExpression::csvTagNotationRegex() { +Regex& OrTagExpression::csvTagNotationRegex() { static Regex r("\\s*@(\\w+)\\s*(?:,|$)"); return r; } -OrTagExpression::OrTagExpression(const std::string &csvTagNotation) { +OrTagExpression::OrTagExpression(const std::string& csvTagNotation) { const std::shared_ptr match(csvTagNotationRegex().findAll(csvTagNotation)); const RegexMatch::submatches_type submatches = match->getSubmatches(); orTags.reserve(submatches.size()); - for (RegexMatch::submatches_type::const_iterator i = submatches.begin(); i != submatches.end(); ++i) { + for (RegexMatch::submatches_type::const_iterator i = submatches.begin(); i != submatches.end(); + ++i) { orTags.push_back(i->value); } } -bool OrTagExpression::matches(const tag_list &tags) const { +bool OrTagExpression::matches(const tag_list& tags) const { for (tag_list::const_iterator i = orTags.begin(); i != orTags.end(); ++i) { if (orTagMatchesTagList(*i, tags)) return true; @@ -50,7 +53,8 @@ bool OrTagExpression::matches(const tag_list &tags) const { return false; } -bool OrTagExpression::orTagMatchesTagList(const std::string ¤tOrTag, const tag_list &tags) const { +bool OrTagExpression::orTagMatchesTagList(const std::string& currentOrTag, const tag_list& tags) + const { for (tag_list::const_iterator i = tags.begin(); i != tags.end(); ++i) { if (*i == currentOrTag) return true; diff --git a/src/connectors/wire/WireProtocol.cpp b/src/connectors/wire/WireProtocol.cpp index dc35a9f7..f13fcc03 100644 --- a/src/connectors/wire/WireProtocol.cpp +++ b/src/connectors/wire/WireProtocol.cpp @@ -14,17 +14,15 @@ using namespace json_spirit; namespace cucumber { namespace internal { - /* * Responses */ - void SuccessResponse::accept(WireResponseVisitor& visitor) const { visitor.visit(*this); } -FailureResponse::FailureResponse(const std::string & message, const std::string & exceptionType) : +FailureResponse::FailureResponse(const std::string& message, const std::string& exceptionType) : message(message), exceptionType(exceptionType) { } @@ -41,7 +39,7 @@ void FailureResponse::accept(WireResponseVisitor& visitor) const { visitor.visit(*this); } -PendingResponse::PendingResponse(const std::string & message) : +PendingResponse::PendingResponse(const std::string& message) : message(message) { } @@ -53,8 +51,8 @@ void PendingResponse::accept(WireResponseVisitor& visitor) const { visitor.visit(*this); } -StepMatchesResponse::StepMatchesResponse(const std::vector & matchingSteps) - : matchingSteps(matchingSteps) { +StepMatchesResponse::StepMatchesResponse(const std::vector& matchingSteps) : + matchingSteps(matchingSteps) { } const std::vector& StepMatchesResponse::getMatchingSteps() const { @@ -65,7 +63,7 @@ void StepMatchesResponse::accept(WireResponseVisitor& visitor) const { visitor.visit(*this); } -SnippetTextResponse::SnippetTextResponse(const std::string & stepSnippet) : +SnippetTextResponse::SnippetTextResponse(const std::string& stepSnippet) : stepSnippet(stepSnippet) { } @@ -77,114 +75,112 @@ void SnippetTextResponse::accept(WireResponseVisitor& visitor) const { visitor.visit(*this); } - /* * Command decoders */ - namespace { - typedef std::shared_ptr (*CommandDecoder)(const mValue& jsonArgs); - - CukeEngine::tags_type getScenarioTags(const mValue& jsonArgs) { - CukeEngine::tags_type tags; - if (!jsonArgs.is_null()) { - const mArray & jsonTags = jsonArgs.get_obj().find("tags")->second.get_array(); - for (mArray::const_iterator i = jsonTags.begin(); i != jsonTags.end(); ++i) { - tags.push_back(i->get_str()); - } +typedef std::shared_ptr (*CommandDecoder)(const mValue& jsonArgs); + +CukeEngine::tags_type getScenarioTags(const mValue& jsonArgs) { + CukeEngine::tags_type tags; + if (!jsonArgs.is_null()) { + const mArray& jsonTags = jsonArgs.get_obj().find("tags")->second.get_array(); + for (mArray::const_iterator i = jsonTags.begin(); i != jsonTags.end(); ++i) { + tags.push_back(i->get_str()); } - return tags; } + return tags; +} - std::shared_ptr BeginScenarioDecoder(const mValue& jsonArgs) { - return std::make_shared(getScenarioTags(jsonArgs)); - } +std::shared_ptr BeginScenarioDecoder(const mValue& jsonArgs) { + return std::make_shared(getScenarioTags(jsonArgs)); +} - std::shared_ptr EndScenarioDecoder(const mValue& jsonArgs) { - return std::make_shared(getScenarioTags(jsonArgs)); - } +std::shared_ptr EndScenarioDecoder(const mValue& jsonArgs) { + return std::make_shared(getScenarioTags(jsonArgs)); +} - std::shared_ptr StepMatchesDecoder(const mValue& jsonArgs) { - mObject stepMatchesArgs(jsonArgs.get_obj()); - const std::string& nameToMatch(stepMatchesArgs["name_to_match"].get_str()); - return std::make_shared(nameToMatch); - } +std::shared_ptr StepMatchesDecoder(const mValue& jsonArgs) { + mObject stepMatchesArgs(jsonArgs.get_obj()); + const std::string& nameToMatch(stepMatchesArgs["name_to_match"].get_str()); + return std::make_shared(nameToMatch); +} - void fillTableArg(const mArray& jsonTableArg, CukeEngine::invoke_table_type& tableArg) { - typedef mArray::size_type size_type; - size_type rows = jsonTableArg.size(); - if (rows > 0) { - size_type columns = jsonTableArg[0].get_array().size(); - tableArg.resize(boost::extents[rows][columns]); - for (size_type i = 0; i < rows; ++i) { - const mArray & jsonRow(jsonTableArg[i].get_array()); - if (jsonRow.size() == columns) { - for (size_type j = 0; j < columns; ++j) { - tableArg[i][j] = jsonRow[j].get_str(); - } - } else { - // TODO: Invalid row +void fillTableArg(const mArray& jsonTableArg, CukeEngine::invoke_table_type& tableArg) { + typedef mArray::size_type size_type; + size_type rows = jsonTableArg.size(); + if (rows > 0) { + size_type columns = jsonTableArg[0].get_array().size(); + tableArg.resize(boost::extents[rows][columns]); + for (size_type i = 0; i < rows; ++i) { + const mArray& jsonRow(jsonTableArg[i].get_array()); + if (jsonRow.size() == columns) { + for (size_type j = 0; j < columns; ++j) { + tableArg[i][j] = jsonRow[j].get_str(); } + } else { + // TODO: Invalid row } - } else { - // TODO: Invalid table (no column specified) } + } else { + // TODO: Invalid table (no column specified) } +} - void fillInvokeArgs( - const mObject& invokeParams, - CukeEngine::invoke_args_type& args, - CukeEngine::invoke_table_type& tableArg) { - const mArray & jsonArgs(invokeParams.find("args")->second.get_array()); - for (mArray::const_iterator i = jsonArgs.begin(); i != jsonArgs.end(); ++i) { - if (i->type() == str_type) { - args.push_back(i->get_str()); - } else if (i->type() == array_type) { - fillTableArg(i->get_array(), tableArg); - } +void fillInvokeArgs( + const mObject& invokeParams, + CukeEngine::invoke_args_type& args, + CukeEngine::invoke_table_type& tableArg +) { + const mArray& jsonArgs(invokeParams.find("args")->second.get_array()); + for (mArray::const_iterator i = jsonArgs.begin(); i != jsonArgs.end(); ++i) { + if (i->type() == str_type) { + args.push_back(i->get_str()); + } else if (i->type() == array_type) { + fillTableArg(i->get_array(), tableArg); } } +} - std::shared_ptr InvokeDecoder(const mValue& jsonArgs) { - mObject invokeParams(jsonArgs.get_obj()); +std::shared_ptr InvokeDecoder(const mValue& jsonArgs) { + mObject invokeParams(jsonArgs.get_obj()); - CukeEngine::invoke_args_type args; - CukeEngine::invoke_table_type tableArg; - const std::string & id(invokeParams["id"].get_str()); - fillInvokeArgs(invokeParams, args, tableArg); - return std::make_shared(id, args, tableArg); - } + CukeEngine::invoke_args_type args; + CukeEngine::invoke_table_type tableArg; + const std::string& id(invokeParams["id"].get_str()); + fillInvokeArgs(invokeParams, args, tableArg); + return std::make_shared(id, args, tableArg); +} - std::shared_ptr SnippetTextDecoder(const mValue& jsonArgs) { - mObject snippetTextArgs(jsonArgs.get_obj()); - const std::string & stepKeyword(snippetTextArgs["step_keyword"].get_str()); - const std::string & stepName(snippetTextArgs["step_name"].get_str()); - const std::string & multilineArgClass(snippetTextArgs["multiline_arg_class"].get_str()); - return std::make_shared(stepKeyword, stepName, multilineArgClass); - } +std::shared_ptr SnippetTextDecoder(const mValue& jsonArgs) { + mObject snippetTextArgs(jsonArgs.get_obj()); + const std::string& stepKeyword(snippetTextArgs["step_keyword"].get_str()); + const std::string& stepName(snippetTextArgs["step_name"].get_str()); + const std::string& multilineArgClass(snippetTextArgs["multiline_arg_class"].get_str()); + return std::make_shared(stepKeyword, stepName, multilineArgClass); +} } static const std::map commandDecodersMap = { {"begin_scenario", BeginScenarioDecoder}, - {"end_scenario" , EndScenarioDecoder }, - {"step_matches" , StepMatchesDecoder }, - {"invoke" , InvokeDecoder }, - {"snippet_text" , SnippetTextDecoder }, + {"end_scenario", EndScenarioDecoder}, + {"step_matches", StepMatchesDecoder}, + {"invoke", InvokeDecoder}, + {"snippet_text", SnippetTextDecoder}, }; -std::shared_ptr JsonSpiritWireMessageCodec::decode(const std::string &request) const { +std::shared_ptr JsonSpiritWireMessageCodec::decode(const std::string& request) const { std::istringstream is(request); mValue json; try { read_stream(is, json); - mArray & jsonRequest = json.get_array(); - mValue & jsonCommand = jsonRequest[0]; + mArray& jsonRequest = json.get_array(); + mValue& jsonCommand = jsonRequest[0]; - const std::map::const_iterator - commandDecoder = commandDecodersMap.find(jsonCommand.get_str()); - if (commandDecoder != commandDecodersMap.end() - && commandDecoder->second) { + const std::map::const_iterator commandDecoder + = commandDecodersMap.find(jsonCommand.get_str()); + if (commandDecoder != commandDecodersMap.end() && commandDecoder->second) { mValue jsonArgs; if (jsonRequest.size() > 1) { jsonArgs = jsonRequest[1]; @@ -199,89 +195,90 @@ std::shared_ptr JsonSpiritWireMessageCodec::decode(const std::strin namespace { - class WireResponseEncoder : public WireResponseVisitor { - private: - mArray jsonOutput; +class WireResponseEncoder : public WireResponseVisitor { +private: + mArray jsonOutput; - void success(const mValue *detail = 0) { - output("success", detail); - } + void success(const mValue* detail = 0) { + output("success", detail); + } - void fail(const mValue *detail = 0) { - output("fail", detail); - } + void fail(const mValue* detail = 0) { + output("fail", detail); + } - void output(const char *responseType, const mValue *detail = 0) { - jsonOutput.push_back(responseType); - if (detail == 0 || detail->is_null()) { - return; - } - jsonOutput.push_back(*detail); + void output(const char* responseType, const mValue* detail = 0) { + jsonOutput.push_back(responseType); + if (detail == 0 || detail->is_null()) { + return; } + jsonOutput.push_back(*detail); + } - public: - std::string encode(const WireResponse& response) { - jsonOutput.clear(); - response.accept(*this); - const mValue v(jsonOutput); - return write_string(v, ::raw_utf8); - } +public: + std::string encode(const WireResponse& response) { + jsonOutput.clear(); + response.accept(*this); + const mValue v(jsonOutput); + return write_string(v, ::raw_utf8); + } - void visit(const SuccessResponse& /*response*/) override { - success(); - } + void visit(const SuccessResponse& /*response*/) override { + success(); + } - void visit(const FailureResponse& response) override { - mObject detailObject; - if (!response.getMessage().empty()) { - detailObject["message"] = response.getMessage(); - } - if (!response.getExceptionType().empty()) { - detailObject["exception"] = response.getExceptionType(); - } - if (detailObject.empty()) { - fail(); - } else { - const mValue detail(detailObject); - fail(&detail); - } + void visit(const FailureResponse& response) override { + mObject detailObject; + if (!response.getMessage().empty()) { + detailObject["message"] = response.getMessage(); } - - void visit(const PendingResponse& response) override { - mValue jsonReponse(response.getMessage()); - output("pending", &jsonReponse); + if (!response.getExceptionType().empty()) { + detailObject["exception"] = response.getExceptionType(); } + if (detailObject.empty()) { + fail(); + } else { + const mValue detail(detailObject); + fail(&detail); + } + } - void visit(const StepMatchesResponse& response) override { - mArray jsonMatches; - for(const StepMatch & m : response.getMatchingSteps()) { - mObject jsonM; - jsonM["id"] = m.id; - mArray jsonArgs; - for(const StepMatchArg & ma : m.args) { - mObject jsonMa; - jsonMa["val"] = ma.value; - jsonMa["pos"] = static_cast(ma.position); - jsonArgs.push_back(jsonMa); - } - jsonM["args"] = jsonArgs; - if (!m.source.empty()) { - jsonM["source"] = m.source;; - } - if (!m.regexp.empty()) { - jsonM["regexp"] = m.regexp; - } - jsonMatches.push_back(jsonM); + void visit(const PendingResponse& response) override { + mValue jsonReponse(response.getMessage()); + output("pending", &jsonReponse); + } + + void visit(const StepMatchesResponse& response) override { + mArray jsonMatches; + for (const StepMatch& m : response.getMatchingSteps()) { + mObject jsonM; + jsonM["id"] = m.id; + mArray jsonArgs; + for (const StepMatchArg& ma : m.args) { + mObject jsonMa; + jsonMa["val"] = ma.value; + jsonMa["pos"] = static_cast(ma.position); + jsonArgs.push_back(jsonMa); + } + jsonM["args"] = jsonArgs; + if (!m.source.empty()) { + jsonM["source"] = m.source; + ; + } + if (!m.regexp.empty()) { + jsonM["regexp"] = m.regexp; } - mValue jsonReponse(jsonMatches); - output("success", &jsonReponse); + jsonMatches.push_back(jsonM); } + mValue jsonReponse(jsonMatches); + output("success", &jsonReponse); + } - void visit(const SnippetTextResponse& response) override { - mValue jsonReponse(response.getStepSnippet()); - success(&jsonReponse); - } - }; + void visit(const SnippetTextResponse& response) override { + mValue jsonReponse(response.getStepSnippet()); + success(&jsonReponse); + } +}; } @@ -299,7 +296,7 @@ WireProtocolHandler::WireProtocolHandler(const WireMessageCodec& codec, CukeEngi engine(engine) { } -std::string WireProtocolHandler::handle(const std::string &request) const { +std::string WireProtocolHandler::handle(const std::string& request) const { std::string response; // LOG request try { @@ -313,5 +310,5 @@ std::string WireProtocolHandler::handle(const std::string &request) const { return response; } -} -} +} // namespace internal +} // namespace cucumber diff --git a/src/connectors/wire/WireProtocolCommands.cpp b/src/connectors/wire/WireProtocolCommands.cpp index 6138a620..d184231e 100644 --- a/src/connectors/wire/WireProtocolCommands.cpp +++ b/src/connectors/wire/WireProtocolCommands.cpp @@ -7,7 +7,6 @@ ScenarioCommand::ScenarioCommand(const CukeEngine::tags_type& tags) : tags(tags) { } - BeginScenarioCommand::BeginScenarioCommand(const CukeEngine::tags_type& tags) : ScenarioCommand(tags) { } @@ -17,7 +16,6 @@ std::shared_ptr BeginScenarioCommand::run(CukeEngine& engine) cons return std::make_shared(); } - EndScenarioCommand::EndScenarioCommand(const CukeEngine::tags_type& tags) : ScenarioCommand(tags) { } @@ -27,8 +25,7 @@ std::shared_ptr EndScenarioCommand::run(CukeEngine& engine) const return std::make_shared(); } - -StepMatchesCommand::StepMatchesCommand(const std::string & stepName) : +StepMatchesCommand::StepMatchesCommand(const std::string& stepName) : stepName(stepName) { } @@ -37,10 +34,11 @@ std::shared_ptr StepMatchesCommand::run(CukeEngine& engine) const return std::make_shared(matchingSteps); } - -InvokeCommand::InvokeCommand(const std::string & stepId, - const CukeEngine::invoke_args_type& args, - const CukeEngine::invoke_table_type& tableArg) : +InvokeCommand::InvokeCommand( + const std::string& stepId, + const CukeEngine::invoke_args_type& args, + const CukeEngine::invoke_table_type& tableArg +) : stepId(stepId), args(args), tableArg(tableArg) { @@ -59,18 +57,20 @@ std::shared_ptr InvokeCommand::run(CukeEngine& engine) const { } } - -SnippetTextCommand::SnippetTextCommand(const std::string & keyword, const std::string & name, const std::string & multilineArgClass) : +SnippetTextCommand::SnippetTextCommand( + const std::string& keyword, const std::string& name, const std::string& multilineArgClass +) : keyword(keyword), name(name), multilineArgClass(multilineArgClass) { } std::shared_ptr SnippetTextCommand::run(CukeEngine& engine) const { - return std::make_shared(engine.snippetText(keyword, name, multilineArgClass)); + return std::make_shared( + engine.snippetText(keyword, name, multilineArgClass) + ); } - std::shared_ptr FailingCommand::run(CukeEngine& /*engine*/) const { return std::make_shared(); } diff --git a/src/connectors/wire/WireServer.cpp b/src/connectors/wire/WireServer.cpp index e31a9562..df88e5df 100644 --- a/src/connectors/wire/WireServer.cpp +++ b/src/connectors/wire/WireServer.cpp @@ -10,19 +10,21 @@ using namespace boost::asio::ip; using namespace boost::asio::local; #endif -SocketServer::SocketServer(const ProtocolHandler *protocolHandler) : +SocketServer::SocketServer(const ProtocolHandler* protocolHandler) : protocolHandler(protocolHandler), ios() { } #if BOOST_VERSION <= 106500 -template -void SocketServer::doListen(basic_socket_acceptor& acceptor, - const typename Protocol::endpoint& endpoint) { +template +void SocketServer::doListen( + basic_socket_acceptor& acceptor, const typename Protocol::endpoint& endpoint +) { #else -template -void SocketServer::doListen(basic_socket_acceptor& acceptor, - const typename Protocol::endpoint& endpoint) { +template +void SocketServer::doListen( + basic_socket_acceptor& acceptor, const typename Protocol::endpoint& endpoint +) { #endif if (acceptor.is_open()) throw boost::system::system_error(boost::asio::error::already_open); @@ -33,10 +35,10 @@ void SocketServer::doListen(basic_socket_acceptor& acceptor, } #if BOOST_VERSION <= 106500 -template +template void SocketServer::doAcceptOnce(basic_socket_acceptor& acceptor) { #else -template +template void SocketServer::doAcceptOnce(basic_socket_acceptor& acceptor) { #endif typename Protocol::iostream stream; @@ -51,7 +53,7 @@ void SocketServer::processStream(std::iostream& stream) { } } -TCPSocketServer::TCPSocketServer(const ProtocolHandler *protocolHandler) : +TCPSocketServer::TCPSocketServer(const ProtocolHandler* protocolHandler) : SocketServer(protocolHandler), acceptor(ios) { } @@ -74,7 +76,7 @@ void TCPSocketServer::acceptOnce() { } #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) -UnixSocketServer::UnixSocketServer(const ProtocolHandler *protocolHandler) : +UnixSocketServer::UnixSocketServer(const ProtocolHandler* protocolHandler) : SocketServer(protocolHandler), acceptor(ios) { } @@ -98,7 +100,8 @@ UnixSocketServer::~UnixSocketServer() { if (!acceptor.is_open()) return; std::string path = acceptor.local_endpoint().path(); - // NOTE: this will fail if this path got deleted manually or represents an abstract-namespace socket + // NOTE: this will fail if this path got deleted manually or represents an abstract-namespace + // socket std::filesystem::remove(path); } #endif diff --git a/src/drivers/BoostDriver.cpp b/src/drivers/BoostDriver.cpp index 9213c55b..6fa75ade 100644 --- a/src/drivers/BoostDriver.cpp +++ b/src/drivers/BoostDriver.cpp @@ -14,18 +14,16 @@ using ::boost::execution_exception; namespace cucumber { namespace internal { - namespace { - test_case* testCase = 0; - boost::function currentTestBody; +test_case* testCase = 0; +boost::function currentTestBody; - void exec_test_body() { - if (currentTestBody) { - currentTestBody(); - } +void exec_test_body() { + if (currentTestBody) { + currentTestBody(); } - +} bool boost_test_init() { testCase = BOOST_TEST_CASE(&exec_test_body); @@ -35,44 +33,50 @@ bool boost_test_init() { } // Freed by Boost's unit test framework on exit -static CukeBoostLogInterceptor *logInterceptor = 0; +static CukeBoostLogInterceptor* logInterceptor = 0; } - class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatter { public: const InvokeResult getResult() const; void reset(); // Formatter - void log_start( std::ostream&, counter_t /*test_cases_amount*/) override {}; - void log_finish( std::ostream&) override {}; + void log_start(std::ostream&, counter_t /*test_cases_amount*/) override{}; + void log_finish(std::ostream&) override{}; #if BOOST_VERSION >= 107000 - void log_build_info(std::ostream&, bool /*log_build_info*/) override {}; + void log_build_info(std::ostream&, bool /*log_build_info*/) override{}; #else - void log_build_info( std::ostream&) override {}; + void log_build_info(std::ostream&) override{}; #endif - void test_unit_start( std::ostream&, test_unit const& /*tu*/) override {}; - void test_unit_finish( std::ostream&, test_unit const& /*tu*/, unsigned long /*elapsed*/) override {}; - void test_unit_skipped( std::ostream&, test_unit const& /*tu*/) override {}; + void test_unit_start(std::ostream&, test_unit const& /*tu*/) override{}; + void test_unit_finish(std::ostream&, test_unit const& /*tu*/, unsigned long /*elapsed*/) + override{}; + void test_unit_skipped(std::ostream&, test_unit const& /*tu*/) override{}; - void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const&) override {}; - void log_exception_finish( std::ostream& ) override {}; + void log_exception_start(std::ostream&, log_checkpoint_data const&, execution_exception const&) + override{}; + void log_exception_finish(std::ostream&) override{}; - void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types /*let*/) override {}; - void log_entry_value( std::ostream&, const_string value) override; - void log_entry_value( std::ostream&, lazy_ostream const& value) override; - void log_entry_finish( std::ostream&) override {}; + void log_entry_start(std::ostream&, log_entry_data const&, log_entry_types /*let*/) override{}; + void log_entry_value(std::ostream&, const_string value) override; + void log_entry_value(std::ostream&, lazy_ostream const& value) override; + void log_entry_finish(std::ostream&) override{}; - void entry_context_start( std::ostream&, log_level /*l*/) override {} + void entry_context_start(std::ostream&, log_level /*l*/) override { + } #if BOOST_VERSION >= 106500 - void log_entry_context( std::ostream&, log_level /*l*/, const_string /*value*/) override {} - void entry_context_finish( std::ostream&, log_level /*l*/ ) override {} + void log_entry_context(std::ostream&, log_level /*l*/, const_string /*value*/) override { + } + void entry_context_finish(std::ostream&, log_level /*l*/) override { + } #else - void log_entry_context( std::ostream&, const_string /*value*/) override {} - void entry_context_finish( std::ostream& ) override {} + void log_entry_context(std::ostream&, const_string /*value*/) override { + } + void entry_context_finish(std::ostream&) override { + } #endif private: @@ -115,12 +119,12 @@ const InvokeResult BoostStep::invokeStepBody() { void BoostStep::initBoostTest() { int argc = 1; char dummyArg[] = "dummy"; - char *argv[] = { dummyArg }; + char* argv[] = {dummyArg}; framework::init(&boost_test_init, argc, argv); #if BOOST_VERSION >= 105900 framework::finalize_setup_phase(); #endif - + logInterceptor = new CukeBoostLogInterceptor; ::boost::unit_test::unit_test_log.set_formatter(logInterceptor); ::boost::unit_test::unit_test_log.set_threshold_level(log_all_errors); @@ -128,7 +132,7 @@ void BoostStep::initBoostTest() { void BoostStep::runWithMasterSuite() { currentTestBody = std::bind(&BoostStep::body, this); - + ::boost::unit_test::framework::run(testCase, false); currentTestBody.clear(); diff --git a/src/drivers/GTestDriver.cpp b/src/drivers/GTestDriver.cpp index 072e94be..70469f64 100644 --- a/src/drivers/GTestDriver.cpp +++ b/src/drivers/GTestDriver.cpp @@ -15,7 +15,7 @@ const InvokeResult GTestStep::invokeStepBody() { try { body(); return InvokeResult::success(); - } catch (const ::std::runtime_error &e) { + } catch (const ::std::runtime_error& e) { // ::testing::GoogleTestFailureException inherits from ::std::runtime_error return InvokeResult::failure(e.what()); } @@ -23,8 +23,8 @@ const InvokeResult GTestStep::invokeStepBody() { void GTestStep::initGTest() { int fake_argc = 1; - char *fake_argv[1]; - fake_argv[0] = (char *) "cucumber-cpp"; + char* fake_argv[1]; + fake_argv[0] = (char*)"cucumber-cpp"; ::testing::InitGoogleTest(&fake_argc, fake_argv); initialized = true; } diff --git a/src/drivers/QtTestDriver.cpp b/src/drivers/QtTestDriver.cpp index f55b3005..95b46f78 100644 --- a/src/drivers/QtTestDriver.cpp +++ b/src/drivers/QtTestDriver.cpp @@ -15,10 +15,11 @@ const InvokeResult QtTestStep::invokeStepBody() { file.close(); QtTestObject testObject(this); - int returnValue = QTest::qExec(&testObject, - QStringList() << "test" - << "-o" - << file.fileName()); + int returnValue = QTest::qExec( + &testObject, + QStringList() << "test" + << "-o" << file.fileName() + ); if (returnValue == 0) { return InvokeResult::success(); } else { @@ -30,4 +31,3 @@ const InvokeResult QtTestStep::invokeStepBody() { } } - diff --git a/src/main.cpp b/src/main.cpp index 70834ed3..c66fc60c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,22 +8,22 @@ namespace { -void acceptWireProtocol(const std::string& host, int port, const std::string& unixPath, bool verbose) { +void acceptWireProtocol( + const std::string& host, int port, const std::string& unixPath, bool verbose +) { using namespace ::cucumber::internal; CukeEngineImpl cukeEngine; JsonSpiritWireMessageCodec wireCodec; WireProtocolHandler protocolHandler(wireCodec, cukeEngine); std::unique_ptr server; #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) - if (!unixPath.empty()) - { + if (!unixPath.empty()) { UnixSocketServer* const unixServer = new UnixSocketServer(&protocolHandler); server.reset(unixServer); unixServer->listen(unixPath); if (verbose) std::clog << "Listening on socket " << unixServer->listenEndpoint() << std::endl; - } - else + } else #else // Prevent warning about unused parameter static_cast(unixPath); @@ -31,7 +31,9 @@ void acceptWireProtocol(const std::string& host, int port, const std::string& un { TCPSocketServer* const tcpServer = new TCPSocketServer(&protocolHandler); server.reset(tcpServer); - tcpServer->listen(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(host), port)); + tcpServer->listen( + boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(host), port) + ); if (verbose) std::clog << "Listening on " << tcpServer->listenEndpoint() << std::endl; } @@ -43,17 +45,22 @@ void acceptWireProtocol(const std::string& host, int port, const std::string& un int CUCUMBER_CPP_EXPORT main(int argc, char** argv) { using boost::program_options::value; boost::program_options::options_description optionDescription("Allowed options"); - optionDescription.add_options() - ("help,h", "help for cucumber-cpp") - ("verbose,v", "verbose output") - ("listen,l", value(), "listening address of wireserver") - ("port,p", value(), "listening port of wireserver, use '0' (zero) to select an ephemeral port") + optionDescription.add_options()("help,h", "help for cucumber-cpp")( + "verbose,v", "verbose output" + )("listen,l", value(), "listening address of wireserver" + )("port,p", + value(), + "listening port of wireserver, use '0' (zero) to select an ephemeral port") #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) - ("unix,u", value(), "listening unix socket of wireserver (disables listening on port)") + ("unix,u", + value(), + "listening unix socket of wireserver (disables listening on port)") #endif ; boost::program_options::variables_map optionVariableMap; - boost::program_options::store(boost::program_options::parse_command_line(argc, argv, optionDescription), optionVariableMap); + boost::program_options::store( + boost::program_options::parse_command_line(argc, argv, optionDescription), optionVariableMap + ); boost::program_options::notify(optionVariableMap); if (optionVariableMap.count("help")) { @@ -85,7 +92,7 @@ int CUCUMBER_CPP_EXPORT main(int argc, char** argv) { try { acceptWireProtocol(listenHost, port, unixPath, verbose); - } catch (std::exception &e) { + } catch (std::exception& e) { std::cerr << e.what() << std::endl; exit(1); } diff --git a/tests/integration/ContextHandlingTest.cpp b/tests/integration/ContextHandlingTest.cpp index 55c034cf..0627328e 100644 --- a/tests/integration/ContextHandlingTest.cpp +++ b/tests/integration/ContextHandlingTest.cpp @@ -10,6 +10,7 @@ class ContextHandlingTest : public ::testing::Test { ContextHandlingTest() : contextManager() { } + protected: ContextManagerTestDouble contextManager; @@ -51,12 +52,10 @@ TEST_F(ContextHandlingTest, contextsArePurgedExplicitlyOnly) { ASSERT_EQ(0, contextManager.countContexts()); ::cucumber::ScenarioScope context1_a; ASSERT_EQ(1, contextManager.countContexts()); - ::cucumber::ScenarioScope *context1_b = - new ::cucumber::ScenarioScope(); + ::cucumber::ScenarioScope* context1_b = new ::cucumber::ScenarioScope(); ASSERT_EQ(2, contextManager.countContexts()); delete context1_b; ASSERT_EQ(2, contextManager.countContexts()); contextManager.purgeContexts(); ASSERT_EQ(0, contextManager.countContexts()); } - diff --git a/tests/integration/HookRegistrationTest.cpp b/tests/integration/HookRegistrationTest.cpp index c1b0c049..380714c0 100644 --- a/tests/integration/HookRegistrationTest.cpp +++ b/tests/integration/HookRegistrationTest.cpp @@ -7,23 +7,35 @@ #define BEFORE_ALL_MARKER_1 "A" #define BEFORE_ALL_MARKER_2 "B" #define BEFORE_ALL_MARKER_3 "C" -BEFORE_ALL() { beforeAllHookCallMarker << BEFORE_ALL_MARKER_1; } -BEFORE_ALL() { beforeAllHookCallMarker << BEFORE_ALL_MARKER_2; } -BEFORE_ALL() { beforeAllHookCallMarker << BEFORE_ALL_MARKER_3; } +BEFORE_ALL() { + beforeAllHookCallMarker << BEFORE_ALL_MARKER_1; +} +BEFORE_ALL() { + beforeAllHookCallMarker << BEFORE_ALL_MARKER_2; +} +BEFORE_ALL() { + beforeAllHookCallMarker << BEFORE_ALL_MARKER_3; +} #define BEFORE_MARKER_1 "D" #define BEFORE_MARKER_2 "E" #define BEFORE_MARKER_3 "F" -BEFORE() { beforeHookCallMarker << BEFORE_MARKER_1; } -BEFORE() { beforeHookCallMarker << BEFORE_MARKER_2; } -BEFORE() { beforeHookCallMarker << BEFORE_MARKER_3; } +BEFORE() { + beforeHookCallMarker << BEFORE_MARKER_1; +} +BEFORE() { + beforeHookCallMarker << BEFORE_MARKER_2; +} +BEFORE() { + beforeHookCallMarker << BEFORE_MARKER_3; +} #define AROUND_STEP_MARKER_BEFORE_1 "G" #define AROUND_STEP_MARKER_BEFORE_2 "H" #define AROUND_STEP_MARKER_BEFORE_3 "I" -#define AROUND_STEP_MARKER_AFTER_3 "g" -#define AROUND_STEP_MARKER_AFTER_2 "h" -#define AROUND_STEP_MARKER_AFTER_1 "i" +#define AROUND_STEP_MARKER_AFTER_3 "g" +#define AROUND_STEP_MARKER_AFTER_2 "h" +#define AROUND_STEP_MARKER_AFTER_1 "i" AROUND_STEP() { beforeAroundStepHookCallMarker << AROUND_STEP_MARKER_BEFORE_1; globalStepHookCallMarker << AROUND_STEP_MARKER_BEFORE_1; @@ -65,17 +77,28 @@ AFTER_STEP() { #define AFTER_MARKER_1 "M" #define AFTER_MARKER_2 "N" #define AFTER_MARKER_3 "O" -AFTER() { afterHookCallMarker << AFTER_MARKER_1; } -AFTER() { afterHookCallMarker << AFTER_MARKER_2; } -AFTER() { afterHookCallMarker << AFTER_MARKER_3; } +AFTER() { + afterHookCallMarker << AFTER_MARKER_1; +} +AFTER() { + afterHookCallMarker << AFTER_MARKER_2; +} +AFTER() { + afterHookCallMarker << AFTER_MARKER_3; +} #define AFTER_ALL_MARKER_1 "P" #define AFTER_ALL_MARKER_2 "Q" #define AFTER_ALL_MARKER_3 "R" -AFTER_ALL() { afterAllHookCallMarker << AFTER_ALL_MARKER_1; } -AFTER_ALL() { afterAllHookCallMarker << AFTER_ALL_MARKER_2; } -AFTER_ALL() { afterAllHookCallMarker << AFTER_ALL_MARKER_3; } - +AFTER_ALL() { + afterAllHookCallMarker << AFTER_ALL_MARKER_1; +} +AFTER_ALL() { + afterAllHookCallMarker << AFTER_ALL_MARKER_2; +} +AFTER_ALL() { + afterAllHookCallMarker << AFTER_ALL_MARKER_3; +} #define CONTEXT_MARKER "X" BEFORE() { @@ -87,16 +110,19 @@ AFTER() { contextContents = *context; } - const std::string correctBeforeOrder(BEFORE_MARKER_1 BEFORE_MARKER_2 BEFORE_MARKER_3); -const std::string correctBeforeAroundStepOrder(AROUND_STEP_MARKER_BEFORE_1 AROUND_STEP_MARKER_BEFORE_2 AROUND_STEP_MARKER_BEFORE_3); -const std::string correctAfterAroundStepOrder(AROUND_STEP_MARKER_AFTER_3 AROUND_STEP_MARKER_AFTER_2 AROUND_STEP_MARKER_AFTER_1); -const std::string correctAfterStepOrder(AFTER_STEP_MARKER_1 AFTER_STEP_MARKER_2 AFTER_STEP_MARKER_3); +const std::string correctBeforeAroundStepOrder( + AROUND_STEP_MARKER_BEFORE_1 AROUND_STEP_MARKER_BEFORE_2 AROUND_STEP_MARKER_BEFORE_3 +); +const std::string correctAfterAroundStepOrder(AROUND_STEP_MARKER_AFTER_3 AROUND_STEP_MARKER_AFTER_2 + AROUND_STEP_MARKER_AFTER_1); +const std::string correctAfterStepOrder(AFTER_STEP_MARKER_1 AFTER_STEP_MARKER_2 AFTER_STEP_MARKER_3 +); const std::string correctAfterOrder(AFTER_MARKER_1 AFTER_MARKER_2 AFTER_MARKER_3); -const std::string correctBeforeAllOrder(BEFORE_ALL_MARKER_1 BEFORE_ALL_MARKER_2 BEFORE_ALL_MARKER_3); +const std::string correctBeforeAllOrder(BEFORE_ALL_MARKER_1 BEFORE_ALL_MARKER_2 BEFORE_ALL_MARKER_3 +); const std::string correctAfterAllOrder(AFTER_ALL_MARKER_1 AFTER_ALL_MARKER_2 AFTER_ALL_MARKER_3); - TEST_F(HookRegistrationTest, hooksAreRegisteredByTheMacros) { beginScenario(); EXPECT_EQ(correctBeforeOrder, sort(beforeHookOrder())); @@ -154,10 +180,11 @@ TEST_F(HookRegistrationTest, afterStepHooksAreInvokedAfterAroundStepHooks) { beginScenario(); EXPECT_EQ("", globalStepHookCallMarker.str()); invokeStep(); - EXPECT_EQ(beforeAroundStepHookCallMarker.str() + - afterAroundStepHookCallMarker.str() + - afterStepHookCallMarker.str(), - globalStepHookCallMarker.str()); + EXPECT_EQ( + beforeAroundStepHookCallMarker.str() + afterAroundStepHookCallMarker.str() + + afterStepHookCallMarker.str(), + globalStepHookCallMarker.str() + ); endScenario(); } @@ -165,7 +192,7 @@ TEST_F(HookRegistrationTest, beforeAllHooksAreInvokedInAnyOrderDuringFirstScenar EXPECT_EQ("", afterAllHookCallMarker.str()); beginScenario(); EXPECT_EQ(correctBeforeAllOrder, sort(beforeAllHookCallMarker.str())); - + clearHookCallMarkers(); invokeStep(); endScenario(); diff --git a/tests/integration/StepRegistrationTest.cpp b/tests/integration/StepRegistrationTest.cpp index b8614355..9a5ba5c3 100644 --- a/tests/integration/StepRegistrationTest.cpp +++ b/tests/integration/StepRegistrationTest.cpp @@ -10,11 +10,13 @@ using namespace cucumber::internal; class ManualStep : public GenericStep { public: - void body() override {}; -//private: + void body() override{}; + // private: static const int cukeRegId; }; -const int ManualStep::cukeRegId = ::cucumber::internal::registerStep(MANUAL_STEP_MATCHER, "C:\\Path\\With/Barward/And\\Forward/Slashes.cpp", 42); +const int ManualStep::cukeRegId = ::cucumber::internal::registerStep( + MANUAL_STEP_MATCHER, "C:\\Path\\With/Barward/And\\Forward/Slashes.cpp", 42 +); TEST(StepRegistrationTest, manualRegistration) { // static_cast is necessary for GTest <= 1.7 and C++ >= 2011 because it @@ -27,9 +29,12 @@ TEST(StepRegistrationTest, manualRegistration) { #define WHEN_MATCHER "when matcher" #define THEN_MATCHER "then matcher" -GIVEN(GIVEN_MATCHER) {} -WHEN(WHEN_MATCHER) {} -THEN(THEN_MATCHER) {} +GIVEN(GIVEN_MATCHER) { +} +WHEN(WHEN_MATCHER) { +} +THEN(THEN_MATCHER) { +} TEST(StepRegistrationTest, macroRegistration) { EXPECT_TRUE(static_cast(StepManager::stepMatches(GIVEN_MATCHER))); diff --git a/tests/integration/TaggedHookRegistrationTest.cpp b/tests/integration/TaggedHookRegistrationTest.cpp index cfd76f7e..193d5af5 100644 --- a/tests/integration/TaggedHookRegistrationTest.cpp +++ b/tests/integration/TaggedHookRegistrationTest.cpp @@ -3,22 +3,48 @@ #include "../utils/HookRegistrationFixture.hpp" #include -BEFORE("@a") { beforeHookCallMarker << "A"; } -BEFORE("@a","@b") { beforeHookCallMarker << "B"; } -BEFORE("@a,@b") { beforeHookCallMarker << "C"; } - -AROUND_STEP("@a") { afterAroundStepHookCallMarker << "D"; step->call(); } -AROUND_STEP("@a","@b") { afterAroundStepHookCallMarker << "E"; step->call(); } -AROUND_STEP("@a,@b") { afterAroundStepHookCallMarker << "F"; step->call(); } +BEFORE("@a") { + beforeHookCallMarker << "A"; +} +BEFORE("@a", "@b") { + beforeHookCallMarker << "B"; +} +BEFORE("@a,@b") { + beforeHookCallMarker << "C"; +} -AFTER_STEP("@a") { afterStepHookCallMarker << "G"; } -AFTER_STEP("@a","@b") { afterStepHookCallMarker << "H"; } -AFTER_STEP("@a,@b") { afterStepHookCallMarker << "I"; } +AROUND_STEP("@a") { + afterAroundStepHookCallMarker << "D"; + step->call(); +} +AROUND_STEP("@a", "@b") { + afterAroundStepHookCallMarker << "E"; + step->call(); +} +AROUND_STEP("@a,@b") { + afterAroundStepHookCallMarker << "F"; + step->call(); +} -AFTER("@a") { afterHookCallMarker << "J"; } -AFTER("@a","@b") { afterHookCallMarker << "K"; } -AFTER("@a,@b") { afterHookCallMarker << "L"; } +AFTER_STEP("@a") { + afterStepHookCallMarker << "G"; +} +AFTER_STEP("@a", "@b") { + afterStepHookCallMarker << "H"; +} +AFTER_STEP("@a,@b") { + afterStepHookCallMarker << "I"; +} +AFTER("@a") { + afterHookCallMarker << "J"; +} +AFTER("@a", "@b") { + afterHookCallMarker << "K"; +} +AFTER("@a,@b") { + afterHookCallMarker << "L"; +} TEST_F(HookRegistrationTest, noTaggedHooksAreInvokedIfNoScenarioTag) { beginScenario(); diff --git a/tests/integration/WireProtocolTest.cpp b/tests/integration/WireProtocolTest.cpp index 3c85560e..b9d1b3ea 100644 --- a/tests/integration/WireProtocolTest.cpp +++ b/tests/integration/WireProtocolTest.cpp @@ -11,11 +11,21 @@ using namespace testing; class MockCukeEngine : public CukeEngine { public: - MOCK_METHOD(std::vector, stepMatches, (const std::string & name), (const, override)); - MOCK_METHOD(void, endScenario, (const tags_type & tags), (override)); - MOCK_METHOD(void, invokeStep, (const std::string & id, const invoke_args_type & args, const invoke_table_type & tableArg), (override)); - MOCK_METHOD(void, beginScenario, (const tags_type & tags), (override)); - MOCK_METHOD(std::string, snippetText, (const std::string & keyword, const std::string & name, const std::string & multilineArgClass), (const, override)); + MOCK_METHOD(std::vector, stepMatches, (const std::string& name), (const, override)); + MOCK_METHOD(void, endScenario, (const tags_type& tags), (override)); + MOCK_METHOD( + void, + invokeStep, + (const std::string& id, const invoke_args_type& args, const invoke_table_type& tableArg), + (override) + ); + MOCK_METHOD(void, beginScenario, (const tags_type& tags), (override)); + MOCK_METHOD( + std::string, + snippetText, + (const std::string& keyword, const std::string& name, const std::string& multilineArgClass), + (const, override) + ); }; #define EXPECT_PTRTYPE(classname, expression) \ @@ -25,7 +35,7 @@ class WireMessageCodecTest : public Test { protected: std::shared_ptr commandAutoPtr; - WireCommand& decode(const char *jsonStr) { + WireCommand& decode(const char* jsonStr) { commandAutoPtr = codec.decode(jsonStr); return *commandAutoPtr; } @@ -38,7 +48,6 @@ class WireMessageCodecTest : public Test { const JsonSpiritWireMessageCodec codec; }; - /* * Request decoding */ @@ -56,12 +65,12 @@ TEST_F(WireMessageCodecTest, decodesUnknownOrMalformedMessage) { TEST_F(WireMessageCodecTest, handlesStepMatchesMessage) { MockCukeEngine engine; EXPECT_CALL(engine, stepMatches("name to match")) - .Times(1) - .WillRepeatedly(Return(std::vector(0))); + .Times(1) + .WillRepeatedly(Return(std::vector(0))); decode("[\"step_matches\"," "{\"name_to_match\":\"name to match\"}]") - .run(engine); + .run(engine); } TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithoutArgument) { @@ -73,14 +82,15 @@ TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithoutArgument) { TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithTagsArgument) { MockCukeEngine engine; - EXPECT_CALL(engine, beginScenario(ElementsAre("bar","baz","foo"))).Times(1); + EXPECT_CALL(engine, beginScenario(ElementsAre("bar", "baz", "foo"))).Times(1); decode("[\"begin_scenario\"," "{\"tags\":[" - "\"bar\"," - "\"baz\"," - "\"foo\"" - "]}]").run(engine); + "\"bar\"," + "\"baz\"," + "\"foo\"" + "]}]") + .run(engine); } TEST_F(WireMessageCodecTest, handlesBeginScenarioMessageWithNullArgument) { @@ -99,41 +109,47 @@ TEST_F(WireMessageCodecTest, handlesInvokeMessageWithNoArgs) { TEST_F(WireMessageCodecTest, handlesInvokeMessageWithoutTableArgs) { MockCukeEngine engine; - EXPECT_CALL(engine, invokeStep("42", ElementsAre("p1","p2","p3"), ElementsAre())).Times(1); + EXPECT_CALL(engine, invokeStep("42", ElementsAre("p1", "p2", "p3"), ElementsAre())).Times(1); decode("[\"invoke\",{" "\"id\":\"42\"," "\"args\":[" - "\"p1\"," - "\"p2\"," - "\"p3\"" - "}]").run(engine); + "\"p1\"," + "\"p2\"," + "\"p3\"" + "}]") + .run(engine); } TEST_F(WireMessageCodecTest, handlesInvokeMessageWithTableArgs) { MockCukeEngine engine; - EXPECT_CALL(engine, invokeStep( + EXPECT_CALL( + engine, + invokeStep( "42", ElementsAre("p1"), ElementsAre( - ElementsAre("col1","col2"), - ElementsAre("r1c1","r1c2"), - ElementsAre("r2c1","r2c2"), - ElementsAre("r3c1","r3c2") + ElementsAre("col1", "col2"), + ElementsAre("r1c1", "r1c2"), + ElementsAre("r2c1", "r2c2"), + ElementsAre("r3c1", "r3c2") ) - )).Times(1); + ) + ) + .Times(1); decode("[\"invoke\",{" "\"id\":\"42\"," "\"args\":[" - "\"p1\"," - "[" - "[\"col1\",\"col2\"]," - "[\"r1c1\",\"r1c2\"]," - "[\"r2c1\",\"r2c2\"]," - "[\"r3c1\",\"r3c2\"]" - "]" - "}]").run(engine); + "\"p1\"," + "[" + "[\"col1\",\"col2\"]," + "[\"r1c1\",\"r1c2\"]," + "[\"r2c1\",\"r2c2\"]," + "[\"r3c1\",\"r3c2\"]" + "]" + "}]") + .run(engine); } TEST_F(WireMessageCodecTest, handlesInvokeMessageWithNullArg) { @@ -159,25 +175,26 @@ TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithNullArgument) { TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithTagsArgument) { MockCukeEngine engine; - EXPECT_CALL(engine, endScenario(ElementsAre("cu","cum","ber"))).Times(1); + EXPECT_CALL(engine, endScenario(ElementsAre("cu", "cum", "ber"))).Times(1); decode("[\"end_scenario\"," "{\"tags\":[" - "\"cu\"," - "\"cum\"," - "\"ber\"" - "]}]").run(engine); + "\"cu\"," + "\"cum\"," + "\"ber\"" + "]}]") + .run(engine); } TEST_F(WireMessageCodecTest, handlesSnippetTextMessage) { MockCukeEngine engine; - EXPECT_CALL(engine, snippetText("Keyword", "step description","Some::Class")).Times(1); + EXPECT_CALL(engine, snippetText("Keyword", "step description", "Some::Class")).Times(1); decode("[\"snippet_text\"," "{\"step_keyword\":\"Keyword\"," - "\"multiline_arg_class\":\"Some::Class\"," - "\"step_name\":\"step description\"}]") - .run(engine); + "\"multiline_arg_class\":\"Some::Class\"," + "\"step_name\":\"step description\"}]") + .run(engine); } /* @@ -195,12 +212,14 @@ TEST_F(WireMessageCodecTest, handlesSimpleFailureResponse) { } TEST_F(WireMessageCodecTest, handlesDetailedFailureResponse) { - FailureResponse response("My message","ExceptionClassName"); - EXPECT_THAT(codec.encode(response), StrEq( - "[\"fail\",{" - "\"exception\":\"ExceptionClassName\"," - "\"message\":\"My message\"" - "}]")); + FailureResponse response("My message", "ExceptionClassName"); + EXPECT_THAT( + codec.encode(response), + StrEq("[\"fail\",{" + "\"exception\":\"ExceptionClassName\"," + "\"message\":\"My message\"" + "}]") + ); } TEST_F(WireMessageCodecTest, handlesPendingResponse) { @@ -229,19 +248,21 @@ TEST_F(WireMessageCodecTest, handlesStepMatchesResponse) { matches.push_back(sm2); StepMatchesResponse response(matches); - EXPECT_THAT(codec.encode(response), StrEq( - "[\"success\",[{" - "\"args\":[]," - "\"id\":\"1234\"," - "\"regexp\":\"Some (.*) regexp\"," - "\"source\":\"MyClass.cpp:56\"" - "},{" - "\"args\":[{" - "\"pos\":5," - "\"val\":\"odd\"" - "}]," - "\"id\":\"9876\"" - "}]]")); + EXPECT_THAT( + codec.encode(response), + StrEq("[\"success\",[{" + "\"args\":[]," + "\"id\":\"1234\"," + "\"regexp\":\"Some (.*) regexp\"," + "\"source\":\"MyClass.cpp:56\"" + "},{" + "\"args\":[{" + "\"pos\":5," + "\"val\":\"odd\"" + "}]," + "\"id\":\"9876\"" + "}]]") + ); } TEST_F(WireMessageCodecTest, handlesSnippetTextResponse) { @@ -287,9 +308,10 @@ TEST_F(WireMessageCodecTest, encodesResponseUsingRawUtf8) { TEST(WireCommandsTest, succesfulInvokeReturnsSuccess) { MockCukeEngine engine; - InvokeCommand invokeCommand("x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type()); - EXPECT_CALL(engine, invokeStep(_, _, _)) - .Times(1); + InvokeCommand invokeCommand( + "x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type() + ); + EXPECT_CALL(engine, invokeStep(_, _, _)).Times(1); std::shared_ptr response(invokeCommand.run(engine)); EXPECT_PTRTYPE(SuccessResponse, response.get()); @@ -297,10 +319,12 @@ TEST(WireCommandsTest, succesfulInvokeReturnsSuccess) { TEST(WireCommandsTest, throwingFailureInvokeReturnsFailure) { MockCukeEngine engine; - InvokeCommand invokeCommand("x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type()); + InvokeCommand invokeCommand( + "x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type() + ); EXPECT_CALL(engine, invokeStep(_, _, _)) - .Times(1) - .WillOnce(Throw(InvokeFailureException("A", "B"))); + .Times(1) + .WillOnce(Throw(InvokeFailureException("A", "B"))); std::shared_ptr response(invokeCommand.run(engine)); EXPECT_PTRTYPE(FailureResponse, response.get()); @@ -309,10 +333,10 @@ TEST(WireCommandsTest, throwingFailureInvokeReturnsFailure) { TEST(WireCommandsTest, throwingPendingStepReturnsPending) { MockCukeEngine engine; - InvokeCommand invokeCommand("x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type()); - EXPECT_CALL(engine, invokeStep(_, _, _)) - .Times(1) - .WillOnce(Throw(PendingStepException("S"))); + InvokeCommand invokeCommand( + "x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type() + ); + EXPECT_CALL(engine, invokeStep(_, _, _)).Times(1).WillOnce(Throw(PendingStepException("S"))); std::shared_ptr response(invokeCommand.run(engine)); EXPECT_PTRTYPE(PendingResponse, response.get()); @@ -321,18 +345,12 @@ TEST(WireCommandsTest, throwingPendingStepReturnsPending) { TEST(WireCommandsTest, throwingAnythingInvokeReturnsFailure) { MockCukeEngine engine; - InvokeCommand invokeCommand("x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type()); - EXPECT_CALL(engine, invokeStep(_, _, _)) - .Times(1) - .WillOnce(Throw(string("something"))); + InvokeCommand invokeCommand( + "x", CukeEngine::invoke_args_type(), CukeEngine::invoke_table_type() + ); + EXPECT_CALL(engine, invokeStep(_, _, _)).Times(1).WillOnce(Throw(string("something"))); std::shared_ptr response(invokeCommand.run(engine)); EXPECT_PTRTYPE(FailureResponse, response.get()); // TODO Test empty } - - - - - - diff --git a/tests/integration/WireServerTest.cpp b/tests/integration/WireServerTest.cpp index fe953e57..5827bcfc 100644 --- a/tests/integration/WireServerTest.cpp +++ b/tests/integration/WireServerTest.cpp @@ -34,20 +34,21 @@ MATCHER(EventuallyTerminates, "") { } MATCHER_P(EventuallyReceives, value, "") { - std::basic_iostream *stream = const_cast *>( - static_cast *>(&arg)); + std::basic_iostream* stream + = const_cast*>(static_cast*>(&arg) + ); std::string output; -// FIXME It should not block + // FIXME It should not block (*stream) >> output; -// boost::timer timer; -// double timeout = THREAD_TEST_TIMEOUT.total_milliseconds() / 1000.0; -// while (timer.elapsed() < timeout) { -// if (stream->rdbuf()->available() > 0) { // it is zero even if it doesn't block! -// (*stream) >> output; -// break; -// } -// boost::this_thread::yield(); -// } + // boost::timer timer; + // double timeout = THREAD_TEST_TIMEOUT.total_milliseconds() / 1000.0; + // while (timer.elapsed() < timeout) { + // if (stream->rdbuf()->available() > 0) { // it is zero even if it doesn't block! + // (*stream) >> output; + // break; + // } + // boost::this_thread::yield(); + // } return (output == value); } @@ -112,7 +113,7 @@ TEST_F(TCPSocketServerTest, moreThanOneClientCanConnect) { // when tcp::iostream client2(server->listenEndpoint()); - //then + // then ASSERT_THAT(client2, IsConnected()); } @@ -140,17 +141,17 @@ TEST_F(TCPSocketServerTest, receiveAndSendsSingleLineMassages) { class TCPSocketServerLocalhostTest : public SocketServerTest { protected: - std::unique_ptr server; + std::unique_ptr server; - SocketServer* createListeningServer() override { - server.reset(new TCPSocketServer(&protocolHandler)); - server->listen(tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 0)); - return server.get(); - } + SocketServer* createListeningServer() override { + server.reset(new TCPSocketServer(&protocolHandler)); + server->listen(tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 0)); + return server.get(); + } - void destroyListeningServer() override { - server.reset(); - } + void destroyListeningServer() override { + server.reset(); + } }; TEST_F(TCPSocketServerLocalhostTest, listensOnLocalhost) { diff --git a/tests/integration/drivers/BoostDriverTest.cpp b/tests/integration/drivers/BoostDriverTest.cpp index c2364243..8f18e06f 100644 --- a/tests/integration/drivers/BoostDriverTest.cpp +++ b/tests/integration/drivers/BoostDriverTest.cpp @@ -28,13 +28,13 @@ using namespace cucumber::internal; #if BOOST_VERSION >= 105900 namespace boost { - namespace unit_test { - namespace framework { - bool is_initialized() { - return boost::unit_test::framework::master_test_suite().argc > 0; - } - } - } +namespace unit_test { +namespace framework { +bool is_initialized() { + return boost::unit_test::framework::master_test_suite().argc > 0; +} +} +} } #endif @@ -44,7 +44,7 @@ class BoostStepDouble : public BoostStep { return BoostStep::invokeStepBody(); }; - void body() override {}; + void body() override{}; }; class BoostDriverTest : public DriverTest { @@ -59,7 +59,9 @@ class BoostDriverTest : public DriverTest { std::cout << "= Init =" << std::endl; using namespace boost::unit_test; BoostStepDouble step; - expectFalse("Framework is not initialized before the first test", framework::is_initialized()); + expectFalse( + "Framework is not initialized before the first test", framework::is_initialized() + ); step.invokeStepBody(); expectTrue("Framework is initialized after the first test", framework::is_initialized()); } diff --git a/tests/integration/drivers/GTestDriverTest.cpp b/tests/integration/drivers/GTestDriverTest.cpp index 658ef34a..b5d2e6c5 100644 --- a/tests/integration/drivers/GTestDriverTest.cpp +++ b/tests/integration/drivers/GTestDriverTest.cpp @@ -35,7 +35,7 @@ class GTestStepDouble : public GTestStep { return GTestStep::invokeStepBody(); }; - void body() override {}; + void body() override{}; }; class GTestDriverTest : public DriverTest { @@ -49,7 +49,9 @@ class GTestDriverTest : public DriverTest { void stepInvocationInitsGTest() { std::cout << "= Init =" << std::endl; GTestStepDouble framework; - expectFalse("Framework is not initialized before the first test", framework.isInitialized()); + expectFalse( + "Framework is not initialized before the first test", framework.isInitialized() + ); framework.invokeStepBody(); expectTrue("Framework is initialized after the first test", framework.isInitialized()); } diff --git a/tests/integration/drivers/QtTestDriverTest.cpp b/tests/integration/drivers/QtTestDriverTest.cpp index 170b9a00..bbdc9406 100644 --- a/tests/integration/drivers/QtTestDriverTest.cpp +++ b/tests/integration/drivers/QtTestDriverTest.cpp @@ -27,7 +27,10 @@ using namespace cucumber::internal; class QtTestStepDouble : public QtTestStep { public: - QtTestStepDouble() : QtTestStep(), testRun(false) {} + QtTestStepDouble() : + QtTestStep(), + testRun(false) { + } const InvokeResult invokeStepBody() override { return QtTestStep::invokeStepBody(); diff --git a/tests/unit/ContextManagerTest.cpp b/tests/unit/ContextManagerTest.cpp index 421cabd8..8d300321 100644 --- a/tests/unit/ContextManagerTest.cpp +++ b/tests/unit/ContextManagerTest.cpp @@ -13,6 +13,7 @@ class ContextManagerTest : public ::testing::Test { ContextManagerTest() : contextManager() { } + protected: private: void TearDown() override { @@ -24,7 +25,7 @@ class Context1 {}; class Context2 {}; TEST_F(ContextManagerTest, createsValidContextPointers) { - std::weak_ptr ctx1 = contextManager.addContext (); + std::weak_ptr ctx1 = contextManager.addContext(); ASSERT_EQ(1, contextManager.countContexts()); ASSERT_FALSE(ctx1.expired()); std::weak_ptr ctx2 = contextManager.addContext(); @@ -33,7 +34,7 @@ TEST_F(ContextManagerTest, createsValidContextPointers) { } TEST_F(ContextManagerTest, allowsCreatingTheSameContextTypeTwice) { - std::weak_ptr ctx1 = contextManager.addContext (); + std::weak_ptr ctx1 = contextManager.addContext(); ASSERT_EQ(1, contextManager.countContexts()); ASSERT_FALSE(ctx1.expired()); std::weak_ptr ctx2 = contextManager.addContext(); @@ -43,7 +44,7 @@ TEST_F(ContextManagerTest, allowsCreatingTheSameContextTypeTwice) { } TEST_F(ContextManagerTest, purgesContexts) { - std::weak_ptr ctx1 = contextManager.addContext (); + std::weak_ptr ctx1 = contextManager.addContext(); ASSERT_EQ(1, contextManager.countContexts()); ASSERT_FALSE(ctx1.expired()); contextManager.purgeContexts(); diff --git a/tests/unit/CukeCommandsTest.cpp b/tests/unit/CukeCommandsTest.cpp index e8607ad6..4fb1d911 100644 --- a/tests/unit/CukeCommandsTest.cpp +++ b/tests/unit/CukeCommandsTest.cpp @@ -11,7 +11,7 @@ using std::string; class CukeCommandsTest : public CukeCommandsFixture { protected: - void addStepWithMatcher(const std::string &matcher) { + void addStepWithMatcher(const std::string& matcher) { addStepToManager(matcher); } }; @@ -81,11 +81,11 @@ class CheckAllParametersWithMacro : public CheckAllParameters { class CheckAllParametersWithFuncArgs : public CheckAllParameters { public: void bodyWithArgs( - const int got_arg_0_int - , const double got_arg_1_double - , const std::string got_arg_2_string - , const std::string& got_arg_3_string_with_spaces - ) { + const int got_arg_0_int, + const double got_arg_1_double, + const std::string got_arg_2_string, + const std::string& got_arg_3_string_with_spaces + ) { EXPECT_EQ(arg_0_int, got_arg_0_int); EXPECT_EQ(arg_1_double, got_arg_1_double); EXPECT_EQ(arg_2_string, got_arg_2_string); @@ -120,15 +120,19 @@ TEST_F(CukeCommandsTest, invokeHandlesParametersWithMacro) { } TEST_F(CukeCommandsTest, producesSnippetsEscapingTitle) { - EXPECT_EQ("THEN(\"^x\\\\|y\\\"z$\") {\n" - " pending();\n" - "}\n", - snippetText("then","x|y\"z")); + EXPECT_EQ( + "THEN(\"^x\\\\|y\\\"z$\") {\n" + " pending();\n" + "}\n", + snippetText("then", "x|y\"z") + ); } TEST_F(CukeCommandsTest, escapesCaractersInRegexes) { // abc|()[]{}^$*+?.\def <= abc\|\(\)\[\]\{\}\^\$\*\+\?\.\\def - EXPECT_EQ("abc\\|\\(\\)\\[\\]\\{\\}\\^\\$\\*\\+\\?\\.\\\\def", escapeRegex("abc|()[]{}^$*+?.\\def")); + EXPECT_EQ( + "abc\\|\\(\\)\\[\\]\\{\\}\\^\\$\\*\\+\\?\\.\\\\def", escapeRegex("abc|()[]{}^$*+?.\\def") + ); } TEST_F(CukeCommandsTest, escapesCharactersInCStrings) { diff --git a/tests/unit/RegexTest.cpp b/tests/unit/RegexTest.cpp index e31ae283..81635d83 100644 --- a/tests/unit/RegexTest.cpp +++ b/tests/unit/RegexTest.cpp @@ -5,7 +5,6 @@ using namespace cucumber::internal; #include - TEST(RegexTest, matchesSimpleRegex) { Regex exact("^cde$"); @@ -82,7 +81,7 @@ TEST(RegexTest, findAllExtractsTheFirstGroupOfEveryToken) { EXPECT_TRUE(match->matches()); EXPECT_EQ(3, match->getSubmatches().size()); - //EXPECT_THAT(match.getSubmatches(), ElementsAre("a", "b", "cc")); + // EXPECT_THAT(match.getSubmatches(), ElementsAre("a", "b", "cc")); } /* diff --git a/tests/unit/StepCallChainTest.cpp b/tests/unit/StepCallChainTest.cpp index d95d64db..52ad8df2 100644 --- a/tests/unit/StepCallChainTest.cpp +++ b/tests/unit/StepCallChainTest.cpp @@ -6,35 +6,38 @@ using namespace cucumber::internal; class FakeStepInfo : public StepInfo { public: - FakeStepInfo(std::stringstream *markersPtr, const InvokeResult &result) : + FakeStepInfo(std::stringstream* markersPtr, const InvokeResult& result) : StepInfo("FAKE", ""), latestArgsPtr(0), markersPtr(markersPtr), result(result) { } - InvokeResult invokeStep(const InvokeArgs *pArgs) const override { + InvokeResult invokeStep(const InvokeArgs* pArgs) const override { latestArgsPtr = pArgs; (*markersPtr) << "S"; return result; } - const InvokeArgs *getLatestArgsPassed() const { + const InvokeArgs* getLatestArgsPassed() const { return latestArgsPtr; } private: - mutable const InvokeArgs *latestArgsPtr; - std::stringstream *markersPtr; + mutable const InvokeArgs* latestArgsPtr; + std::stringstream* markersPtr; const InvokeResult result; }; class MarkingAroundStepHook : public AroundStepHook { public: - MarkingAroundStepHook(std::string id, std::stringstream *markersPtr) : - id(id), markersPtr(markersPtr) {}; + MarkingAroundStepHook(std::string id, std::stringstream* markersPtr) : + id(id), + markersPtr(markersPtr){}; - MarkingAroundStepHook() : id(""), markersPtr(0) {}; + MarkingAroundStepHook() : + id(""), + markersPtr(0){}; void body() override { if (markersPtr) { @@ -53,13 +56,14 @@ class MarkingAroundStepHook : public AroundStepHook { private: std::string id; - std::stringstream *markersPtr; + std::stringstream* markersPtr; }; class BlockingAroundStepHook : public MarkingAroundStepHook { public: - BlockingAroundStepHook(std::string id, std::stringstream *markersPtr) : - MarkingAroundStepHook(id, markersPtr) {}; + BlockingAroundStepHook(std::string id, std::stringstream* markersPtr) : + MarkingAroundStepHook(id, markersPtr){}; + protected: void doCall() override { } @@ -72,7 +76,7 @@ class StepCallChainTest : public ::testing::Test { HookRegistrar::aroundhook_list_type aroundHooks; std::stringstream markers; - InvokeResult execStep(const InvokeResult &result) { + InvokeResult execStep(const InvokeResult& result) { const FakeStepInfo step(&markers, result); StepCallChain scc(0, &step, &NO_INVOKE_ARGS, aroundHooks); return scc.exec(); @@ -109,11 +113,11 @@ TEST_F(StepCallChainTest, stepExecutionReturnsTheExpectedResult) { } TEST_F(StepCallChainTest, aroundHooksAreInvokedInTheCorrectOrder) { - std::shared_ptr - hook1(std::make_shared("1", &markers)) - , hook2(std::make_shared("2", &markers)) - , hook3(std::make_shared("3", &markers)) - ; + std::shared_ptr hook1( + std::make_shared("1", &markers) + ), + hook2(std::make_shared("2", &markers)), + hook3(std::make_shared("3", &markers)); aroundHooks.push_back(hook1); aroundHooks.push_back(hook2); @@ -134,11 +138,11 @@ TEST_F(StepCallChainTest, argsArePassedToTheStep) { } TEST_F(StepCallChainTest, aroundHooksCanStopTheCallChain) { - std::shared_ptr - hook1(std::make_shared("1", &markers)) - , hook2(std::make_shared("2", &markers)) - , hook3(std::make_shared("3", &markers)) - ; + std::shared_ptr hook1( + std::make_shared("1", &markers) + ), + hook2(std::make_shared("2", &markers)), + hook3(std::make_shared("3", &markers)); aroundHooks.push_back(hook1); aroundHooks.push_back(hook2); diff --git a/tests/unit/StepManagerTest.cpp b/tests/unit/StepManagerTest.cpp index ae13f96a..72c1eafb 100644 --- a/tests/unit/StepManagerTest.cpp +++ b/tests/unit/StepManagerTest.cpp @@ -7,20 +7,20 @@ using namespace std; using namespace cucumber::internal; - class StepManagerTest : public ::testing::Test { public: typedef StepManagerTestDouble StepManager; protected: - StepManagerTest() {} - const static char *a_matcher; - const static char *another_matcher; - const static char *no_match; - const static char *a_third_matcher; + StepManagerTest() { + } + const static char* a_matcher; + const static char* another_matcher; + const static char* no_match; + const static char* a_third_matcher; const map no_params; - int getUniqueMatchIdOrZeroFor(const string &stepMatch) { + int getUniqueMatchIdOrZeroFor(const string& stepMatch) { MatchResult::match_results_type resultSet = getResultSetFor(stepMatch); if (resultSet.size() != 1) { return 0; @@ -29,15 +29,15 @@ class StepManagerTest : public ::testing::Test { } } - size_t countMatches(const string &stepMatch) { + size_t countMatches(const string& stepMatch) { return getResultSetFor(stepMatch).size(); } - bool matchesOnce(const string &stepMatch) { + bool matchesOnce(const string& stepMatch) { return (countMatches(stepMatch) == 1); } - bool matchesAtLeastOnce(const string &stepMatch) { + bool matchesAtLeastOnce(const string& stepMatch) { return (countMatches(stepMatch) > 0); } @@ -60,8 +60,9 @@ class StepManagerTest : public ::testing::Test { } return true; } + private: - MatchResult::match_results_type getResultSetFor(const string &stepMatch) { + MatchResult::match_results_type getResultSetFor(const string& stepMatch) { return StepManager::stepMatches(stepMatch).getResultSet(); } void TearDown() override { @@ -69,10 +70,10 @@ class StepManagerTest : public ::testing::Test { } }; -const char *StepManagerTest::a_matcher = "a matcher"; -const char *StepManagerTest::another_matcher = "another matcher"; -const char *StepManagerTest::a_third_matcher = "a third matcher"; -const char *StepManagerTest::no_match = "no match"; +const char* StepManagerTest::a_matcher = "a matcher"; +const char* StepManagerTest::another_matcher = "another matcher"; +const char* StepManagerTest::a_third_matcher = "a third matcher"; +const char* StepManagerTest::no_match = "no match"; TEST_F(StepManagerTest, holdsNonConflictingSteps) { ASSERT_EQ(0, StepManager::count()); @@ -112,9 +113,11 @@ TEST_F(StepManagerTest, extractsParamsFromRegExMatchers) { StepManager::addStepDefinition("match the (\\w+) param"); EXPECT_TRUE(extractedParamsAre("match the first param", {{10, "first"}})); StepManager::addStepDefinition("match a (.+)$"); - EXPECT_TRUE(extractedParamsAre("match a string with spaces ", {{8, " string with spaces "}})); + EXPECT_TRUE( + extractedParamsAre("match a string with spaces ", {{8, " string with spaces "}}) + ); StepManager::addStepDefinition("match params (\\w+), (\\w+) and (\\w+)"); - EXPECT_TRUE(extractedParamsAre("match params A, B and C", {{13, "A"},{16, "B"},{22, "C"}})); + EXPECT_TRUE(extractedParamsAre("match params A, B and C", {{13, "A"}, {16, "B"}, {22, "C"}})); } TEST_F(StepManagerTest, handlesMultipleMatches) { diff --git a/tests/unit/TableTest.cpp b/tests/unit/TableTest.cpp index dd089751..2c2ae5f0 100644 --- a/tests/unit/TableTest.cpp +++ b/tests/unit/TableTest.cpp @@ -7,27 +7,29 @@ TEST(TableTest, forbidsRowsNotMatchingTableColumnsSize) { Table t; t.addColumn("C1"); - EXPECT_THROW({ - Table::row_type row; - t.addRow(row); - }, std::range_error); + EXPECT_THROW( + { + Table::row_type row; + t.addRow(row); + }, + std::range_error + ); - EXPECT_NO_THROW({ - t.addRow({"R1"}); - }); + EXPECT_NO_THROW({ t.addRow({"R1"}); }); - EXPECT_THROW({ - t.addRow({"R1", "R2"}); - }, std::range_error); + EXPECT_THROW({ t.addRow({"R1", "R2"}); }, std::range_error); } TEST(TableTest, rowsCannotBeAddedBeforeColumnsAreSet) { Table t; - EXPECT_THROW({ - Table::row_type row; - t.addRow(row); - }, std::runtime_error); + EXPECT_THROW( + { + Table::row_type row; + t.addRow(row); + }, + std::runtime_error + ); } TEST(TableTest, columnsCannotBeChangesAfterRowsAreAdded) { @@ -35,9 +37,7 @@ TEST(TableTest, columnsCannotBeChangesAfterRowsAreAdded) { t.addColumn("C1"); t.addRow({"R1"}); - EXPECT_THROW({ - t.addColumn("C2"); - }, std::runtime_error); + EXPECT_THROW({ t.addColumn("C2"); }, std::runtime_error); } TEST(TableTest, addedRowsMatchColumnDefinition) { diff --git a/tests/unit/TagTest.cpp b/tests/unit/TagTest.cpp index e934a70a..bddf4a6e 100644 --- a/tests/unit/TagTest.cpp +++ b/tests/unit/TagTest.cpp @@ -34,7 +34,6 @@ TEST(TagTest, orExpressionsAllowSpaces) { EXPECT_FALSE(tagExpr.matches({"x"})); } - TEST(TagTest, emptyAndExpressionMatchesAnyTag) { AndTagExpression tagExpr(""); EXPECT_TRUE(tagExpr.matches({"x"})); diff --git a/tests/utils/CukeCommandsFixture.hpp b/tests/utils/CukeCommandsFixture.hpp index 93a32c0b..e0e4d479 100644 --- a/tests/utils/CukeCommandsFixture.hpp +++ b/tests/utils/CukeCommandsFixture.hpp @@ -1,4 +1,4 @@ -#ifndef CUKE_CUKECOMMANDSFIXTURE_HPP_ +#ifndef CUKE_CUKECOMMANDSFIXTURE_HPP_ #define CUKE_CUKECOMMANDSFIXTURE_HPP_ #include @@ -11,7 +11,8 @@ using namespace cucumber::internal; class EmptyStep : public GenericStep { - void body() override {} + void body() override { + } }; class CukeCommandsFixture : public ::testing::Test, public CukeCommands { @@ -31,8 +32,8 @@ class CukeCommandsFixture : public ::testing::Test, public CukeCommands { } template - void addStepToManager(const std::string &matcher) { - stepId = StepManager::addStep(std::make_shared >(matcher, "")); + void addStepToManager(const std::string& matcher) { + stepId = StepManager::addStep(std::make_shared>(matcher, "")); } void TearDown() override { @@ -43,4 +44,3 @@ class CukeCommandsFixture : public ::testing::Test, public CukeCommands { const std::string CukeCommandsFixture::STATIC_MATCHER("MATCHER"); #endif /* CUKE_CUKECOMMANDSFIXTURE_HPP_ */ - diff --git a/tests/utils/DriverTestRunner.hpp b/tests/utils/DriverTestRunner.hpp index b9fdf16e..387ea3f9 100644 --- a/tests/utils/DriverTestRunner.hpp +++ b/tests/utils/DriverTestRunner.hpp @@ -12,6 +12,7 @@ class ContextListener { private: static int createdContexts; static int destroyedContexts; + public: int getCreatedContexts() { return createdContexts; @@ -37,6 +38,7 @@ int ContextListener::destroyedContexts = 0; class SomeContext { private: ContextListener listener; + public: SomeContext() { listener.notifyCreation(); @@ -51,12 +53,12 @@ namespace internal { static const InvokeArgs NO_INVOKE_ARGS; -#define SUCCEED_MATCHER "Succeeding step" -#define FAIL_MATCHER "Failing step" +#define SUCCEED_MATCHER "Succeeding step" +#define FAIL_MATCHER "Failing step" #define PENDING_MATCHER_1 "Pending step without description" #define PENDING_MATCHER_2 "Pending step with description" -#define PENDING_DESCRIPTION "Describe me!" +#define PENDING_DESCRIPTION "Describe me!" class DriverTest { public: @@ -70,21 +72,22 @@ class DriverTest { } virtual ~DriverTest() = default; + protected: - void expectTrue(const char *description, bool condition) { + void expectTrue(const char* description, bool condition) { updateState(description, condition); } - void expectFalse(const char *description, bool condition) { + void expectFalse(const char* description, bool condition) { updateState(description, !condition); } template - void expectEqual(const char *description, T val1, T val2) { + void expectEqual(const char* description, T val1, T val2) { updateState(description, val1 == val2); } - void expectStrEqual(const char *description, const char *val1, const char *val2) { + void expectStrEqual(const char* description, const char* val1, const char* val2) { updateState(description, strcmp(val1, val2) == 0); } @@ -95,15 +98,16 @@ class DriverTest { } CukeCommands cukeCommands; + private: typedef StepManagerTestDouble StepManager; ContextListener listener; int failedTests; - void updateState(const char *description, bool testSuccessState) { - std::cout << (testSuccessState ? "SUCCESS" : "FAILURE") - << " (" << description << ")" << std::endl; + void updateState(const char* description, bool testSuccessState) { + std::cout << (testSuccessState ? "SUCCESS" : "FAILURE") << " (" << description << ")" + << std::endl; failedTests += testSuccessState ? 0 : 1; } @@ -127,11 +131,17 @@ class DriverTest { result = cukeCommands.invoke(getStepIdFromMatcher(PENDING_MATCHER_1), &NO_INVOKE_ARGS); expectTrue("Pending step with no description - result", result.isPending()); - expectStrEqual("Pending step with no description - description", "", result.getDescription().c_str()); + expectStrEqual( + "Pending step with no description - description", "", result.getDescription().c_str() + ); result = cukeCommands.invoke(getStepIdFromMatcher(PENDING_MATCHER_2), &NO_INVOKE_ARGS); expectTrue("Pending step with description - result", result.isPending()); - expectStrEqual("Pending step with description - description", PENDING_DESCRIPTION, result.getDescription().c_str()); + expectStrEqual( + "Pending step with description - description", + PENDING_DESCRIPTION, + result.getDescription().c_str() + ); result = cukeCommands.invoke(42, &NO_INVOKE_ARGS); expectFalse("Inexistent step", result.isSuccess()); @@ -169,7 +179,9 @@ class DriverTest { result = cukeCommands.invoke(getStepIdFromMatcher(FAIL_MATCHER), &NO_INVOKE_ARGS); - expectEqual("Failing step description is the same", failureMessage, result.getDescription()); + expectEqual( + "Failing step description is the same", failureMessage, result.getDescription() + ); } }; diff --git a/tests/utils/HookRegistrationFixture.hpp b/tests/utils/HookRegistrationFixture.hpp index 3a98a104..9cd81c1e 100644 --- a/tests/utils/HookRegistrationFixture.hpp +++ b/tests/utils/HookRegistrationFixture.hpp @@ -36,25 +36,23 @@ void clearHookCallMarkers() { } std::string getHookCallMarkers() { - return beforeAllHookCallMarker.str() + - beforeHookCallMarker.str() + - beforeAroundStepHookCallMarker.str() + - afterStepHookCallMarker.str() + - afterHookCallMarker.str() + - afterAllHookCallMarker.str(); + return beforeAllHookCallMarker.str() + beforeHookCallMarker.str() + + beforeAroundStepHookCallMarker.str() + afterStepHookCallMarker.str() + + afterHookCallMarker.str() + afterAllHookCallMarker.str(); } class EmptyCallableStep : public CallableStep { public: - void call() override {}; + void call() override{}; }; class HookRegistrarDouble : public HookRegistrar { public: - static void execAroundStepHooks(Scenario *scenario) { + static void execAroundStepHooks(Scenario* scenario) { EmptyCallableStep emptyStep; - aroundhook_list_type &ash = aroundStepHooks(); - for (HookRegistrar::aroundhook_list_type::const_iterator h = ash.begin(); h != ash.end(); ++h) { + aroundhook_list_type& ash = aroundStepHooks(); + for (HookRegistrar::aroundhook_list_type::const_iterator h = ash.begin(); h != ash.end(); + ++h) { (*h)->invokeHook(scenario, &emptyStep); } } @@ -70,7 +68,7 @@ class HookRegistrationTest : public CukeCommandsFixture { emptyScenario = std::make_shared(); } - Scenario *getEmptyScenario() { + Scenario* getEmptyScenario() { return emptyScenario.get(); } @@ -98,7 +96,7 @@ class HookRegistrationTest : public CukeCommandsFixture { return getHookCallMarkers(); } - void beginScenario(const TagExpression::tag_list & tags = TagExpression::tag_list()) { + void beginScenario(const TagExpression::tag_list& tags = TagExpression::tag_list()) { CukeCommandsFixture::beginScenario(tags); } diff --git a/tests/utils/StepManagerTestDouble.hpp b/tests/utils/StepManagerTestDouble.hpp index 02108760..7cb0d832 100644 --- a/tests/utils/StepManagerTestDouble.hpp +++ b/tests/utils/StepManagerTestDouble.hpp @@ -6,10 +6,11 @@ namespace cucumber { namespace internal { - class StepInfoNoOp : public StepInfo { public: - StepInfoNoOp(const std::string &stepMatcher, const std::string source) : StepInfo(stepMatcher, source) {} + StepInfoNoOp(const std::string& stepMatcher, const std::string source) : + StepInfo(stepMatcher, source) { + } InvokeResult invokeStep(const InvokeArgs*) const override { return InvokeResult::success(); } @@ -17,9 +18,10 @@ class StepInfoNoOp : public StepInfo { class StepInfoPending : public StepInfo { private: - const char *description; + const char* description; + public: - StepInfoPending(const std::string &stepMatcher, const char *description) : + StepInfoPending(const std::string& stepMatcher, const char* description) : StepInfo(stepMatcher, ""), description(description) { } @@ -34,13 +36,14 @@ class StepInfoPending : public StepInfo { */ class StepInfoWithTableArg : public StepInfo { const unsigned short expectedSize; + public: - StepInfoWithTableArg(const std::string &stepMatcher, const unsigned short expectedSize) : + StepInfoWithTableArg(const std::string& stepMatcher, const unsigned short expectedSize) : StepInfo(stepMatcher, ""), expectedSize(expectedSize) { } - InvokeResult invokeStep(const InvokeArgs *pArgs) const override { + InvokeResult invokeStep(const InvokeArgs* pArgs) const override { if (pArgs->getTableArg().hashes().size() == expectedSize) { return InvokeResult::success(); } else { @@ -49,7 +52,6 @@ class StepInfoWithTableArg : public StepInfo { } }; - class StepManagerTestDouble : public StepManager { public: static void clearSteps() { @@ -60,39 +62,51 @@ class StepManagerTestDouble : public StepManager { return steps().size(); } - static step_id_type addStepDefinition(const std::string &stepMatcher) { + static step_id_type addStepDefinition(const std::string& stepMatcher) { return addStep(std::make_shared(stepMatcher, "")); } - static step_id_type addStepDefinitionWithId(step_id_type desiredId, const std::string &stepMatcher) { + static step_id_type addStepDefinitionWithId( + step_id_type desiredId, const std::string& stepMatcher + ) { return addStepDefinitionWithId(desiredId, stepMatcher, ""); } - static step_id_type addStepDefinitionWithId(step_id_type desiredId, const std::string &stepMatcher, - const std::string source) { + static step_id_type addStepDefinitionWithId( + step_id_type desiredId, const std::string& stepMatcher, const std::string source + ) { std::shared_ptr stepInfo(std::make_shared(stepMatcher, source)); stepInfo->id = desiredId; return addStep(stepInfo); } - static step_id_type addPendingStepDefinitionWithId(step_id_type desiredId, const std::string &stepMatcher) { + static step_id_type addPendingStepDefinitionWithId( + step_id_type desiredId, const std::string& stepMatcher + ) { return addPendingStepDefinitionWithId(desiredId, stepMatcher, 0); } - static step_id_type addPendingStepDefinitionWithId(step_id_type desiredId, - const std::string &stepMatcher, const char *description) { - std::shared_ptr stepInfo(std::make_shared(stepMatcher, description)); + static step_id_type addPendingStepDefinitionWithId( + step_id_type desiredId, const std::string& stepMatcher, const char* description + ) { + std::shared_ptr stepInfo( + std::make_shared(stepMatcher, description) + ); stepInfo->id = desiredId; return addStep(stepInfo); } - static step_id_type addTableStepDefinitionWithId(step_id_type desiredId, const std::string &stepMatcher, const unsigned short expectedSize) { - std::shared_ptr stepInfo(std::make_shared(stepMatcher, expectedSize)); + static step_id_type addTableStepDefinitionWithId( + step_id_type desiredId, const std::string& stepMatcher, const unsigned short expectedSize + ) { + std::shared_ptr stepInfo( + std::make_shared(stepMatcher, expectedSize) + ); stepInfo->id = desiredId; return addStep(stepInfo); } - static step_id_type getStepId(const std::string &stepMatcher) { + static step_id_type getStepId(const std::string& stepMatcher) { step_id_type id = 0; for (steps_type::const_iterator i = steps().begin(); i != steps().end(); ++i) { const StepInfo& stepInfo = *i->second; From a1cad52463f6f7d4d13d1f43ea705d63faae18b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Sun, 17 Dec 2023 22:14:45 +0100 Subject: [PATCH 3/3] check code format on PR and main branch --- .github/workflows/format.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..3636086c --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,26 @@ +name: check format + +on: + pull_request: + branches: [ main ] + workflow_dispatch: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v2 + + - name: setup environment + run: | + sudo apt-get install --no-install-recommends \ + clang-format-15 + + - name: check code format + run: | + clang-format-15 --style=file --Werror --dry-run --verbose `find . -type d \( -name '3rdparty' \) -prune -o -regex '.*\.\(cpp\|hpp\)' -print` +