Compare commits

...

79 commits

Author SHA1 Message Date
Patrick Johnmeyer
10e50ad70c
Extend hiatus to 26 November 2020-11-12 23:26:38 -06:00
Patrick Johnmeyer
854cae2518
Extend hiatus to 15 October
See #180
2020-10-01 19:56:11 -05:00
Patrick Johnmeyer
37df68be21
Add hiatus note & link to issue 2020-08-17 19:53:58 -05:00
Patrick Johnmeyer
0ea55a251b
Merge pull request #173 from dhuantes/install-improvements
UnitTest++ now correctly supports CMake's find_package config mode
2020-04-18 19:17:46 -05:00
Dan Huantes
f871471d90 Added Namespace to Exported Target
[CMakeLists.txt]
- It is standard practice to have a namespace
for an imported target.  Added UnitTest++::
as the namespace argument so that
find_package(UnitTest++) will result in
UnitTest++::UnitTest++ target that will
be used in target_link_libraries.
- Updated target_link_libraries for
TestUnitTest++ as an example
2020-04-07 18:07:24 -05:00
Dan Huantes
c269666681 Version made explicitly 3 parts
- Updated to appveyor.yml and
configure.ac to 2.1.0 to
match CMake project version.
2019-10-17 08:23:46 -05:00
Patrick Johnmeyer
d355e127be
Merge pull request #172 from Flow86/patch-1
add support to build unittest cpp on AIX (IBM)
2019-10-15 21:27:12 -05:00
Dan Huantes
2423fcac76 CrasingTestsAreReportedAsFailures no longer core dumps on Clang Release
Found that Crashing tests at some point in Clang
history were actually caught but testing on
Clang 6.0 and Clang 7.0 this is not the case.
So added Clang to the list of compilers that
don't run this tests.  Noted that several
other Pull Requests were failing for the same
reason.
2019-08-15 08:30:43 -05:00
Dan Huantes
bdef2bdd62 UnitTest++ now correctly supports CMake's find_package config mode
[CMakeLists.txt]
- Bumped cmake minimum requirement to go to 3.0 as this
appears to be earliest version that transitive usage
requirements are supported.
- Added version to project so that is evident
when looking at CMakeLists.txt
- Removed include_directories as that command
affects more than just UnitTest++ in favor
of target_include_directories.
- The target_include_directories uses the
generator expressions to do the same thing
for the BUILD_INTERFACE condition but only
affects UnitTest++.  The INSTALL_INTERFACE
ensures that when UnitTest++ is installed
client applications calling find_package
for UnitTest++ only have to add the
UnitTest++ target to the target_link_libraries
and will get the correct include path
for UnitTest++ added to their include paths.
- Added DEBUG_POSTFIX to both library and
unit test to distinguish them from each other
as they are installed into the same directory
and would otherwise overwrite one another.
- Added Versioning using write_basic_package_version_file
to the install so that a client can call
find_package(UnitTest++ 2.1 REQUIRED) and it will be
able to confirm the version.  If the version is updated
you could theoretically ahve a version 2.2, 2.3 ,etc...
and the find_package mechanism will find the correct one.
the SameMajorVersion option in that call indicates
that 2.3 is compatible with 2.1 or in other words if
find_package(UnitTest++ 2.1 REQUIRED) is called and
2.3 is installed that satisfies the condition but
if only 3.0 was installed it will fail because of
'SameMajorVersion'.
- Also added installation for the Version file.
2019-08-15 07:26:45 -05:00
Flow86
a7d506d7eb
add support to build unittest cpp on AIX (IBM) 2019-03-20 13:19:15 +01:00
Patrick Johnmeyer
bc5d87f484 Merge pull request #161 from martinmoene/cmake
Use if (MSVC) as per issue #160
2017-07-08 10:06:47 -05:00
Martin Moene
a6fdaeef12 Use if (MSVC) as per issue #160 2017-07-08 11:09:38 +02:00
Patrick Johnmeyer
85b3666173 Merge pull request #149 from timdave13/patch-1
fix clang warnings
2017-07-07 23:16:00 -05:00
Patrick Johnmeyer
8c460c48e6 Merge pull request #141 from Reification/feature-MSVC-Clang
Feature msvc clang
2017-06-30 23:46:28 -05:00
Patrick Johnmeyer
65af507437 Merge pull request #155 from vicentebolea/adding-autogen-script
Added autogen.sh file to ease autotools installation
2017-06-30 23:35:29 -05:00
Patrick Johnmeyer
ee996164f2 Merge branch 'master' into feature-MSVC-Clang 2017-06-30 23:31:18 -05:00
Patrick Johnmeyer
af28992c5d Merge pull request #148 from cwilling/add-lib_dir
Add support for LIB_SUFFIX
2017-06-30 23:13:06 -05:00
Vicente Adolfo Bolea Sanchez
33e6314753 Added autogen.sh file to ease autotools installation 2017-05-22 00:22:38 +09:00
Tim Bochenek
07d4872076 fix clang warnings
fix clang warning warning: no previous extern declaration for non-static variable 'X' [-Wmissing-variable-declarations]
2017-02-03 08:19:17 -05:00
Gabriel Hare
0b15459ee4 Downgrade message to STATUS and do not declare C++11 as a requirement. 2017-02-02 21:56:48 -08:00
Tim Bochenek
0a6857e388 fix clang warning
fix clang warning 'extra ';' outside function is c++11 extension
2017-02-02 18:03:59 -05:00
timdave13
d7bd757862 fix clang warning
fix clang warning: 'X' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Wweak-vtables]
2017-02-02 17:14:27 -05:00
Christoph Willing
0757ba8f90
Add support for LIB_SUFFIX
Signed-off-by: Christoph Willing <chris.willing@iinet.net.au>
2017-01-23 17:49:12 +10:00
Patrick Johnmeyer
c331bb0dea Merge pull request #146 from iblis17/fbsd-cmake
cmake: fix pkgconfig dir path on FreeBSD
2017-01-19 19:00:12 -06:00
Iblis Lin
85bade33f5 cmake: fix pkgconfig dir path on FreeBSD 2017-01-14 23:00:24 +08:00
Patrick Johnmeyer
d0980fe7e2 Merge pull request #143 from unittest-cpp/v2-prep
v2.0.0 prep

Closes #96
2017-01-13 15:55:01 -06:00
Patrick Johnmeyer
615b6cdd0f Add note re: autotools to INSTALL file 2017-01-13 14:51:19 -06:00
Patrick Johnmeyer
8e5968bb05 Roll version number to 2.0.0 2017-01-13 14:38:23 -06:00
Patrick Johnmeyer
8d70dff05b Delete unused ChangeLog file
Closes #138
2017-01-13 14:38:07 -06:00
Patrick Johnmeyer
5e3b37825c Merge pull request #139 from edanaher/pkgconfig-with-cmake
Build pkgconfig file with CMake, not just with autoconf.

Fixes #89
2017-01-13 13:28:25 -06:00
Gabriel Hare
a2fe23887a Use “MATCHES” instead of “STREQUAL” to avoid ambiguous comparison.
NOTE: Unlike STREQUAL this comparison is supported pre and post CMake v3.1.0
2016-12-15 02:50:09 -08:00
Gabriel Hare
bb49539107 Revert "Increase CMake version to resolve developer warnings regarding implicit quoted dereference in STREQUAL comparison"
This reverts commit 8f7a263446.
2016-12-15 02:46:13 -08:00
Gabriel Hare
c4ab9d31ed Identify Clang compiler when used as an MSVC extension 2016-12-15 00:40:03 -08:00
Gabriel Hare
8f7a263446 Increase CMake version to resolve developer warnings regarding implicit quoted dereference in STREQUAL comparison 2016-12-15 00:31:56 -08:00
Gabriel Hare
9eba823269 Demonstrate that compiler is identified as MSVC when VS2014 Clang extension is used 2016-12-14 23:11:20 -08:00
Patrick Johnmeyer
478b6545b2 Merge pull request #135 from jumonatr/master
Update Docs Hash
2016-12-03 22:57:09 -06:00
Evan Danaher
40f90dc601 Build pkgconfig file with CMake, not just with autoconf. 2016-12-01 12:52:48 -05:00
Julien Monat Rodier
0d77b1ae10 Update docs reference to avoid bad path names on windows 2016-10-11 13:00:40 -07:00
Patrick Johnmeyer
d8e27e1825 Merge pull request #127 from pjohnmeyer/up_gcc_clang_warning_levels
Up non-MSVC warning levels
2016-08-30 20:45:40 -05:00
Patrick Johnmeyer
1d0e157c5a Merge pull request #126 from pjohnmeyer/up_msvc_warning_levels
Up MSVC warning levels
2016-08-30 20:45:20 -05:00
Patrick Johnmeyer
c431be9f94 Merge pull request #128 from killoctal/useSize_t
Use size_t for array or vector index
2016-08-30 20:44:49 -05:00
Gabriel Schlozer
eca039304b Used size_t for CHECK macros 2016-08-29 22:36:31 +02:00
Patrick Johnmeyer
7d7ba0aba4 Re-enable ignored-qualifiers warning and fix 2016-08-27 20:41:41 -05:00
Patrick Johnmeyer
e161d44077 Use CMake SET instead of string CONCAT
string(CONCAT...) was not available in older versions of CMake
targeted by this project.
2016-08-27 10:04:54 -05:00
Patrick Johnmeyer
2e2475fa54 Fix unused variable warnings 2016-08-27 09:55:37 -05:00
Patrick Johnmeyer
f0044e919d Up warning level to -Wall/extra/error for non-MSVC
UTPP_AMPLIFY_WARNINGS can be turned OFF to disable the new behavior.
2016-08-27 09:54:32 -05:00
Patrick Johnmeyer
7e4fff3bb4 Fix "assignment operator could not be generated" warning
This shows up with /W4 on MSVC. Fixes #107.
2016-08-27 08:27:15 -05:00
Patrick Johnmeyer
7c15942751 Up warning level to /W4 /WX for MSVC-like compilers
Also adds a CMake option, UTPP_AMPLIFY_WARNINGS, that can be turned
OFF to disable the new behavior.
2016-08-27 08:26:05 -05:00
Patrick Johnmeyer
83dbcc076d Merge pull request #115 from unittest-cpp/add_cmake_option_to_disable_running_tests_as_build_step
Add UTPP_INCLUDE_TESTS_IN_BUILD CMake option
2016-08-16 22:45:34 -05:00
Patrick Johnmeyer
097c71e6b8 Merge pull request #114 from unittest-cpp/long_and_short_macros
Long and short macros
2016-08-16 22:41:13 -05:00
Patrick Johnmeyer
77ae15ab8a Merge pull request #120 from pjohnmeyer/check_by_reference
Take UnitTest::Check parameter by const reference
2016-08-16 22:22:58 -05:00
Patrick Johnmeyer
6b69ed78ba Skip test build with same option as run
As part of this, changed the option name to
`UTPP_INCLUDE_TESTS_IN_BUILD`. The test target is still added to the
build and can be built/run separately using the CMake --target option.
2016-07-18 21:13:03 -05:00
Patrick Johnmeyer
14f317c40c Eliminate double-negative in option name / value
UTPP_SKIP_TESTS_AS_BUILD_STEP with a default value of OFF was an
unfortunate choice, so this changes it to UTPP_RUN_TESTS_AS_BUILD_STEP
with a default value of ON.
2016-07-18 20:49:18 -05:00
Patrick Johnmeyer
fa97152619 Add UTPP_SKIP_TESTS_AS_BUILD_STEP CMake option
Helps address #104.
2016-07-18 20:49:18 -05:00
Patrick Johnmeyer
de915185f6 Remove unused variable from test copy constructor 2016-07-15 23:58:48 -05:00
Patrick Johnmeyer
bec6ba56ec Attempted fix for Travis build. 2016-07-15 23:54:59 -05:00
Patrick Johnmeyer
21589e5612 Take UnitTest::Check parameter by const reference
Fixes #119 and #7
2016-07-15 23:23:45 -05:00
Patrick Johnmeyer
510903c880 Merge pull request #117 from korli/master
Add support for Haiku.
2016-07-15 22:58:31 -05:00
Patrick Johnmeyer
c7a9e7fd9e Merge pull request #116 from JonChesterfield/master
Prefix local variable message in CHECK macros with UnitTest_
2016-07-15 22:54:17 -05:00
Jerome Duval
053bcfc9c7 Add support for Haiku. 2016-06-03 13:13:33 +02:00
JonChesterfield
27317ec077 Prefix local variable message in CHECK macros with UnitTest_ to reduce the risk of name collisions with application code 2016-05-16 11:13:51 +01:00
Patrick Johnmeyer
910381fadc Change UNITTEST_ENABLE_SHORT_MACROS to DISABLE
Also add a test file.
2016-05-07 01:02:20 -05:00
Patrick Johnmeyer
df386f189f Add UNITTEST_ prefixes to remaining macros
TEST, SUITE, and REQUIRE macros now have UNITTEST_ and UNITTEST_IMPL_
prefixes like the others, completing the set.
2016-05-07 00:12:09 -05:00
Patrick Johnmeyer
c96bf52613 Replace UT_ macro prefix with UNITTEST_IMPL_
The UT_ prefix was primarily for "internal" macros. This commit seeks
to more consistently "namespace" UnitTest++ macros with the UNITTEST_
prefix, while also marking these particular macros as "private"
implementation details with the IMPL_ wart.
2016-05-06 23:57:59 -05:00
Patrick Johnmeyer
185b3d5086 Add UNITTEST_ versions of all CHECK macros
UNITTEST_ now prefixes the implementation of all CHECK macros.
Additionally, the build option UNITTEST_ENABLE_SHORT_MACROS can be
shut off, disabling the creation of the existing short forms. This is
helpful for users who may have conflicts with their projects or other
libs.
2016-05-06 23:44:02 -05:00
Patrick Johnmeyer
d220612eba Merge pull request #111 from unittest-cpp/v1.6.1-prep
v1.6.1 prep
2016-05-04 22:48:32 -05:00
Patrick Johnmeyer
782e620fbb Update versions to 1.6.1 2016-05-04 21:36:40 -05:00
Patrick Johnmeyer
1a62540b79 Determine autoconf package version from git tags 2016-05-04 21:30:44 -05:00
Patrick Johnmeyer
b7e0d70a63 Fix failures in make distcheck 2016-04-25 13:37:31 -05:00
Patrick Johnmeyer
90357e2138 Merge pull request #109 from bittwiddler1/master
autoconf & automake improvements
2016-04-19 22:13:28 -05:00
Patrick Johnmeyer
8973952bbe Merge pull request #106 from jasonhorsburgh/master
Add support for CMake find_package()

Fixes #99
2016-04-19 22:09:19 -05:00
Patrick Johnmeyer
032e495bba Merge branch 'master' of https://github.com/jasonhorsburgh/unittest-cpp into jasonhorsburgh-master
Conflicts:
	CMakeLists.txt
2016-04-19 22:08:24 -05:00
Patrick Johnmeyer
843d17398f Merge pull request #110 from stubb/patch-1
Fix spelling of UTPP_USE_PLUS_SIGN option comment.
2016-04-19 21:51:48 -05:00
bittwiddler1
791c37a9f1 Enabling silent build rules for automake 2016-04-16 19:12:21 -04:00
Kilian Köppchen
451ba1e2bc Fix spelling of UTPP_USE_PLUS_SIGN option comment. 2016-04-14 15:23:10 +02:00
bittwiddler1
2a806451b1 Comment changes
Making the comments more explicative and less opinionated. :)
2016-04-07 15:03:34 -04:00
Saul Beniquez
80d6bf7568 Better native OS detection using AC_CANONICAL_HOST. More information here: https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Canonicalizing.html 2016-04-07 14:56:31 -04:00
Saul Beniquez
8544b5b6be Fix for #105 - Automake improvements: fixing pkgincludedir. 2016-04-07 14:55:53 -04:00
Jason Horsburgh
e88121f69e Add support for CMake find_package()
Added export configuration for UnitTest++ target and installed the export and config file in libs/cmake/UnitTest++.
Added basic UnitTest++Config.cmake file which includes exported targets file and sets UTPP_INCLUDE_DIRS to the install location of the includes directory, this allows UnitTest++ to be used as a normal target in your own CMakeLists.txt file.

e.g.:

    find_package(UnitTest++ REQUIRED NO_MODULE)
    add_executable(foo ...)
    include_directories(${UTPP_INCLUDE_DIRS})
    target_link_libraries(foo UnitTest++)

which will ensure the library and installed headers paths are set up correctly for your own target.
2016-03-15 12:14:19 +00:00
27 changed files with 417 additions and 182 deletions

View file

@ -1,10 +1,26 @@
cmake_minimum_required(VERSION 2.8.1)
project(UnitTest++)
cmake_minimum_required(VERSION 3.0)
project(UnitTest++ VERSION 2.1.0)
option(UTPP_USE_PLUS_SIGN "Set this to OFF is you with to use '-cpp' instead of '++' in lib/include paths" ON)
option(UTPP_USE_PLUS_SIGN
"Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
ON)
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"
ON)
option(UTPP_AMPLIFY_WARNINGS
"Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler"
ON)
if(MSVC14 OR MSVC12)
# has the support we need
set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64")
if (MSVC)
# CHECK_CXX_COMPILER_FLAG could be used
# but MSVC version is preferred for feature requirements
if (MSVC14 OR MSVC12)
# has the support we need
else()
message(STATUS "The MSVC compiler version does not support UnitTest++ C++11 features.")
endif()
else()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
@ -14,7 +30,18 @@ else()
elseif(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
endif()
# up warning level for project
if (${UTPP_AMPLIFY_WARNINGS})
# instead of getting compiler specific, we're going to try making an assumption that an existing /W# means
# we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
endif()
@ -37,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_})
# create the lib
add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
add_library(UnitTest++::UnitTest++ ALIAS UnitTest++)
if(${UTPP_USE_PLUS_SIGN})
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
@ -47,18 +76,25 @@ endif()
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
source_group( "" FILES ${TEST_SRCS})
add_executable(TestUnitTest++ ${TEST_SRCS})
include_directories(.)
if(${UTPP_USE_PLUS_SIGN})
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
endif()
target_link_libraries(TestUnitTest++ UnitTest++)
target_link_libraries(TestUnitTest++
PUBLIC
UnitTest++::UnitTest++
)
# run unit tests as post build step
add_custom_command(TARGET TestUnitTest++
POST_BUILD COMMAND TestUnitTest++
COMMENT "Running unit tests")
POST_BUILD COMMAND TestUnitTest++
COMMENT "Running unit tests")
if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
# add install targets
# need a custom install path?
@ -69,6 +105,41 @@ else()
set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
endif()
install(TARGETS UnitTest++ DESTINATION lib)
target_include_directories( UnitTest++
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
)
set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
set(targets_export_name_ "${PROJECT_NAME}Targets")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
cmake/UnitTest++ConfigVersion.cmake
VERSION ${UnitTest++_VERSION}
COMPATIBILITY SameMajorVersion
)
install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
install(FILES
cmake/UnitTest++Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
DESTINATION "${config_install_dir_}")
install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}")
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(includedir ${CMAKE_INSTALL_PREFIX}/include/UnitTest++)
configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY)
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig)
else()
set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig)
endif()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc"
DESTINATION "${pkgconfdir}")

View file

View file

@ -1,3 +1,9 @@
Preamble: If you are installing UnitTest++ from source, or from a
release prior to 1.6.1, you will need to have autotools installed and
run `autoreconf -i; autoconf` prior to following the standard
instructions below.
Installation Instructions
*************************

View file

@ -1,3 +1,6 @@
> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates.
[![Build Status](https://travis-ci.org/unittest-cpp/unittest-cpp.svg?branch=master)](https://travis-ci.org/unittest-cpp/unittest-cpp)
[![Build status](https://ci.appveyor.com/api/projects/status/ffs2k8dddts5cyok/branch/master?svg=true)](https://ci.appveyor.com/project/pjohnmeyer/unittest-cpp/branch/master)
@ -30,17 +33,17 @@ Via svn:
svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp
### Latest release (v1.6.0) ###
### Latest release (v2.0.0) ###
Via git:
git clone https://github.com/unittest-cpp/unittest-cpp
cd unittest-cpp
git checkout v1.6.0
git checkout v2.0.0
Via svn:
svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v1.6.0 unittest-cpp
svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v2.0.0 unittest-cpp
License
---------
@ -58,7 +61,7 @@ Contributors
* Charles Nicholson (charles.nicholson@gmail.com) @charlesnicholson
### Original Authors: ###
* Noel Llopis (llopis@convexhull.com)
* Noel Llopis (llopis@convexhull.com)
* Charles Nicholson (charles.nicholson@gmail.com)
### Contributors not included in github history ###
@ -77,6 +80,12 @@ Contributors
Historic release notes
----------------------
### Version 2.0.0 (2017-01-13) ###
- Change Check method supporting CHECK macro to accept argument by reference
- Introduce long macro forms (e.g. UNITTEST_CHECK); make short forms optional
- Improved Visual Studio 2015 support
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A2.0.0+)
### Version 1.6.0 (2016-02-29) ###
- Add REQUIRE macro to end tests early when selected checks fail
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A1.6.0+)
@ -114,7 +123,7 @@ Historic release notes
- Standard streams can be optionally compiled off by defining UNITTEST_USE_CUSTOM_STREAMS
in Config.h
- Added named test suites
- Added CHECK_ARRAY2D_CLOSE
- Added CHECK_ARRAY2D_CLOSE
- Posix library name is libUnitTest++.a now
- Floating point numbers are postfixed with 'f' in the failure reports

View file

@ -11,162 +11,175 @@
#include "CurrentTest.h"
#include "ReportAssertImpl.h"
#ifdef CHECK
#error UnitTest++ redefines CHECK
#endif
#ifdef CHECK_EQUAL
#error UnitTest++ redefines CHECK_EQUAL
#endif
#ifdef CHECK_CLOSE
#error UnitTest++ redefines CHECK_CLOSE
#endif
#ifdef CHECK_ARRAY_EQUAL
#error UnitTest++ redefines CHECK_ARRAY_EQUAL
#endif
#ifdef CHECK_ARRAY_CLOSE
#error UnitTest++ redefines CHECK_ARRAY_CLOSE
#endif
#ifdef CHECK_ARRAY2D_CLOSE
#error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
#endif
#define CHECK(value) \
#define UNITTEST_CHECK(value) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
if (!UnitTest::Check(value)) \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK(" #value ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK(" #value ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK(" #value ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_EQUAL(expected, actual) \
#define UNITTEST_CHECK_EQUAL(expected, actual) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_CLOSE(expected, actual, tolerance) \
#define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
#define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
#define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
#define UNITTEST_CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
}) \
UT_RETHROW (UnitTest::RequiredCheckException) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream message; \
message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
message.GetText()); \
UnitTest_message.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
}) \
UNITTEST_MULTILINE_MACRO_END
#ifndef UNITTEST_DISABLE_SHORT_MACROS
#ifdef CHECK
#error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead
#else
#define CHECK UNITTEST_CHECK
#endif
#ifdef CHECK_EQUAL
#error CHECK_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL instead
#else
#define CHECK_EQUAL UNITTEST_CHECK_EQUAL
#endif
#ifdef CHECK_CLOSE
#error CHECK_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_CLOSE instead
#else
#define CHECK_CLOSE UNITTEST_CHECK_CLOSE
#endif
#ifdef CHECK_ARRAY_EQUAL
#error CHECK_ARRAY_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_EQUAL instead
#else
#define CHECK_ARRAY_EQUAL UNITTEST_CHECK_ARRAY_EQUAL
#endif
#ifdef CHECK_ARRAY_CLOSE
#error CHECK_ARRAY_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_CLOSE instead
#else
#define CHECK_ARRAY_CLOSE UNITTEST_CHECK_ARRAY_CLOSE
#endif
#ifdef CHECK_ARRAY2D_CLOSE
#error CHECK_ARRAY2D_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY2D_CLOSE instead
#else
#define CHECK_ARRAY2D_CLOSE UNITTEST_CHECK_ARRAY2D_CLOSE
#endif
#endif
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
#ifndef UNITTEST_NO_EXCEPTIONS
#define CHECK_THROW(expression, ExpectedExceptionType) \
#define UNITTEST_CHECK_THROW(expression, ExpectedExceptionType) \
UNITTEST_MULTILINE_MACRO_BEGIN \
bool caught_ = false; \
try { expression; } \
@ -177,7 +190,7 @@
UNITTEST_MULTILINE_MACRO_END
#define CHECK_ASSERT(expression) \
#define UNITTEST_CHECK_ASSERT(expression) \
UNITTEST_MULTILINE_MACRO_BEGIN \
UnitTest::Detail::ExpectAssert(true); \
CHECK_THROW(expression, UnitTest::AssertException); \
@ -185,4 +198,19 @@
UNITTEST_MULTILINE_MACRO_END
#endif
#ifndef UNITTEST_DISABLE_SHORT_MACROS
#ifdef CHECK_THROW
#error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead
#else
#define CHECK_THROW UNITTEST_CHECK_THROW
#endif
#ifdef CHECK_ASSERT
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
#else
#define CHECK_ASSERT UNITTEST_CHECK_ASSERT
#endif
#endif
#endif

View file

@ -9,7 +9,7 @@ namespace UnitTest {
template< typename Value >
bool Check(Value const value)
bool Check(Value const& value)
{
return !!value; // doing double negative to avoid silly VS warnings
}
@ -57,10 +57,10 @@ namespace UnitTest {
template< typename Expected, typename Actual >
void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual,
int const count, TestDetails const& details)
size_t const count, TestDetails const& details)
{
bool equal = true;
for (int i = 0; i < count; ++i)
for (size_t i = 0; i < count; ++i)
equal &= (expected[i] == actual[i]);
if (!equal)
@ -69,12 +69,12 @@ namespace UnitTest {
stream << "Expected [ ";
for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex)
for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex)
stream << expected[expectedIndex] << " ";
stream << "] but was [ ";
for (int actualIndex = 0; actualIndex < count; ++actualIndex)
for (size_t actualIndex = 0; actualIndex < count; ++actualIndex)
stream << actual[actualIndex] << " ";
stream << "]";
@ -84,17 +84,17 @@ namespace UnitTest {
}
template< typename Expected, typename Actual, typename Tolerance >
bool ArrayAreClose(Expected const& expected, Actual const& actual, int const count, Tolerance const& tolerance)
bool ArrayAreClose(Expected const& expected, Actual const& actual, size_t const count, Tolerance const& tolerance)
{
bool equal = true;
for (int i = 0; i < count; ++i)
for (size_t i = 0; i < count; ++i)
equal &= AreClose(expected[i], actual[i], tolerance);
return equal;
}
template< typename Expected, typename Actual, typename Tolerance >
void CheckArrayClose(TestResults& results, Expected const& expected, Actual const& actual,
int const count, Tolerance const& tolerance, TestDetails const& details)
size_t const count, Tolerance const& tolerance, TestDetails const& details)
{
bool equal = ArrayAreClose(expected, actual, count, tolerance);
@ -103,11 +103,11 @@ namespace UnitTest {
UnitTest::MemoryOutStream stream;
stream << "Expected [ ";
for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex)
for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex)
stream << expected[expectedIndex] << " ";
stream << "] +/- " << tolerance << " but was [ ";
for (int actualIndex = 0; actualIndex < count; ++actualIndex)
for (size_t actualIndex = 0; actualIndex < count; ++actualIndex)
stream << actual[actualIndex] << " ";
stream << "]";
@ -117,10 +117,10 @@ namespace UnitTest {
template< typename Expected, typename Actual, typename Tolerance >
void CheckArray2DClose(TestResults& results, Expected const& expected, Actual const& actual,
int const rows, int const columns, Tolerance const& tolerance, TestDetails const& details)
size_t const rows, size_t const columns, Tolerance const& tolerance, TestDetails const& details)
{
bool equal = true;
for (int i = 0; i < rows; ++i)
for (size_t i = 0; i < rows; ++i)
equal &= ArrayAreClose(expected[i], actual[i], columns, tolerance);
if (!equal)
@ -129,20 +129,20 @@ namespace UnitTest {
stream << "Expected [ ";
for (int expectedRow = 0; expectedRow < rows; ++expectedRow)
for (size_t expectedRow = 0; expectedRow < rows; ++expectedRow)
{
stream << "[ ";
for (int expectedColumn = 0; expectedColumn < columns; ++expectedColumn)
for (size_t expectedColumn = 0; expectedColumn < columns; ++expectedColumn)
stream << expected[expectedRow][expectedColumn] << " ";
stream << "] ";
}
stream << "] +/- " << tolerance << " but was [ ";
for (int actualRow = 0; actualRow < rows; ++actualRow)
for (size_t actualRow = 0; actualRow < rows; ++actualRow)
{
stream << "[ ";
for (int actualColumn = 0; actualColumn < columns; ++actualColumn)
for (size_t actualColumn = 0; actualColumn < columns; ++actualColumn)
stream << actual[actualRow][actualColumn] << " ";
stream << "] ";
}

View file

@ -16,12 +16,13 @@
#ifdef _USRDLL
#define UNITTEST_WIN32_DLL
#endif
#define UNITTEST_WIN32
#endif
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) \
|| defined (__HAIKU__) || defined(_AIX)
#define UNITTEST_POSIX
#endif
@ -71,4 +72,13 @@
#define UNIITEST_NS_QUAL_STD(x) ::std::x
#endif
// By default, UnitTest++ will attempt to define "short" macro names like CHECK and CHECK_EQUAL
// for "public" interface macros etc. Defining UNITTEST_DISABLE_SHORT_MACROS in your project
// will disable this behavior, leaving only the longer macros "namespaced" with the UNITTEST_
// prefix.
//
// "Internal" utility macros will only have the UNITTEST_IMPL_ prefix.
// #define UNITTEST_DISABLE_SHORT_MACROS
#endif

View file

@ -4,17 +4,17 @@
#include "Config.h"
#ifndef UNITTEST_NO_EXCEPTIONS
#define UT_TRY(x) try x
#define UT_THROW(x) throw x
#define UT_RETHROW(ExceptionType) catch(ExceptionType&) { throw; }
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody
#define UT_CATCH_ALL(CatchBody) catch(...) CatchBody
#define UNITTEST_IMPL_TRY(x) try x
#define UNITTEST_IMPL_THROW(x) throw x
#define UNITTEST_IMPL_RETHROW(ExceptionType) catch(ExceptionType&) { throw; }
#define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody
#define UNITTEST_IMPL_CATCH_ALL(CatchBody) catch(...) CatchBody
#else
#define UT_TRY(x) x
#define UT_THROW(x)
#define UT_RETHROW(ExceptionType)
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody)
#define UT_CATCH_ALL(CatchBody)
#define UNITTEST_IMPL_TRY(x) x
#define UNITTEST_IMPL_THROW(x)
#define UNITTEST_IMPL_RETHROW(ExceptionType)
#define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody)
#define UNITTEST_IMPL_CATCH_ALL(CatchBody)
#endif
#endif

View file

@ -31,23 +31,23 @@ namespace UnitTest {
{
#endif
#ifndef UNITTEST_POSIX
UT_TRY({ testObject.RunImpl(); })
UNITTEST_IMPL_TRY({ testObject.RunImpl(); })
#else
UT_TRY
UNITTEST_IMPL_TRY
({
UNITTEST_THROW_SIGNALS_POSIX_ONLY
testObject.RunImpl();
})
#endif
UT_CATCH(RequiredCheckException, e, { (void)e; })
UT_CATCH(AssertException, e, { (void)e; })
UT_CATCH(std::exception, e,
UNITTEST_IMPL_CATCH(RequiredCheckException, e, { (void)e; })
UNITTEST_IMPL_CATCH(AssertException, e, { (void)e; })
UNITTEST_IMPL_CATCH(std::exception, e,
{
MemoryOutStream stream;
stream << "Unhandled exception: " << e.what();
CurrentTest::Results()->OnTestFailure(details, stream.GetText());
})
UT_CATCH_ALL
UNITTEST_IMPL_CATCH_ALL
({
CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed");
})

View file

@ -1,12 +1,13 @@
lib_LTLIBRARIES = UnitTest++/libUnitTest++.la
pkgincludedir = $(includedir)/UnitTest++/
pkgincludedir = $(includedir)
nobase_pkginclude_HEADERS = UnitTest++/AssertException.h UnitTest++/CheckMacros.h UnitTest++/Checks.h UnitTest++/CompositeTestReporter.h UnitTest++/Config.h UnitTest++/CurrentTest.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h UnitTest++/ExceptionMacros.h UnitTest++/ExecuteTest.h UnitTest++/HelperMacros.h UnitTest++/MemoryOutStream.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/RequireMacros.h UnitTest++/RequiredCheckException.h UnitTest++/RequiredCheckTestReporter.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestMacros.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/TestResults.h UnitTest++/TestRunner.h UnitTest++/TestSuite.h UnitTest++/ThrowingTestReporter.h UnitTest++/TimeConstraint.h UnitTest++/TimeHelpers.h UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/XmlTestReporter.h
UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Checks.cpp UnitTest++/CompositeTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/ReportAssert.cpp UnitTest++/RequiredCheckException.cpp UnitTest++/RequiredCheckTestReporter.cpp UnitTest++/Test.cpp UnitTest++/TestDetails.cpp UnitTest++/TestList.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/TestResults.cpp UnitTest++/TestRunner.cpp UnitTest++/ThrowingTestReporter.cpp UnitTest++/TimeConstraint.cpp UnitTest++/XmlTestReporter.cpp
if WINDOWS
if WINDOWS
nobase_pkginclude_HEADERS += UnitTest++/Win32/TimeHelpers.h
UnitTest___libUnitTest___la_SOURCES += UnitTest++/Win32/TimeHelpers.cpp
else
else
nobase_pkginclude_HEADERS += UnitTest++/Posix/SignalTranslator.h UnitTest++/Posix/TimeHelpers.h
UnitTest___libUnitTest___la_SOURCES += UnitTest++/Posix/SignalTranslator.cpp UnitTest++/Posix/TimeHelpers.cpp
endif

View file

@ -28,12 +28,12 @@ namespace UnitTest {
sigaction( SIGFPE, &action, &m_old_SIGFPE_action );
sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action );
sigaction( SIGBUS, &action, &m_old_SIGBUS_action );
sigaction( SIGILL, &action, &m_old_SIGBUS_action );
sigaction( SIGILL, &action, &m_old_SIGILL_action );
}
SignalTranslator::~SignalTranslator()
{
sigaction( SIGILL, &m_old_SIGBUS_action, 0 );
sigaction( SIGILL, &m_old_SIGILL_action, 0 );
sigaction( SIGBUS, &m_old_SIGBUS_action, 0 );
sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 );
sigaction( SIGFPE, &m_old_SIGFPE_action, 0 );

View file

@ -22,8 +22,7 @@ namespace UnitTest {
struct sigaction m_old_SIGTRAP_action;
struct sigaction m_old_SIGSEGV_action;
struct sigaction m_old_SIGBUS_action;
struct sigaction m_old_SIGABRT_action;
struct sigaction m_old_SIGALRM_action;
struct sigaction m_old_SIGILL_action;
};
#if !defined (__GNUC__)

View file

@ -3,10 +3,14 @@
#include "RequiredCheckTestReporter.h"
#ifdef REQUIRE
#error UnitTest++ redefines REQUIRE
#define UNITTEST_REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
#ifndef UNITTEST_DISABLE_SHORT_MACROS
#ifdef REQUIRE
#error REQUIRE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_REQUIRE instead
#else
#define REQUIRE UNITTEST_REQUIRE
#endif
#endif
#define REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
#endif

View file

@ -19,6 +19,9 @@ namespace UnitTest {
bool Next();
private:
RequiredCheckTestReporter(RequiredCheckTestReporter const&);
RequiredCheckTestReporter& operator =(RequiredCheckTestReporter const&);
TestResults& m_results;
TestReporter* m_originalTestReporter;
ThrowingTestReporter m_throwingReporter;

View file

@ -15,19 +15,7 @@
#include "Posix/SignalTranslator.h"
#endif
#ifdef TEST
#error UnitTest++ redefines TEST
#endif
#ifdef TEST_EX
#error UnitTest++ redefines TEST_EX
#endif
#ifdef TEST_FIXTURE_EX
#error UnitTest++ redefines TEST_FIXTURE_EX
#endif
#define SUITE(Name) \
#define UNITTEST_SUITE(Name) \
namespace Suite ## Name { \
namespace UnitTestSuite { \
inline char const* GetSuiteName () { \
@ -37,34 +25,36 @@
} \
namespace Suite ## Name
#define TEST_EX(Name, List) \
#define UNITTEST_IMPL_TEST(Name, List) \
class Test ## Name : public UnitTest::Test \
{ \
public: \
Test ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \
private: \
virtual void RunImpl() const; \
} test ## Name ## Instance; \
} static test ## Name ## Instance; \
\
UnitTest::ListAdder adder ## Name (List, &test ## Name ## Instance); \
static UnitTest::ListAdder adder ## Name (List, &test ## Name ## Instance); \
\
void Test ## Name::RunImpl() const
#define TEST(Name) TEST_EX(Name, UnitTest::Test::GetTestList())
#define UNITTEST_TEST(Name) UNITTEST_IMPL_TEST(Name, UnitTest::Test::GetTestList())
#define TEST_FIXTURE_EX(Fixture, Name, List) \
#define UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, List) \
class Fixture ## Name ## Helper : public Fixture \
{ \
public: \
explicit Fixture ## Name ## Helper(UnitTest::TestDetails const& details) : m_details(details) {} \
void RunImpl(); \
UnitTest::TestDetails const& m_details; \
virtual ~Fixture ## Name ## Helper(); \
private: \
Fixture ## Name ## Helper(Fixture ## Name ## Helper const&); \
Fixture ## Name ## Helper& operator =(Fixture ## Name ## Helper const&); \
}; \
Fixture ## Name ## Helper::~Fixture ## Name ## Helper(){} \
\
class Test ## Fixture ## Name : public UnitTest::Test \
{ \
@ -72,30 +62,30 @@
Test ## Fixture ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \
private: \
virtual void RunImpl() const; \
} test ## Fixture ## Name ## Instance; \
} static test ## Fixture ## Name ## Instance; \
\
UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \
static UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \
\
void Test ## Fixture ## Name::RunImpl() const \
{ \
volatile bool ctorOk = false; \
UT_TRY \
UNITTEST_IMPL_TRY \
({ \
Fixture ## Name ## Helper fixtureHelper(m_details); \
ctorOk = true; \
UnitTest::ExecuteTest(fixtureHelper, m_details, false); \
}) \
UT_CATCH (UnitTest::AssertException, e, \
UNITTEST_IMPL_CATCH (UnitTest::AssertException, e, \
{ \
(void)e; \
}) \
UT_CATCH (std::exception, e, \
UNITTEST_IMPL_CATCH (std::exception, e, \
{ \
UnitTest::MemoryOutStream stream; \
stream << "Unhandled exception: " << e.what(); \
UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); \
}) \
UT_CATCH_ALL \
UNITTEST_IMPL_CATCH_ALL \
({ \
if (ctorOk) \
{ \
@ -111,7 +101,26 @@
} \
void Fixture ## Name ## Helper::RunImpl()
#define TEST_FIXTURE(Fixture,Name) TEST_FIXTURE_EX(Fixture, Name, UnitTest::Test::GetTestList())
#define UNITTEST_TEST_FIXTURE(Fixture,Name) UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, UnitTest::Test::GetTestList())
#ifndef UNITTEST_DISABLE_SHORT_MACROS
#ifdef SUITE
#error SUITE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_SUITE instead
#else
#define SUITE UNITTEST_SUITE
#endif
#ifdef TEST
#error TEST already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST instead
#else
#define TEST UNITTEST_TEST
#endif
#ifdef TEST_FIXTURE
#error TEST_FIXTURE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST_FIXTURE instead
#else
#define TEST_FIXTURE UNITTEST_TEST_FIXTURE
#endif
#endif
#endif

View file

@ -1,4 +1,4 @@
version: 1.6.0.{build}
version: 2.1.0.{build}
os:
- Windows Server 2012 R2

9
autogen.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
test -e ./.autotools_aux || mkdir .autotools_aux
libtoolize -cq
aclocal -I m4 --install # Generate aclocal
autoconf # Generate configure script
autoheader # Generate config.h
automake --add-missing --copy # Generate Makefile.in and other scripts

View file

@ -0,0 +1,2 @@
include("${CMAKE_CURRENT_LIST_DIR}/UnitTest++Targets.cmake")
get_filename_component(UTPP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include/" ABSOLUTE)

View file

@ -2,18 +2,28 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([UnitTest++], [1.6.0], [pjohnmeyer@gmail.com])
AC_INIT([UnitTest++],
m4_esyscmd_s([git describe --tags | cut -c2-]),
[pjohnmeyer@gmail.com],
[unittest-cpp])
AC_CONFIG_SRCDIR([UnitTest++/TestDetails.cpp])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([UnitTest++.pc])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_SILENT_RULES([yes])
AC_CANONICAL_HOST
dnl Detect Windows, as it doesn't implement UNIX signals and requires special code
AM_CONDITIONAL([WINDOWS],
[test "${host#*mingw}" != "${host}" -o "${host#*msvc}" != "${host}"])
[test "${host//mingw/}" != "${host}" -o "${host//msvc/}" != "${host}"])
LT_INIT()
AC_SUBST([LIBUNITTEST_SO_VERSION], [1:6:0])
AC_SUBST([LIBUNITTEST_SO_VERSION], [2:1:0])
# Checks for programs.
AC_PROG_CXX

2
docs

@ -1 +1 @@
Subproject commit 14495a3a81568e9ce187231b629e4eb7bc7e0350
Subproject commit a6963b798400df760e148a6e15e9c13db965a3ec

View file

@ -1,4 +1,5 @@
check_PROGRAMS = UnitTest++/TestUnitTest++
UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacrosWithExceptionsOff.cpp tests/TestRequireMacrosWithExceptionsOn.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp
UnitTest___TestUnitTest___SOURCES = tests/Main.cpp tests/TestAssertHandler.cpp tests/TestCheckMacros.cpp tests/TestChecks.cpp tests/TestCompositeTestReporter.cpp tests/TestCurrentTest.cpp tests/TestDeferredTestReporter.cpp tests/TestExceptions.cpp tests/TestMemoryOutStream.cpp tests/TestRequireMacrosWithExceptionsOff.cpp tests/TestRequireMacrosWithExceptionsOn.cpp tests/TestTest.cpp tests/TestTestList.cpp tests/TestTestMacros.cpp tests/TestTestResults.cpp tests/TestTestRunner.cpp tests/TestTestSuite.cpp tests/TestTimeConstraint.cpp tests/TestTimeConstraintMacro.cpp tests/TestUnitTestPP.cpp tests/TestXmlTestReporter.cpp tests/RecordingReporter.h tests/ScopedCurrentTest.h
UnitTest___TestUnitTest___LDADD = UnitTest++/libUnitTest++.la
TESTS = UnitTest++/TestUnitTest++

View file

@ -315,4 +315,32 @@ namespace {
CHECK_EQUAL(1234, reporter.lastFailedLine);
}
class TruthyUnlessCopied
{
public:
TruthyUnlessCopied()
: truthy_(true)
{
}
TruthyUnlessCopied(const TruthyUnlessCopied&)
: truthy_(false)
{
}
operator bool() const
{
return truthy_;
}
private:
bool truthy_;
};
TEST(CheckProperlyDealsWithOperatorBoolOverrides)
{
TruthyUnlessCopied objectThatShouldBeTruthy;
CHECK(objectThatShouldBeTruthy);
}
}

View file

@ -253,7 +253,7 @@ namespace {
class ThrowingObject
{
public:
float operator[](int) const
float operator[](size_t) const
{
throw "Test throw";
}
@ -262,7 +262,7 @@ namespace {
class StdThrowingObject
{
public:
float operator[](int) const
float operator[](size_t) const
{
throw std::runtime_error("Test throw");
}
@ -451,7 +451,7 @@ namespace {
class ThrowingObject2D
{
public:
float* operator[](int) const
float* operator[](size_t) const
{
throw "Test throw";
}
@ -460,7 +460,7 @@ namespace {
class StdThrowingObject2D
{
public:
float* operator[](int) const
float* operator[](size_t) const
{
throw std::runtime_error("Test throw");
}

45
tests/TestLongMacros.cpp Normal file
View file

@ -0,0 +1,45 @@
#define UNITTEST_DISABLE_SHORT_MACROS
#include "UnitTest++/UnitTestPP.h"
// This file is not intended to test every little thing, just a few basics to hopefully ensure
// the macros are working and the short macros are not defined.
UNITTEST_SUITE(LongMacros)
{
UNITTEST_TEST(LongCheckMacroWorks)
{
UNITTEST_CHECK(true);
}
class Fixture
{
public:
Fixture() : sanity_(true) {}
protected:
bool sanity_;
};
UNITTEST_TEST_FIXTURE(Fixture, LongFixtureMacroWorks)
{
UNITTEST_REQUIRE UNITTEST_CHECK(sanity_);
}
UNITTEST_TEST(ShortMacrosAreNotDefined)
{
#if defined(CHECK) || \
defined(CHECK_EQUAL) || \
defined(CHECK_CLOSE) || \
defined(CHECK_ARRAY_EQUAL) || \
defined(CHECK_ARRAY_CLOSE) || \
defined(CHECK_ARRAY2D_CLOSE) || \
defined(CHECK_THROW) || \
defined(CHECK_ASSERT) || \
defined(SUITE) || \
defined(TEST) || \
defined(TEST_FIXTURE) || \
defined(REQUIRE)
UNITTEST_CHECK(false);
#endif
}
}

View file

@ -11,7 +11,7 @@ using namespace std;
namespace {
const char* const maxSignedIntegralStr(size_t nBytes)
const char* maxSignedIntegralStr(size_t nBytes)
{
switch(nBytes)
{
@ -28,7 +28,7 @@ namespace {
}
}
const char* const minSignedIntegralStr(size_t nBytes)
const char* minSignedIntegralStr(size_t nBytes)
{
switch(nBytes)
{
@ -45,7 +45,7 @@ namespace {
}
}
const char* const maxUnsignedIntegralStr(size_t nBytes)
const char* maxUnsignedIntegralStr(size_t nBytes)
{
switch(nBytes)
{

View file

@ -72,7 +72,7 @@ namespace {
CHECK_EQUAL(1, results.GetFailureCount());
}
#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32)
#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) && !defined(__clang__)
// Skip this test in debug because some debuggers don't like it.
#if defined(NDEBUG)
TEST(CrashingTestsAreReportedAsFailures)

View file

@ -46,7 +46,7 @@ using namespace std;
namespace {
TestList list1;
TEST_EX(DummyTest, list1)
UNITTEST_IMPL_TEST(DummyTest, list1)
{}
TEST (TestsAreAddedToTheListThroughMacro)
@ -69,7 +69,7 @@ namespace {
};
TestList list2;
TEST_FIXTURE_EX(ThrowingThingie, DummyTestName, list2)
UNITTEST_IMPL_TEST_FIXTURE(ThrowingThingie, DummyTestName, list2)
{}
TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture)
@ -113,7 +113,7 @@ namespace {
}
TestList macroTestList1;
TEST_EX(MacroTestHelper1, macroTestList1)
UNITTEST_IMPL_TEST(MacroTestHelper1, macroTestList1)
{}
TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)
@ -124,7 +124,7 @@ namespace {
}
TestList macroTestList2;
TEST_FIXTURE_EX(DummyFixture, MacroTestHelper2, macroTestList2)
UNITTEST_IMPL_TEST_FIXTURE(DummyFixture, MacroTestHelper2, macroTestList2)
{}
TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
@ -144,7 +144,7 @@ namespace {
};
TestList throwingFixtureTestList1;
TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
UNITTEST_IMPL_TEST_FIXTURE(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
{}
TEST(FixturesWithThrowingCtorsAreFailures)
@ -170,7 +170,7 @@ namespace {
};
TestList throwingFixtureTestList2;
TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
UNITTEST_IMPL_TEST_FIXTURE(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
{}
TEST(FixturesWithThrowingDtorsAreFailures)
@ -200,7 +200,7 @@ namespace {
};
TestList ctorAssertFixtureTestList;
TEST_FIXTURE_EX(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList)
UNITTEST_IMPL_TEST_FIXTURE(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList)
{}
TEST(CorrectlyReportsFixturesWithCtorsThatAssert)