diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index 5e0ef5c..e263e01 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -189,13 +189,13 @@ void test_all_eq_impl(FormattedOutputFunction& output, { if (std::distance(first_begin, first_end) != std::distance(second_begin, second_end)) { - ::boost::detail::error_impl("Container sizes are different", __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); + ::boost::detail::error_impl("Container sizes are different", file, line, function); } else { ForwardIterator1 first_it = first_begin; ForwardIterator2 second_it = second_begin; - bool first_iteration = true; + std::size_t error_count = 0; do { while ((first_it != first_end) && (second_it != second_end) && (*first_it == *second_it)) @@ -205,20 +205,27 @@ void test_all_eq_impl(FormattedOutputFunction& output, } if (first_it == first_end) { - boost::detail::report_errors_remind(); - return; + break; // do-while } - if (first_iteration) + if (error_count == 0) { - first_iteration = true; output << file << "(" << line << "): Container contents differ in function '" << function << "': mismatching indices"; } output << " [" << std::distance(first_begin, first_it) << "] '" << *first_it << "' != '" << *second_it << "'"; ++first_it; ++second_it; + ++error_count; } while (first_it != first_end); - output << std::endl; - ++boost::detail::test_errors(); + + if (error_count == 0) + { + boost::detail::report_errors_remind(); + } + else + { + output << std::endl; + ++boost::detail::test_errors(); + } } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 31ba00f..fb9845f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -78,6 +78,7 @@ run-fail lightweight_test_fail8.cpp ; run-fail lightweight_test_fail8.cpp : : : off : lightweight_test_fail8_no_rtti ; run-fail lightweight_test_fail9.cpp ; run-fail lightweight_test_fail10.cpp ; +run-fail lightweight_test_fail11.cpp ; run is_same_test.cpp ; diff --git a/test/lightweight_test_fail11.cpp b/test/lightweight_test_fail11.cpp new file mode 100644 index 0000000..474d307 --- /dev/null +++ b/test/lightweight_test_fail11.cpp @@ -0,0 +1,50 @@ +// +// Negative test for BOOST_TEST_ALL_EQ +// +// Copyright (c) 2017 Bjorn Reese +// +// 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 +#include + +int main() +{ + int test_cases = 0; + + { + std::vector x, y; + x.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + { + std::vector x, y; + y.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1.0f ); x.push_back( 2.0f ); x.push_back( 3.0f ); x.push_back( 4.0f ); + y.push_back( 4.0f ); y.push_back( 2.0f ); y.push_back( 3.0f ); y.push_back( 1.0f ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + boost::report_errors(); + + return boost::detail::test_errors() == test_cases; +}