diff options
Diffstat (limited to 'src/boost/libs/assert')
26 files changed, 1628 insertions, 0 deletions
diff --git a/src/boost/libs/assert/CMakeLists.txt b/src/boost/libs/assert/CMakeLists.txt new file mode 100644 index 000000000..0066aeb2f --- /dev/null +++ b/src/boost/libs/assert/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright 2018, 2019 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +# We support CMake 3.5, but prefer 3.16 policies and behavior +cmake_minimum_required(VERSION 3.5...3.16) + +project(boost_assert VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) + +add_library(boost_assert INTERFACE) +add_library(Boost::assert ALIAS boost_assert) + +target_include_directories(boost_assert INTERFACE include) + +target_link_libraries(boost_assert + INTERFACE + Boost::config +) + +# boost_install requires PROJECT_VERSION +# Without the superproject, we don't have any, so skip installation + +if(BOOST_SUPERPROJECT_VERSION) + + include(BoostInstall) + boost_install(TARGETS boost_assert HEADER_DIRECTORY include/) + +endif() + +# BUILD_TESTING is the standard CTest variable that enables testing + +if(BUILD_TESTING) + + add_subdirectory(test) + +endif() diff --git a/src/boost/libs/assert/README.md b/src/boost/libs/assert/README.md new file mode 100644 index 000000000..645b7bb49 --- /dev/null +++ b/src/boost/libs/assert/README.md @@ -0,0 +1,14 @@ +# Boost.Assert + +The Boost.Assert library, part of the collection of [Boost C++ Libraries](http://github.com/boostorg), +provides several configurable diagnostic macros similar in behavior and purpose to the standard macro +`assert` from `<cassert>`. + +## Documentation + +See the documentation of [BOOST_ASSERT](doc/assert.adoc) and +[BOOST_CURRENT_FUNCTION](doc/current_function.adoc) for more information. + +## License + +Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/assert/index.html b/src/boost/libs/assert/index.html new file mode 100644 index 000000000..a3c843e08 --- /dev/null +++ b/src/boost/libs/assert/index.html @@ -0,0 +1,15 @@ +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/html/assert.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="doc/html/assert.html">doc/html/assert.html</a>. +</body> +</html> +<!-- + © Copyright Beman Dawes, 2001 + Distributed under the Boost Software License, Version 1.0. + See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt +--> diff --git a/src/boost/libs/assert/meta/libraries.json b/src/boost/libs/assert/meta/libraries.json new file mode 100644 index 000000000..833779619 --- /dev/null +++ b/src/boost/libs/assert/meta/libraries.json @@ -0,0 +1,14 @@ +{ + "key": "assert", + "name": "Assert", + "authors": [ + "Peter Dimov" + ], + "maintainers": [ + "Peter Dimov <pdimov -at- pdimov.com>" + ], + "description": "Customizable assert macros.", + "category": [ + "Correctness" + ] +} diff --git a/src/boost/libs/assert/test/CMakeLists.txt b/src/boost/libs/assert/test/CMakeLists.txt new file mode 100644 index 000000000..d6be2c921 --- /dev/null +++ b/src/boost/libs/assert/test/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2018, 2019 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) + +if(HAVE_BOOST_TEST) + +boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::assert Boost::core) + +if(BOOST_SUPERPROJECT_VERSION) + boost_test(SOURCES check_cmake_version.cpp ARGUMENTS ${PROJECT_VERSION} LINK_LIBRARIES Boost::core Boost::config) +endif() + +endif() diff --git a/src/boost/libs/assert/test/Jamfile.v2 b/src/boost/libs/assert/test/Jamfile.v2 new file mode 100644 index 000000000..0e935b637 --- /dev/null +++ b/src/boost/libs/assert/test/Jamfile.v2 @@ -0,0 +1,40 @@ +# Boost.Assert Library test Jamfile +# +# Copyright (c) 2014, 2017, 2019 Peter Dimov +# +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt + +import testing ; + +project : requirements + <warnings>extra + <toolset>msvc:<warnings-as-errors>on + <toolset>clang:<warnings-as-errors>on + <toolset>gcc:<warnings-as-errors>on + <toolset>gcc:<cxxflags>-Wshadow + <toolset>gcc-4.4.7:<cxxflags>-Wno-sign-compare ; + +run assert_test.cpp ; +run current_function_test.cpp + : : : <test-info>always_show_run_output ; +run verify_test.cpp ; +run assert_is_void_test.cpp ; + +# expansion tests are in exp/ so that there is a backslash in the path on Windows +run exp/assert_exp_test.cpp ; +run exp/assert_msg_exp_test.cpp ; +run exp/verify_exp_test.cpp ; +run exp/verify_msg_exp_test.cpp ; +run assert_test2.cpp ; +run assert_msg_test2.cpp ; + +# quick test (for CI) +run quick.cpp ; + +run current_function_test2.cpp ; + +run source_location_test.cpp ; +run source_location_test2.cpp ; +run source_location_test3.cpp ; diff --git a/src/boost/libs/assert/test/assert_is_void_test.cpp b/src/boost/libs/assert/test/assert_is_void_test.cpp new file mode 100644 index 000000000..5e64a6857 --- /dev/null +++ b/src/boost/libs/assert/test/assert_is_void_test.cpp @@ -0,0 +1,108 @@ +// +// assert_is_void_test.cpp - tests BOOST_ASSERT_IS_VOID +// +// Copyright (c) 2015 Ion Gaztanaga +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/config.hpp> + +// default case, !NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#undef NDEBUG +#include <boost/assert.hpp> + +#ifdef BOOST_ASSERT_IS_VOID +#error "BOOST_ASSERT should NOT be void if NDEBUG is not defined" +#endif + +// default case, NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#define NDEBUG +#include <boost/assert.hpp> + +#ifndef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should be void in NDEBUG" +#endif + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include <boost/assert.hpp> + +#ifndef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should be void with BOOST_DISABLE_ASSERTS" +#endif + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +#ifndef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should be void with BOOST_DISABLE_ASSERTS and NDEBUG" +#endif + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +#ifdef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_HANDLER" +#endif + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define NDEBUG +#include <boost/assert.hpp> + +#ifdef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_HANDLER" +#endif + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +#ifdef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_DEBUG_HANDLER and !NDEBUG" +#endif + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +#ifndef BOOST_ASSERT_IS_VOID +#error "Error: BOOST_ASSERT should be void with BOOST_ENABLE_ASSERT_DEBUG_HANDLER and NDEBUG" +#endif + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + return 0; +} diff --git a/src/boost/libs/assert/test/assert_msg_test2.cpp b/src/boost/libs/assert/test/assert_msg_test2.cpp new file mode 100644 index 000000000..f079e1559 --- /dev/null +++ b/src/boost/libs/assert/test/assert_msg_test2.cpp @@ -0,0 +1,118 @@ +// +// assert_msg_test2.cpp - a test for BOOST_ASSERT_MSG and NDEBUG +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/detail/lightweight_test.hpp> +#include <stdio.h> + +// default case, !NDEBUG +// BOOST_ASSERT_MSG(x) -> assert(x) + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_default() +{ + int x = 1; + + BOOST_ASSERT_MSG( 1, "msg" ); + BOOST_ASSERT_MSG( x, "msg" ); + BOOST_ASSERT_MSG( x == 1, "msg" ); +} + +// default case, NDEBUG +// BOOST_ASSERT_MSG(x) -> assert(x) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_default_ndebug() +{ + int x = 1; + + BOOST_ASSERT_MSG( 1, "msg" ); + BOOST_ASSERT_MSG( x, "msg" ); + BOOST_ASSERT_MSG( x == 1, "msg" ); + + BOOST_ASSERT_MSG( 0, "msg" ); + BOOST_ASSERT_MSG( !x, "msg" ); + BOOST_ASSERT_MSG( x == 0, "msg" ); + + (void)x; +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +int handler_invoked = 0; + +void boost::assertion_failed_msg( char const * expr, char const * msg, char const * function, char const * file, long line ) +{ + printf( "Expression: %s\nMessage: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, msg, function, file, line ); + ++handler_invoked; +} + +void test_debug_handler() +{ + handler_invoked = 0; + + int x = 1; + + BOOST_ASSERT_MSG( 1, "msg" ); + BOOST_ASSERT_MSG( x, "msg" ); + BOOST_ASSERT_MSG( x == 1, "msg" ); + + BOOST_ASSERT_MSG( 0, "msg" ); + BOOST_ASSERT_MSG( !x, "msg" ); + BOOST_ASSERT_MSG( x == 0, "msg" ); + + BOOST_TEST( handler_invoked == 3 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT_MSG(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + handler_invoked = 0; + + int x = 1; + + BOOST_ASSERT_MSG( 1, "msg" ); + BOOST_ASSERT_MSG( x, "msg" ); + BOOST_ASSERT_MSG( x == 1, "msg" ); + + BOOST_ASSERT_MSG( 0, "msg" ); + BOOST_ASSERT_MSG( !x, "msg" ); + BOOST_ASSERT_MSG( x == 0, "msg" ); + + BOOST_TEST( handler_invoked == 0 ); + + (void)x; +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/assert_test.cpp b/src/boost/libs/assert/test/assert_test.cpp new file mode 100644 index 000000000..bc5c3db4b --- /dev/null +++ b/src/boost/libs/assert/test/assert_test.cpp @@ -0,0 +1,157 @@ +// +// assert_test.cpp - a test for boost/assert.hpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (2) Beman Dawes 2011 +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#include <boost/core/lightweight_test.hpp> + +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Waddress" +#endif + +#include <boost/assert.hpp> + +void test_default() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); + + BOOST_ASSERT_MSG(1, "msg"); + BOOST_ASSERT_MSG(x, "msg"); + BOOST_ASSERT_MSG(x == 1, "msg"); + BOOST_ASSERT_MSG(&x, "msg"); +} + +#define BOOST_DISABLE_ASSERTS +#include <boost/assert.hpp> + +void test_disabled() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); + + BOOST_ASSERT_MSG(1, "msg"); + BOOST_ASSERT_MSG(x, "msg"); + BOOST_ASSERT_MSG(x == 1, "msg"); + BOOST_ASSERT_MSG(&x, "msg"); + + BOOST_ASSERT(0); + BOOST_ASSERT(!x); + BOOST_ASSERT(x == 0); + + BOOST_ASSERT_MSG(0, "msg"); + BOOST_ASSERT_MSG(!x, "msg"); + BOOST_ASSERT_MSG(x == 0, "msg"); + + void * p = 0; + + BOOST_ASSERT(p); + BOOST_ASSERT_MSG(p, "msg"); + + // suppress warnings + p = &x; + p = &p; +} + +#undef BOOST_DISABLE_ASSERTS + +#define BOOST_ENABLE_ASSERT_HANDLER +#include <boost/assert.hpp> +#include <boost/config.hpp> +#include <cstdio> + +int handler_invoked = 0; +int msg_handler_invoked = 0; + +void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); + ++handler_invoked; +} + +void boost::assertion_failed_msg(char const * expr, char const * msg, char const * function, + char const * file, long line) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s Message: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", + expr, msg, function, file, line); + ++msg_handler_invoked; +} + +struct X +{ + static void f() + { + BOOST_ASSERT(0); + BOOST_ASSERT_MSG(0, "msg f()"); + } +}; + +void test_handler() +{ + int x = 1; + + BOOST_ASSERT(1); + BOOST_ASSERT(x); + BOOST_ASSERT(x == 1); + BOOST_ASSERT(&x); + + BOOST_ASSERT_MSG(1, "msg2"); + BOOST_ASSERT_MSG(x, "msg3"); + BOOST_ASSERT_MSG(x == 1, "msg4"); + BOOST_ASSERT_MSG(&x, "msg5"); + + BOOST_ASSERT(0); + BOOST_ASSERT(!x); + BOOST_ASSERT(x == 0); + + BOOST_ASSERT_MSG(0,"msg 0"); + BOOST_ASSERT_MSG(!x, "msg !x"); + BOOST_ASSERT_MSG(x == 0, "msg x == 0"); + + void * p = 0; + + BOOST_ASSERT(p); + BOOST_ASSERT_MSG(p, "msg p"); + + X::f(); + + BOOST_ASSERT(handler_invoked == 5); + BOOST_TEST(handler_invoked == 5); + + BOOST_ASSERT_MSG(msg_handler_invoked == 5, "msg_handler_invoked count is wrong"); + BOOST_TEST(msg_handler_invoked == 5); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER +#undef BOOST_ENABLE_ASSERT_MSG_HANDLER + +int main() +{ + test_default(); + test_disabled(); + test_handler(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/assert_test2.cpp b/src/boost/libs/assert/test/assert_test2.cpp new file mode 100644 index 000000000..9879ecbc5 --- /dev/null +++ b/src/boost/libs/assert/test/assert_test2.cpp @@ -0,0 +1,118 @@ +// +// assert_test2.cpp - a test for BOOST_ASSERT and NDEBUG +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/detail/lightweight_test.hpp> +#include <stdio.h> + +// default case, !NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_default() +{ + int x = 1; + + BOOST_ASSERT( 1 ); + BOOST_ASSERT( x ); + BOOST_ASSERT( x == 1 ); +} + +// default case, NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_default_ndebug() +{ + int x = 1; + + BOOST_ASSERT( 1 ); + BOOST_ASSERT( x ); + BOOST_ASSERT( x == 1 ); + + BOOST_ASSERT( 0 ); + BOOST_ASSERT( !x ); + BOOST_ASSERT( x == 0 ); + + (void)x; +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +int handler_invoked = 0; + +void boost::assertion_failed( char const * expr, char const * function, char const * file, long line ) +{ + printf( "Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line ); + ++handler_invoked; +} + +void test_debug_handler() +{ + handler_invoked = 0; + + int x = 1; + + BOOST_ASSERT( 1 ); + BOOST_ASSERT( x ); + BOOST_ASSERT( x == 1 ); + + BOOST_ASSERT( 0 ); + BOOST_ASSERT( !x ); + BOOST_ASSERT( x == 0 ); + + BOOST_TEST( handler_invoked == 3 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + handler_invoked = 0; + + int x = 1; + + BOOST_ASSERT( 1 ); + BOOST_ASSERT( x ); + BOOST_ASSERT( x == 1 ); + + BOOST_ASSERT( 0 ); + BOOST_ASSERT( !x ); + BOOST_ASSERT( x == 0 ); + + BOOST_TEST( handler_invoked == 0 ); + + (void)x; +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/check_cmake_version.cpp b/src/boost/libs/assert/test/check_cmake_version.cpp new file mode 100644 index 000000000..2fd464836 --- /dev/null +++ b/src/boost/libs/assert/test/check_cmake_version.cpp @@ -0,0 +1,27 @@ +// Check whether the version in CMakeLists.txt is up to date +// +// Copyright 2018 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include <boost/core/lightweight_test.hpp> +#include <boost/version.hpp> +#include <cstdio> + +int main( int ac, char const* av[] ) +{ + BOOST_TEST_EQ( ac, 2 ); + + if( ac >= 2 ) + { + char version[ 64 ]; + std::sprintf( version, "%d.%d.%d", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100 ); + + BOOST_TEST_CSTR_EQ( av[1], version ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/cmake_install_test/CMakeLists.txt b/src/boost/libs/assert/test/cmake_install_test/CMakeLists.txt new file mode 100644 index 000000000..33510dffc --- /dev/null +++ b/src/boost/libs/assert/test/cmake_install_test/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2018 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5...3.16) + +project(cmake_install_test LANGUAGES CXX) + +find_package(boost_assert REQUIRED) + +add_executable(main main.cpp) +target_link_libraries(main Boost::assert) + +enable_testing() +add_test(NAME main COMMAND main) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) diff --git a/src/boost/libs/assert/test/cmake_install_test/main.cpp b/src/boost/libs/assert/test/cmake_install_test/main.cpp new file mode 100644 index 000000000..305a35441 --- /dev/null +++ b/src/boost/libs/assert/test/cmake_install_test/main.cpp @@ -0,0 +1,11 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +#include <boost/assert.hpp> + +int main() +{ + int x = 5; + BOOST_ASSERT( x > 4 ); +} diff --git a/src/boost/libs/assert/test/cmake_subdir_test/CMakeLists.txt b/src/boost/libs/assert/test/cmake_subdir_test/CMakeLists.txt new file mode 100644 index 000000000..80efc8571 --- /dev/null +++ b/src/boost/libs/assert/test/cmake_subdir_test/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright 2018 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5...3.16) + +project(cmake_subdir_test LANGUAGES CXX) + +add_subdirectory(../../../assert boostorg/assert) +add_subdirectory(../../../config boostorg/config) + +add_executable(main main.cpp) +target_link_libraries(main Boost::assert) + +enable_testing() +add_test(NAME main COMMAND main) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) diff --git a/src/boost/libs/assert/test/cmake_subdir_test/main.cpp b/src/boost/libs/assert/test/cmake_subdir_test/main.cpp new file mode 100644 index 000000000..305a35441 --- /dev/null +++ b/src/boost/libs/assert/test/cmake_subdir_test/main.cpp @@ -0,0 +1,11 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +#include <boost/assert.hpp> + +int main() +{ + int x = 5; + BOOST_ASSERT( x > 4 ); +} diff --git a/src/boost/libs/assert/test/current_function_test.cpp b/src/boost/libs/assert/test/current_function_test.cpp new file mode 100644 index 000000000..13439011f --- /dev/null +++ b/src/boost/libs/assert/test/current_function_test.cpp @@ -0,0 +1,40 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// current_function_test.cpp - a test for boost/current_function.hpp +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#include <boost/current_function.hpp> +#include <boost/config.hpp> +#include <cstdio> + +void message(char const * file, long line, char const * func, char const * msg) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("%s(%ld): %s in function '%s'\n", file, line, msg, func); +} + +#define MESSAGE(msg) message(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, msg) + +int main() +{ + MESSAGE("assertion failed"); + + return 0; +} diff --git a/src/boost/libs/assert/test/current_function_test2.cpp b/src/boost/libs/assert/test/current_function_test2.cpp new file mode 100644 index 000000000..e3c25237a --- /dev/null +++ b/src/boost/libs/assert/test/current_function_test2.cpp @@ -0,0 +1,25 @@ +// +// current_function_test2.cpp - a test for boost/current_function.hpp +// +// Copyright 2018 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/current_function.hpp> +#include <boost/core/lightweight_test.hpp> +#include <string> + +int f() +{ + BOOST_TEST_EQ( std::string( BOOST_CURRENT_FUNCTION ).substr( 0, 4 ), std::string( "int " ) ); + return 0; +} + +int main() +{ + f(); + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/exp/assert_exp_test.cpp b/src/boost/libs/assert/test/exp/assert_exp_test.cpp new file mode 100644 index 000000000..c56cdef5b --- /dev/null +++ b/src/boost/libs/assert/test/exp/assert_exp_test.cpp @@ -0,0 +1,164 @@ +// +// assert_exp_test.cpp - tests BOOST_ASSERT expansion +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/config.hpp> +#include <boost/current_function.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <string> + +// Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled +static std::string quote( std::string const & s ) +{ + std::string r; + r.reserve( s.size() ); + + for( char const * p = s.c_str(); *p; ++p ) + { + r += *p; + if( *p == '\\' ) r += *p; + } + + return r; +} + +// default case, !NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#undef NDEBUG +#include <boost/assert.hpp> +#undef assert + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT(x1)); + BOOST_TEST_EQ( v1, "assert(x1)" ); +} + +// default case, NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#define NDEBUG +#include <boost/assert.hpp> +#undef assert + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT(x2)); + BOOST_TEST_EQ( v2, "assert(x2)" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT(x3)); + BOOST_TEST_EQ( v3, "((void)0)" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT(x4)); + BOOST_TEST_EQ( v4, "((void)0)" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#undef BOOST_LIKELY +#undef BOOST_CURRENT_FUNCTION + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT(x5)); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed(\"x5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; + BOOST_TEST_EQ( v5, w5 ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT(x6)); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed(\"x6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; + BOOST_TEST_EQ( v6, w6 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT(x7)); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed(\"x7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; + BOOST_TEST_EQ( v7, w7 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT(x8)); + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; + BOOST_TEST_EQ( v8, "((void)0)" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/exp/assert_msg_exp_test.cpp b/src/boost/libs/assert/test/exp/assert_msg_exp_test.cpp new file mode 100644 index 000000000..faff6169f --- /dev/null +++ b/src/boost/libs/assert/test/exp/assert_msg_exp_test.cpp @@ -0,0 +1,164 @@ +// +// assert_msg_exp_test.cpp - tests BOOST_ASSERT_MSG expansion +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/config.hpp> +#include <boost/current_function.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <string> + +// Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled +static std::string quote( std::string const & s ) +{ + std::string r; + r.reserve( s.size() ); + + for( char const * p = s.c_str(); *p; ++p ) + { + r += *p; + if( *p == '\\' ) r += *p; + } + + return r; +} + +// default case, !NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) + +#undef NDEBUG +#include <boost/assert.hpp> +#undef assert + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x1, "m1")); + BOOST_TEST_EQ( v1, "assert((x1)&&(\"m1\"))" ); +} + +// default case, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) + +#define NDEBUG +#include <boost/assert.hpp> +#undef assert + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x2, "m2")); + BOOST_TEST_EQ( v2, "assert((x2)&&(\"m2\"))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x3, "m3")); + BOOST_TEST_EQ( v3, "((void)0)" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x4, "m4")); + BOOST_TEST_EQ( v4, "((void)0)" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#undef BOOST_LIKELY +#undef BOOST_CURRENT_FUNCTION + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x5, "m5")); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed_msg(\"x5\", \"m5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; + BOOST_TEST_EQ( v5, w5 ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x6, "m6")); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed_msg(\"x6\", \"m6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; + BOOST_TEST_EQ( v6, w6 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x7, "m7")); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed_msg(\"x7\", \"m7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; + BOOST_TEST_EQ( v7, w7 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x8, "m8")); + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; + BOOST_TEST_EQ( v8, "((void)0)" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/exp/verify_exp_test.cpp b/src/boost/libs/assert/test/exp/verify_exp_test.cpp new file mode 100644 index 000000000..844513b5c --- /dev/null +++ b/src/boost/libs/assert/test/exp/verify_exp_test.cpp @@ -0,0 +1,136 @@ +// +// verify_exp_test.cpp - tests BOOST_ASSERT expansion +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/config.hpp> +#include <boost/current_function.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <string> + +// default case, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY(x1)); + BOOST_TEST_EQ( v1, "BOOST_ASSERT(x1)" ); +} + +// default case, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY(x2)); + BOOST_TEST_EQ( v2, "((void)(x2))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define BOOST_DISABLE_ASSERTS +#undef NDEBUG +#include <boost/assert.hpp> + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY(x3)); + BOOST_TEST_EQ( v3, "((void)(x3))" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY(x4)); + BOOST_TEST_EQ( v4, "((void)(x4))" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY(x5)); + BOOST_TEST_EQ( v5, "BOOST_ASSERT(x5)" ); +} + +#define NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY(x6)); + BOOST_TEST_EQ( v6, "BOOST_ASSERT(x6)" ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY(x7)); + BOOST_TEST_EQ( v7, "BOOST_ASSERT(x7)" ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY(x8)); + BOOST_TEST_EQ( v8, "((void)(x8))" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/exp/verify_msg_exp_test.cpp b/src/boost/libs/assert/test/exp/verify_msg_exp_test.cpp new file mode 100644 index 000000000..02090fe00 --- /dev/null +++ b/src/boost/libs/assert/test/exp/verify_msg_exp_test.cpp @@ -0,0 +1,140 @@ +// +// verify_msg_exp_test.cpp - tests BOOST_VERIFY_MSG expansion +// +// Copyright (c) 2014 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/config.hpp> +#include <boost/current_function.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <string> + +// default case, !NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> BOOST_ASSERT_MSG(x,"m") + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT_MSG + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x1, m1)); + BOOST_TEST_EQ( v1, "BOOST_ASSERT_MSG(x1,m1)" ); +} + +// default case, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x2, m2)); + BOOST_TEST_EQ( v2, "((void)(x2))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include <boost/assert.hpp> + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x3, "m3")); + BOOST_TEST_EQ( v3, "((void)(x3))" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x4, "m4")); + BOOST_TEST_EQ( v4, "((void)(x4))" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_VERIFY_MSG(x,m) -> BOOST_ASSERT_MSG(x,m) + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT_MSG + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x5, m5)); + BOOST_TEST_EQ( v5, "BOOST_ASSERT_MSG(x5,m5)" ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) + +#define NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT_MSG + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x6, m6)); + BOOST_TEST_EQ( v6, "BOOST_ASSERT_MSG(x6,m6)" ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include <boost/assert.hpp> +#undef BOOST_ASSERT_MSG + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x7, m7)); + BOOST_TEST_EQ( v7, "BOOST_ASSERT_MSG(x7,m7)" ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include <boost/assert.hpp> + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x8, "m8")); + BOOST_TEST_EQ( v8, "((void)(x8))" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/quick.cpp b/src/boost/libs/assert/test/quick.cpp new file mode 100644 index 000000000..ec3dba6f3 --- /dev/null +++ b/src/boost/libs/assert/test/quick.cpp @@ -0,0 +1,18 @@ +// +// quick.cpp - a quick test for boost/assert.hpp +// +// Copyright 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include <boost/assert.hpp> + +int main() +{ + int x = 1; + BOOST_ASSERT( x == 1 ); +} diff --git a/src/boost/libs/assert/test/source_location_test.cpp b/src/boost/libs/assert/test/source_location_test.cpp new file mode 100644 index 000000000..f94e230fb --- /dev/null +++ b/src/boost/libs/assert/test/source_location_test.cpp @@ -0,0 +1,30 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include <boost/assert/source_location.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() +{ + { + boost::source_location loc; + + BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_EQ( loc.line(), 0 ); + BOOST_TEST_EQ( loc.column(), 0 ); + } + + { + boost::source_location loc = BOOST_CURRENT_LOCATION; + + + BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ ); + BOOST_TEST_CSTR_EQ( loc.function_name(), BOOST_CURRENT_FUNCTION ); + BOOST_TEST_EQ( loc.line(), 20 ); + BOOST_TEST_EQ( loc.column(), 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/source_location_test2.cpp b/src/boost/libs/assert/test/source_location_test2.cpp new file mode 100644 index 000000000..e21e3f6d6 --- /dev/null +++ b/src/boost/libs/assert/test/source_location_test2.cpp @@ -0,0 +1,32 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#define BOOST_DISABLE_CURRENT_LOCATION + +#include <boost/assert/source_location.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() +{ + { + boost::source_location loc; + + BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_EQ( loc.line(), 0 ); + BOOST_TEST_EQ( loc.column(), 0 ); + } + + { + boost::source_location loc = BOOST_CURRENT_LOCATION; + + + BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_EQ( loc.line(), 0 ); + BOOST_TEST_EQ( loc.column(), 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/source_location_test3.cpp b/src/boost/libs/assert/test/source_location_test3.cpp new file mode 100644 index 000000000..72a22894b --- /dev/null +++ b/src/boost/libs/assert/test/source_location_test3.cpp @@ -0,0 +1,30 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include <boost/assert/source_location.hpp> +#include <boost/core/lightweight_test.hpp> +#include <sstream> + +int main() +{ + { + boost::source_location loc; + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), std::string( "(unknown source location)" ) ); + } + + { + boost::source_location loc = BOOST_CURRENT_LOCATION; + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), std::string( __FILE__ ) + ":21: in function '" + BOOST_CURRENT_FUNCTION + "'" ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/assert/test/verify_test.cpp b/src/boost/libs/assert/test/verify_test.cpp new file mode 100644 index 000000000..ea46d53af --- /dev/null +++ b/src/boost/libs/assert/test/verify_test.cpp @@ -0,0 +1,130 @@ +// +// verify_test.cpp - a test for BOOST_VERIFY +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2007 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#include <boost/core/lightweight_test.hpp> + +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Waddress" +#endif + +#include <boost/assert.hpp> + +int f( int & x ) +{ + return ++x; +} + +void test_default() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); +} + +#define BOOST_DISABLE_ASSERTS +#include <boost/assert.hpp> + +void test_disabled() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); + + BOOST_VERIFY( 0 ); + BOOST_VERIFY( !x ); + BOOST_VERIFY( x == 0 ); + BOOST_VERIFY( !++x ); + BOOST_VERIFY( !f(x) ); + + BOOST_TEST( x == 5 ); + + void * p = 0; + BOOST_VERIFY( p ); +} + +#undef BOOST_DISABLE_ASSERTS + +#define BOOST_ENABLE_ASSERT_HANDLER +#include <boost/assert.hpp> +#include <boost/config.hpp> +#include <cstdio> + +int handler_invoked = 0; + +void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) +{ +#if !defined(BOOST_NO_STDC_NAMESPACE) + using std::printf; +#endif + + printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); + ++handler_invoked; +} + +struct X +{ + static bool f() + { + BOOST_VERIFY( 0 ); + return false; + } +}; + +void test_handler() +{ + int x = 1; + + BOOST_VERIFY( 1 ); + BOOST_VERIFY( x == 1 ); + BOOST_VERIFY( ++x ); + BOOST_VERIFY( f(x) ); + BOOST_VERIFY( &x ); + + BOOST_TEST( x == 3 ); + + BOOST_VERIFY( 0 ); + BOOST_VERIFY( !x ); + BOOST_VERIFY( x == 0 ); + BOOST_VERIFY( !++x ); + BOOST_VERIFY( !f(x) ); + + BOOST_TEST( x == 5 ); + + void * p = 0; + BOOST_VERIFY( p ); + + BOOST_VERIFY( X::f() ); + + BOOST_TEST( handler_invoked == 8 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +int main() +{ + test_default(); + test_disabled(); + test_handler(); + + return boost::report_errors(); +} |