Skip to content

Setup UnitTest-cpp for CI #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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++
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# UnitTest-cpp
UnitTest-cpp <br>
[![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:
Expand Down
37 changes: 36 additions & 1 deletion UnitTest++/src/tests/TestTestMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,7 +164,9 @@ TEST(FixturesWithThrowingCtorsAreFailures)

struct FixtureDtorThrows
{
~FixtureDtorThrows() { throw "exception"; }
~FixtureDtorThrows() _NOEXCEPT_OP(false) {
throw "exception";
}
};

TestList throwingFixtureTestList2;
Expand Down