early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -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()

View File

@@ -0,0 +1,44 @@
# 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
<toolset>gcc-4.4:<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 ;
run source_location_test4.cpp ;
run source_location_test5.cpp ;

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -0,0 +1,157 @@
//
// assert_test.cpp - a test for boost/assert.hpp
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 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; (void)x;
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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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>)

View File

@@ -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 );
}

View File

@@ -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(../.. 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>)

View File

@@ -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 );
}

View File

@@ -0,0 +1,39 @@
#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): in function '%s': %s\n", file, line, func, msg);
}
#define MESSAGE(msg) message(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, msg)
int main()
{
MESSAGE("testing BOOST_CURRENT_FUNCTION");
return 0;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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; (void)x;
BOOST_ASSERT( x == 1 );
}

View File

@@ -0,0 +1,66 @@
// 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(), "" );
BOOST_TEST_CSTR_EQ( loc.function_name(), "" );
BOOST_TEST_EQ( loc.line(), 0 );
BOOST_TEST_EQ( loc.column(), 0 );
}
{
boost::source_location loc( __FILE__, __LINE__, "main()" );
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 20 );
BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" );
BOOST_TEST_EQ( loc.column(), 0 );
}
{
boost::source_location loc( "file", 1, "main()", 2 );
BOOST_TEST_CSTR_EQ( loc.file_name(), "file" );
BOOST_TEST_EQ( loc.line(), 1 );
BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" );
BOOST_TEST_EQ( loc.column(), 2 );
}
{
boost::source_location loc = BOOST_CURRENT_LOCATION;
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 38 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 45 );
}
#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
{
std::source_location loc = std::source_location::current();
boost::source_location loc2 = loc;
BOOST_TEST_CSTR_EQ( loc2.file_name(), loc.file_name() );
BOOST_TEST_CSTR_EQ( loc2.function_name(), loc.function_name() );
BOOST_TEST_EQ( loc2.line(), loc.line() );
BOOST_TEST_EQ( loc2.column(), loc.column() );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,31 @@
// 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(), "" );
BOOST_TEST_CSTR_EQ( loc.function_name(), "" );
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(), "" );
BOOST_TEST_CSTR_EQ( loc.function_name(), "" );
BOOST_TEST_EQ( loc.line(), 0 );
BOOST_TEST_EQ( loc.column(), 0 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,74 @@
// Copyright 2020, 2021 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;
BOOST_TEST_EQ( loc.to_string(), std::string( "(unknown source location)" ) );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
{
boost::source_location loc( "file", 5, "" );
BOOST_TEST_EQ( loc.to_string(), std::string( "file:5" ) );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
{
boost::source_location loc( "file", 7, "main()" );
BOOST_TEST_EQ( loc.to_string(), std::string( "file:7 in function 'main()'" ) );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
{
boost::source_location loc( "file", 11, "main()", 13 );
BOOST_TEST_EQ( loc.to_string(), std::string( "file:11:13 in function 'main()'" ) );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
{
boost::source_location loc( "file", 17, "", 19 );
BOOST_TEST_EQ( loc.to_string(), std::string( "file:17:19" ) );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
{
boost::source_location loc = BOOST_CURRENT_LOCATION;
std::string prefix = std::string( __FILE__ ) + ":62";
BOOST_TEST_EQ( loc.to_string().substr( 0, prefix.size() ), prefix );
std::ostringstream os;
os << loc;
BOOST_TEST_EQ( os.str(), loc.to_string() );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,44 @@
// Copyright 2022 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 <boost/config.hpp>
boost::source_location s_loc = BOOST_CURRENT_LOCATION;
BOOST_STATIC_CONSTEXPR boost::source_location c_loc = BOOST_CURRENT_LOCATION;
boost::source_location f( boost::source_location const& loc = BOOST_CURRENT_LOCATION )
{
return loc;
}
int main()
{
{
BOOST_TEST_CSTR_EQ( s_loc.file_name(), __FILE__ );
BOOST_TEST_EQ( s_loc.line(), 9 );
#if defined(BOOST_GCC) && BOOST_GCC < 90000
// '__static_initialization_and_destruction_0'
#else
BOOST_TEST_CSTR_EQ( s_loc.function_name(), "" );
#endif
}
{
BOOST_TEST_CSTR_EQ( c_loc.file_name(), __FILE__ );
BOOST_TEST_EQ( c_loc.line(), 11 );
}
{
boost::source_location loc = f();
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST( loc.line() == 13 || loc.line() == 37 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,44 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// Reduced from a boost::system::result test; codegen bug
// in GCC < 5 which is somehow triggered by __PRETTY_FUNCTION__
// and throwing an exception
#include <boost/assert/source_location.hpp>
#include <boost/core/lightweight_test.hpp>
#include <exception>
template<class T> class result
{
private:
bool has_value_;
T value_;
public:
result(): has_value_( false ), value_()
{
}
T value( boost::source_location const& /*loc*/ = BOOST_CURRENT_LOCATION ) const
{
if( has_value_ )
{
return value_;
}
else
{
throw std::exception();
}
}
};
int main()
{
result<int> r;
BOOST_TEST_THROWS( r.value(), std::exception );
return boost::report_errors();
}

View File

@@ -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();
}