diff --git a/.travis.yml b/.travis.yml index 809cb533..99d4dc70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,27 @@ language: cpp - +sudo: required +dist: trusty +os: + - linux + - osx compiler: - clang - gcc +rvm: + - 1.9.3 + - 2.0 + - 2.2 +addons: + apt: + # List of whitelisted in travis packages for ubuntu-precise can be found here: + # https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise + # List of whitelisted in travis apt-sources: + # https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json + packages: + - libboost-thread-dev + - libboost-system-dev + - libboost-regex-dev + - libboost-date-time-dev + - libboost-test-dev -before_script: - - "sudo apt-get install libboost-thread-dev libboost-system-dev libboost-regex-dev libboost-date-time-dev libboost-test-dev google-mock" - - "cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd -" - -script: "cmake -E make_directory build && cmake -E chdir build cmake -DCUKE_ENABLE_EXAMPLES=on .. && cmake --build build && cmake --build build --target test && cmake --build build --target features" +script: ./travis.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 32f02675..5f45587f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.12) project(Cucumber-Cpp) @@ -86,22 +86,63 @@ endif() # if(NOT CUKE_DISABLE_GTEST) - find_package(GTest) - find_package(GMock) - if(GMOCK_FOUND AND GTEST_FOUND) - set(CUKE_TEST_LIBRARIES ${GTEST_LIBRARIES} ${GMOCK_BOTH_LIBRARIES}) - if(UNIX) - find_package(Threads) # GTest needs this and it's a static library - set(CUKE_TEST_LIBRARIES ${CUKE_TEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) - endif() + if(UNIX) + find_package(Threads REQUIRED) # GTest needs this and it's a static library endif() + + #Gtest as externalproject + + # Enable ExternalProject CMake module + include(ExternalProject) + + # Download and install GoogleMock + ExternalProject_Add( + gmock + URL https://googlemock.googlecode.com/files/gmock-1.7.0.zip + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gmock + # Disable install step + INSTALL_COMMAND "" + # Wrap download, configure and build steps in a script to log output + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + ) + # Create a libgmock target to be used as a dependency by test programs + add_library(libgmock IMPORTED STATIC GLOBAL) + add_dependencies(libgmock gmock) + + # Set gmock properties + ExternalProject_Get_Property(gmock source_dir binary_dir) + set_target_properties(libgmock PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/libgmock.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" + # "INTERFACE_INCLUDE_DIRECTORIES" "${source_dir}/include" + ) + set(GMOCK_INCLUDE_DIRS ${source_dir}/include) + set(GTEST_INCLUDE_DIRS ${source_dir}/gtest/include) + + if(MSVC) + set(Suffix ".lib") + else() + set(Suffix ".a") + endif() + set(CUKE_GTEST_LIBRARIES + "${binary_dir}/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${Suffix}" + ${CMAKE_THREAD_LIBS_INIT} + ) + set(CUKE_GMOCK_LIBRARIES + "${binary_dir}/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${Suffix}" + "${binary_dir}/libgmock${Suffix}" + "${binary_dir}/libgmock_main${Suffix}" + ${CMAKE_THREAD_LIBS_INIT} + ) endif() # # Cucumber-Cpp # -set(CUKE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) +set(CUKE_INCLUDE_DIR ${CUKE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CUKE_INCLUDE_DIR}) diff --git a/Gemfile b/Gemfile index 5cff3f9f..8f635c3e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' group :test do - gem 'cucumber', "=1.3.6" + gem 'cucumber', "=1.3.20" gem 'aruba' gem 'rspec' end diff --git a/cmake/modules/FindGMock.cmake b/cmake/modules/FindGMock.cmake deleted file mode 100644 index c743c241..00000000 --- a/cmake/modules/FindGMock.cmake +++ /dev/null @@ -1,113 +0,0 @@ -# Locate the Google C++ Mocking Framework. -# (This file is almost an identical copy of the original FindGTest.cmake file, -# feel free to use it as it is or modify it for your own needs.) -# -# -# Defines the following variables: -# -# GMOCK_FOUND - Found the Google Testing framework -# GMOCK_INCLUDE_DIRS - Include directories -# -# Also defines the library variables below as normal -# variables. These contain debug/optimized keywords when -# a debugging library is found. -# -# GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main -# GMOCK_LIBRARIES - libgmock -# GMOCK_MAIN_LIBRARIES - libgmock-main -# -# Accepts the following variables as input: -# -# GMOCK_ROOT - (as a CMake or environment variable) -# The root directory of the gmock install prefix -# -# -#----------------------- -# Example Usage: -# -# find_package(GMock REQUIRED) -# include_directories(${GMOCK_INCLUDE_DIRS}) -# -# add_executable(foo foo.cc) -# target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES}) -# -#============================================================================= -# This file is released under the MIT licence: -# -# Copyright (c) 2011 Matej Svec -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -#============================================================================= - - -function(_gmock_append_debugs _endvar _library) - if(${_library} AND ${_library}_DEBUG) - set(_output optimized ${${_library}} debug ${${_library}_DEBUG}) - else() - set(_output ${${_library}}) - endif() - set(${_endvar} ${_output} PARENT_SCOPE) -endfunction() - -function(_gmock_find_library _name) - find_library(${_name} - NAMES ${ARGN} - HINTS - $ENV{GMOCK_ROOT} - ${GMOCK_ROOT} - PATH_SUFFIXES ${_gmock_libpath_suffixes} - ) - mark_as_advanced(${_name}) -endfunction() - - -set(_gmock_libpath_suffixes lib) -if(MSVC) - if(MSVC_VERSION GREATER 1400) - list(APPEND _gmock_libpath_suffixes - msvc/2010/Debug - msvc/2010/Release) - else() - list(APPEND _gmock_libpath_suffixes - msvc/2005/Debug - msvc/2005/Release) - endif() -endif() - -find_path(GMOCK_INCLUDE_DIR gmock/gmock.h - HINTS - $ENV{GMOCK_ROOT}/include - ${GMOCK_ROOT}/include -) -mark_as_advanced(GMOCK_INCLUDE_DIR) - -_gmock_find_library(GMOCK_LIBRARY gmock) -_gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd) -_gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main) -_gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY) - -if(GMOCK_FOUND) - set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR}) - _gmock_append_debugs(GMOCK_LIBRARIES GMOCK_LIBRARY) - _gmock_append_debugs(GMOCK_MAIN_LIBRARIES GMOCK_MAIN_LIBRARY) - set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) -endif() - diff --git a/examples/Calc/CMakeLists.txt b/examples/Calc/CMakeLists.txt index 3c547969..aeb859d7 100644 --- a/examples/Calc/CMakeLists.txt +++ b/examples/Calc/CMakeLists.txt @@ -4,10 +4,10 @@ include_directories(${CUKE_INCLUDE_DIRS} src) add_library(Calc src/Calculator) -if(GTEST_FOUND) +if(NOT CUKE_DISABLE_GTEST) include_directories(${GTEST_INCLUDE_DIRS}) add_executable(GTestCalculatorSteps features/step_definitions/GTestCalculatorSteps) - target_link_libraries(GTestCalculatorSteps Calc ${GTEST_LIBRARIES} ${CUKE_LIBRARIES}) + target_link_libraries(GTestCalculatorSteps Calc ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES}) endif() if(CPPSPEC_FOUND) diff --git a/examples/FeatureShowcase/CMakeLists.txt b/examples/FeatureShowcase/CMakeLists.txt index 29021bc4..b4b694f1 100644 --- a/examples/FeatureShowcase/CMakeLists.txt +++ b/examples/FeatureShowcase/CMakeLists.txt @@ -2,12 +2,12 @@ project(FeatureShowcase) include_directories(${CUKE_INCLUDE_DIRS}) -if(GTEST_FOUND) +if(NOT CUKE_DISABLE_GTEST) include_directories(${GTEST_INCLUDE_DIRS}) function(add_cucumber_executable) add_executable(FeatureShowcaseSteps ${ARGV}) - target_link_libraries(FeatureShowcaseSteps ${GTEST_LIBRARIES} ${CUKE_LIBRARIES}) + target_link_libraries(FeatureShowcaseSteps ${CUKE_LIBRARIES} ${CUKE_GTEST_LIBRARIES}) foreach(_arg ${ARGN}) get_filename_component(OBJECT_PREFIX ${_arg} NAME_WE) set_source_files_properties(${_arg} PROPERTIES COMPILE_FLAGS "-DCUKE_OBJECT_PREFIX=${OBJECT_PREFIX}") diff --git a/features/step_definitions/cucumber_cpp_mappings.rb b/features/step_definitions/cucumber_cpp_mappings.rb index 9dee4c36..3a041f75 100644 --- a/features/step_definitions/cucumber_cpp_mappings.rb +++ b/features/step_definitions/cucumber_cpp_mappings.rb @@ -172,11 +172,11 @@ def assert_executed_scenarios *scenario_offsets end def assert_world_variable_held_value_at_time(value, time) - check_exact_file_content "#{WORLD_VARIABLE_LOG_FILE}.#{time}", value + check_file_content("#{WORLD_VARIABLE_LOG_FILE}.#{time}", value, true) end def assert_world_function_called - check_file_presence [WORLD_FUNCTION_LOG_FILE], true + expect(WORLD_FUNCTION_LOG_FILE).to be_existing_file end def assert_cycle_sequence *args @@ -192,7 +192,7 @@ def assert_cycle_sequence_excluding *args def assert_complete_cycle_sequence *args expected_string = "#{CYCLE_SEQUENCE_SEPARATOR}#{args.join(CYCLE_SEQUENCE_SEPARATOR)}" - check_exact_file_content(CYCLE_LOG_FILE, expected_string) + check_file_content(CYCLE_LOG_FILE, expected_string, true) end def assert_data_table_equals_json(json) @@ -200,7 +200,7 @@ def assert_data_table_equals_json(json) log_file_contents = IO.read(DATA_TABLE_LOG_FILE) actual_array = JSON.parse(log_file_contents) expected_array = JSON.parse(json) - actual_array.should == expected_array + expect(actual_array).to be == expected_array end end @@ -302,7 +302,7 @@ def write_main_step_definitions_file def compile_step_definitions compiler_output = %x[ #{COMPILE_STEP_DEFINITIONS_CMD} ] - expect($?.success?).to be_true, "Compilation failed!\n#{compiler_output}" + expect($?.success?).to be == true, "Compilation failed!\n#{compiler_output}" end def create_wire_file diff --git a/include/cucumber-cpp/internal/hook/HookRegistrar.hpp b/include/cucumber-cpp/internal/hook/HookRegistrar.hpp index bee9009b..dc97b569 100644 --- a/include/cucumber-cpp/internal/hook/HookRegistrar.hpp +++ b/include/cucumber-cpp/internal/hook/HookRegistrar.hpp @@ -35,7 +35,7 @@ class BeforeHook : public Hook { class AroundStepHook : public Hook { public: - virtual void invokeHook(Scenario *scenario, CallableStep *step); + virtual void invokeHookWithStep(Scenario *scenario, CallableStep *step); virtual void skipHook(); protected: CallableStep *step; diff --git a/include/cucumber-cpp/internal/hook/Tag.hpp b/include/cucumber-cpp/internal/hook/Tag.hpp index 22634001..48db4a00 100644 --- a/include/cucumber-cpp/internal/hook/Tag.hpp +++ b/include/cucumber-cpp/internal/hook/Tag.hpp @@ -16,6 +16,7 @@ class TagExpression { public: typedef std::vector tag_list; + virtual ~TagExpression() { } virtual bool matches(const tag_list &tags) = 0; }; diff --git a/include/cucumber-cpp/internal/step/StepManager.hpp b/include/cucumber-cpp/internal/step/StepManager.hpp index 41992230..1b2cbe78 100644 --- a/include/cucumber-cpp/internal/step/StepManager.hpp +++ b/include/cucumber-cpp/internal/step/StepManager.hpp @@ -62,6 +62,11 @@ class InvokeArgs { template T getInvokeArg(size_type i) const; const Table & getTableArg() const; + + size_type argsSize() const { + return args.size(); + } + private: Table tableArg; args_type args; @@ -91,7 +96,7 @@ class InvokeResult { bool isSuccess() const; bool isPending() const; - const InvokeResultType getType() const; + InvokeResultType getType() const; const std::string &getDescription() const; }; @@ -157,7 +162,7 @@ class StepManager { }; -static 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); diff --git a/include/cucumber-cpp/internal/utils/Regex.hpp b/include/cucumber-cpp/internal/utils/Regex.hpp index 55f1e5c9..08bc1205 100644 --- a/include/cucumber-cpp/internal/utils/Regex.hpp +++ b/include/cucumber-cpp/internal/utils/Regex.hpp @@ -1,8 +1,11 @@ #ifndef CUKE_REGEX_HPP_ #define CUKE_REGEX_HPP_ +#include #include +#define BOOST_REGEX_V4_CHAR_REGEX_TRAITS_HPP + #include namespace cucumber { diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..75028b28 --- /dev/null +++ b/run.sh @@ -0,0 +1,13 @@ +#rvm install 2.2 +ruby -v +gem install bundler +rm Gemfile.lock +rm build -rf +cmake -E make_directory build +cmake -E chdir build cmake -DCUKE_ENABLE_EXAMPLES=on -DCUKE_DISABLE_BOOST_TEST=on .. +cmake --build build +cmake --build build --target test +cmake --build build --target features +build/examples/Calc/GTestCalculatorSteps >/dev/null & +cucumber examples/Calc +killall GTestCalculatorSteps diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5baa3a76..849d9178 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ set(CUKE_SOURCES connectors/wire/WireProtocolCommands.cpp ) -if(GTEST_FOUND) +if(NOT CUKE_DISABLE_GTEST) include_directories(${GTEST_INCLUDE_DIRS}) list(APPEND CUKE_SOURCES drivers/GTestDriver.cpp) endif() diff --git a/src/CukeEngineImpl.cpp b/src/CukeEngineImpl.cpp index 290b1f0b..fb594c0c 100644 --- a/src/CukeEngineImpl.cpp +++ b/src/CukeEngineImpl.cpp @@ -55,13 +55,13 @@ void CukeEngineImpl::invokeStep(const std::string & id, const invoke_args_type & if (tableArg.shape()[0] > 1 && tableArg.shape()[1] > 0) { Table & commandTableArg = commandArgs.getVariableTableArg(); - for (table_index j = 0; j < tableArg.shape()[1]; ++j) { + for (table_index j = 0; j < table_index(tableArg.shape()[1]); ++j) { commandTableArg.addColumn(tableArg[0][j]); } - for (table_index i = 1; i < tableArg.shape()[0]; ++i) { + for (table_index i = 1; i < table_index(tableArg.shape()[0]); ++i) { Table::row_type row; - for (table_index j = 0; j < tableArg.shape()[1]; ++j) { + for (table_index j = 0; j < table_index(tableArg.shape()[1]); ++j) { row.push_back(tableArg[i][j]); } commandTableArg.addRow(row); @@ -87,11 +87,11 @@ 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 13e92dc1..eb52caa2 100644 --- a/src/HookRegistrar.cpp +++ b/src/HookRegistrar.cpp @@ -24,7 +24,7 @@ bool Hook::tagsMatch(Scenario *scenario) { return !scenario || tagExpression->matches(scenario->getTags()); } -void AroundStepHook::invokeHook(Scenario *scenario, CallableStep *step) { +void AroundStepHook::invokeHookWithStep(Scenario *scenario, CallableStep *step) { this->step = step; Hook::invokeHook(scenario); } @@ -155,7 +155,7 @@ void StepCallChain::execNext() { } else { HookRegistrar::aroundhook_list_type::iterator currentHook = nextHook++; CallableStepChain callableStepChain(this); - (*currentHook)->invokeHook(scenario, &callableStepChain); + (*currentHook)->invokeHookWithStep(scenario, &callableStepChain); } } diff --git a/src/StepManager.cpp b/src/StepManager.cpp index 20838c3a..73a9781f 100644 --- a/src/StepManager.cpp +++ b/src/StepManager.cpp @@ -114,7 +114,7 @@ bool InvokeResult::isPending() const { return (type == PENDING); } -const InvokeResultType InvokeResult::getType() const { +InvokeResultType InvokeResult::getType() const { return type; } diff --git a/src/connectors/wire/WireProtocol.cpp b/src/connectors/wire/WireProtocol.cpp index b12706e8..e94013d3 100644 --- a/src/connectors/wire/WireProtocol.cpp +++ b/src/connectors/wire/WireProtocol.cpp @@ -88,7 +88,8 @@ void SnippetTextResponse::accept(WireResponseVisitor *visitor) const { class CommandDecoder { public: - virtual WireCommand *decode(const mValue & jsonArgs) const = 0; + virtual ~CommandDecoder() { } + virtual WireCommand *decode(const mValue & jsonArgs) const = 0; }; @@ -256,7 +257,7 @@ namespace { return write_string(v, false); } - void visit(const SuccessResponse *response) { + void visit(const SuccessResponse* /*response*/) { success(); } diff --git a/src/connectors/wire/WireProtocolCommands.cpp b/src/connectors/wire/WireProtocolCommands.cpp index 1209b6d0..a8f00a17 100644 --- a/src/connectors/wire/WireProtocolCommands.cpp +++ b/src/connectors/wire/WireProtocolCommands.cpp @@ -71,7 +71,7 @@ WireResponse *SnippetTextCommand::run(CukeEngine *engine) const { } -WireResponse *FailingCommand::run(CukeEngine *engine) const { +WireResponse *FailingCommand::run(CukeEngine* /*engine*/) const { return new FailureResponse; } diff --git a/src/connectors/wire/WireServer.cpp b/src/connectors/wire/WireServer.cpp index 915c272f..64ac2249 100644 --- a/src/connectors/wire/WireServer.cpp +++ b/src/connectors/wire/WireServer.cpp @@ -4,9 +4,9 @@ namespace cucumber { namespace internal { SocketServer::SocketServer(const ProtocolHandler *protocolHandler) : + protocolHandler(protocolHandler), ios(), - acceptor(ios), - protocolHandler(protocolHandler) { + acceptor(ios) { } void SocketServer::listen(const port_type port) { diff --git a/src/drivers/BoostDriver.cpp b/src/drivers/BoostDriver.cpp index ec74ab40..8525643d 100644 --- a/src/drivers/BoostDriver.cpp +++ b/src/drivers/BoostDriver.cpp @@ -15,13 +15,18 @@ namespace internal { namespace { - -bool boost_test_init() { +#ifdef BOOST_TEST_ALTERNATIVE_INIT_API + bool boost_init_unit_test() { return true; -} - -static CukeBoostLogInterceptor *logInterceptor = 0; - + } +#else + ::boost::unit_test::test_suite* + boost_init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { + return NULL; + } +#endif + + static CukeBoostLogInterceptor *logInterceptor = 0; } @@ -31,19 +36,19 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt void reset(); // Formatter - void log_start( std::ostream&, counter_t test_cases_amount) {}; + void log_start( std::ostream&, counter_t /*test_cases_amount*/) {}; void log_finish( std::ostream&) {}; void log_build_info( std::ostream&) {}; - void test_unit_start( std::ostream&, test_unit const& tu) {}; - void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed) {}; - void test_unit_skipped( std::ostream&, test_unit const& tu) {}; + void test_unit_start( std::ostream&, test_unit const& /*tu*/) {}; + void test_unit_finish( std::ostream&, test_unit const& /*tu*/, unsigned long /*elapsed*/) {}; + void test_unit_skipped( std::ostream&, test_unit const& /*tu*/) {}; - void log_exception( std::ostream&, log_checkpoint_data const&, execution_exception const& ex) {}; + void log_exception( std::ostream&, log_checkpoint_data const&, execution_exception const& /*ex*/) {}; - void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let) {}; - void log_entry_value( std::ostream&, const_string value); - void log_entry_value( std::ostream&, lazy_ostream const& value) {}; + void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types /*let*/) {}; + void log_entry_value( std::ostream&, const_string /*value*/); + void log_entry_value( std::ostream&, lazy_ostream const& /*value*/) {}; void log_entry_finish( std::ostream&) {}; void log_exception(std::ostream&, const boost::unit_test::log_checkpoint_data&, boost::unit_test::const_string) {}; @@ -83,7 +88,12 @@ void BoostStep::initBoostTest() { if (!framework::is_initialized()) { int argc = 2; char *argv[] = { (char *) "", (char *) "" }; - framework::init(&boost_test_init, argc, argv); + +#ifdef BOOST_TEST_ALTERNATIVE_INIT_API + framework::init(&boost_init_unit_test, argc, argv); +#else + framework::init(&boost_init_unit_test_suite, argc, argv); +#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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec9a7ddf..bdeead21 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,37 @@ +# Thanks to Daniel Blezek for the GTEST_ADD_TESTS code + +function(GTEST_ADD_TESTS executable extra_args) + if(NOT ARGN) + message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS") + endif() + if(ARGN STREQUAL "AUTO") + # obtain sources used for building that executable + get_property(ARGN TARGET ${executable} PROPERTY SOURCES) + endif() + set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+) *, *([A-Za-z_0-9]+) *\\).*") + set(gtest_test_type_regex "(TYPED_TEST|TEST_?[FP]?)") + foreach(source ${ARGN}) + file(READ "${source}" contents) + string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents}) + foreach(hit ${found_tests}) + string(REGEX MATCH "${gtest_test_type_regex}" test_type ${hit}) + + # Parameterized tests have a different signature for the filter + if("x${test_type}" STREQUAL "xTEST_P") + string(REGEX REPLACE ${gtest_case_name_regex} "*/\\1.\\2/*" test_name ${hit}) + elseif("x${test_type}" STREQUAL "xTEST_F" OR "x${test_type}" STREQUAL "xTEST") + string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" test_name ${hit}) + elseif("x${test_type}" STREQUAL "xTYPED_TEST") + string(REGEX REPLACE ${gtest_case_name_regex} "\\1/*.\\2" test_name ${hit}) + else() + message(WARNING "Could not parse GTest ${hit} for adding to CTest.") + continue() + endif() + add_test(NAME ${test_name} COMMAND ${executable} --gtest_filter=${test_name} ${extra_args}) + endforeach() + endforeach() +endfunction() + function(cuke_add_driver_test TEST_FILE) get_filename_component(TEST_NAME ${TEST_FILE} NAME) message(STATUS "Adding " ${TEST_NAME}) @@ -6,7 +40,7 @@ function(cuke_add_driver_test TEST_FILE) add_test(${TEST_NAME} ${TEST_NAME}) endfunction() -if(CUKE_TEST_LIBRARIES) +if(NOT CUKE_DISABLE_GTEST) include_directories(${GTEST_INCLUDE_DIRS}) include_directories(${GMOCK_INCLUDE_DIRS}) @@ -14,7 +48,7 @@ if(CUKE_TEST_LIBRARIES) get_filename_component(TEST_NAME ${TEST_FILE} NAME) message(STATUS "Adding " ${TEST_NAME}) add_executable(${TEST_NAME} ${TEST_FILE}.cpp) - target_link_libraries(${TEST_NAME} ${CUKE_TEST_LIBRARIES} cucumber-cpp-nomain ${CUKE_EXTRA_LIBRARIES} ${ARGN}) + target_link_libraries(${TEST_NAME} cucumber-cpp-nomain ${CUKE_EXTRA_LIBRARIES} ${ARGN} ${CUKE_GMOCK_LIBRARIES}) gtest_add_tests(${TEST_NAME} "" ${TEST_FILE}.cpp) endfunction() @@ -36,7 +70,7 @@ if(CUKE_TEST_LIBRARIES) cuke_add_test(unit/TableTest) cuke_add_test(unit/TagTest) - cuke_add_driver_test(integration/drivers/GTestDriverTest ${GTEST_LIBRARIES}) + cuke_add_driver_test(integration/drivers/GTestDriverTest ${CUKE_GTEST_LIBRARIES}) endif() if(CPPSPEC_FOUND) diff --git a/tests/utils/HookRegistrationFixture.hpp b/tests/utils/HookRegistrationFixture.hpp index a488bc2b..6eebcd6b 100644 --- a/tests/utils/HookRegistrationFixture.hpp +++ b/tests/utils/HookRegistrationFixture.hpp @@ -54,7 +54,7 @@ class HookRegistrarDouble : public HookRegistrar { EmptyCallableStep emptyStep; aroundhook_list_type &ash = aroundStepHooks(); for (HookRegistrar::aroundhook_list_type::const_iterator h = ash.begin(); h != ash.end(); ++h) { - (*h)->invokeHook(scenario, &emptyStep); + (*h)->invokeHookWithStep(scenario, &emptyStep); } } }; diff --git a/travis.sh b/travis.sh new file mode 100755 index 00000000..d4169c6b --- /dev/null +++ b/travis.sh @@ -0,0 +1,9 @@ +ruby -v +gem install bundler +cmake -E make_directory build +cmake -E chdir build cmake -DCUKE_ENABLE_EXAMPLES=on .. +cmake --build build +cmake --build build --target test +cmake --build build --target features +build/examples/Calc/GTestCalculatorSteps >/dev/null & +cucumber examples/Calc