diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..40d9deb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: cpp + +matrix: + include: + - os: linux + dist: bionic + compiler: gcc + env: BUILD=Debug + - os: linux + dist: bionic + compiler: gcc + env: BUILD=Release + +script: + - mkdir -p build + - cd build + - cmake .. -DCMAKE_BUILD_TYPE=${BUILD} + - make + - ./TestUnitTest++ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..aadd69b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.10) +project(UnitTest++) + +option(UTPP_INCLUDE_TESTS_IN_BUILD + "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build" + OFF) + +set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64") + +####################################################################### +# Set up compiler flags +####################################################################### +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") +endif() +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -s") +endif() +string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -pedantic " + "-Winit-self -Wmissing-declarations -Wmissing-include-dirs " + "-Wundef -Wredundant-decls -Wfloat-equal -Wmain -Wcast-align " + "-Wswitch-enum") + +# get the main sources +file(GLOB headers_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/src/*.h) +file(GLOB sources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/src/*.cpp) +source_group("" FILES ${headers_} ${sources_}) + +# get platform specific sources +set(platformDir_ Posix) + +file(GLOB platformHeaders_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + UnitTest++/src/${platformDir_}/*.h) +file(GLOB platformSources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + UnitTest++/src/${platformDir_}/*.cpp) +source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_}) + +# create the lib +add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} + ${platformSources_}) + +set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++) + +# build the test runner +file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + UnitTest++/src/tests/*.cpp UnitTest++/src/tests/*.h) +source_group("" FILES ${TEST_SRCS}) +add_executable(TestUnitTest++ ${TEST_SRCS}) +include_directories(UnitTest++/src) + +set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) +target_link_libraries(TestUnitTest++ UnitTest++) + +# run unit tests as post build step +add_custom_command(TARGET TestUnitTest++ + POST_BUILD COMMAND TestUnitTest++ + COMMENT "Running unit tests") diff --git a/README.md b/README.md index 169f30b..bc34c3d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# UnitTest-cpp +UnitTest-cpp
+[![Build Status](https://travis-ci.org/liyier90/UnitTest-cpp.svg?branch=master)](https://travis-ci.org/liyier90/UnitTest-cpp) +======== + The snapshot of UnitTest++ we use for our test environment # IMPORTANT NOTE: diff --git a/UnitTest++/src/tests/TestTestMacros.cpp b/UnitTest++/src/tests/TestTestMacros.cpp index 8bed9dc..7535991 100644 --- a/UnitTest++/src/tests/TestTestMacros.cpp +++ b/UnitTest++/src/tests/TestTestMacros.cpp @@ -9,6 +9,39 @@ using namespace UnitTest; +/* test for c++11 support */ +#ifndef _MSC_VER + + /* Test for clang >= 3.3 */ + #ifdef __clang__ + #if (__clang__ == 1) && (__clang_major__ > 3 || (__clang_major__ == 3 && (__clang_minor__ > 2 ))) + #define _NOEXCEPT_OP(x) noexcept(x) + #else + #define _NOEXCEPT_OP(x) + #endif + #endif + + #ifndef __clang__ + /* Test for GCC >= 4.8.0 */ + #ifdef __GNUC__ + #if (__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ > 7 )) + #define _NOEXCEPT_OP(x) noexcept(x) + #else + #define _NOEXCEPT_OP(x) + #endif + #endif + #endif + +#elif _MSC_VER + + #if (_MSC_VER > 1800) + #define _NOEXCEPT_OP(x) noexcept(x) + #else + #define _NOEXCEPT_OP(x) + #endif + +#endif + namespace { TestList list1; @@ -131,7 +164,9 @@ TEST(FixturesWithThrowingCtorsAreFailures) struct FixtureDtorThrows { - ~FixtureDtorThrows() { throw "exception"; } + ~FixtureDtorThrows() _NOEXCEPT_OP(false) { + throw "exception"; + } }; TestList throwingFixtureTestList2;