b2 icon indicating copy to clipboard operation
b2 copied to clipboard

b2 unit-test '\0' output cache

Open fasxmut opened this issue 3 years ago • 0 comments

If there is a '\0' outputed, the rest information will be not outputed.

I first found it when I printed char std::array and std::vector.

test.cpp

#include <boost/assert.hpp>
#include <array>
#include <vector>
#include <iostream>

int main()
{
	std::array<char, 13> array{"Hello Boost!"};
	BOOST_ASSERT(array[12] == '\0');
	for (auto & x: array)
		std::cout << x;
	std::cout << std::endl; // This '\n' is not outputed.
	std::cout << "Hello C++!\n"; // This is not printed.
}

jamroot

import testing ;

unit-test test : test.cpp : <cxxstd>20 ;

output:

$ b2
...found 13 targets...
...updating 3 targets...
gcc.compile.c++ bin/gcc-12/debug/cxxstd-20-iso/test.o
gcc.link bin/gcc-12/debug/cxxstd-20-iso/test
testing.unit-test bin/gcc-12/debug/cxxstd-20-iso/test.passed
Hello Boost!...updated 3 targets...

If I use boost::unit_test, it gives the similar result, and the nice colorful "No errors detected" is not printed, because everything after '\0' are not printed.

Another example using boost::unit_test

test.cpp

#define BOOST_TEST_MODULE test.cpp
#include <boost/test/unit_test.hpp>
#include <array>
#include <vector>
#include <iostream>

BOOST_AUTO_TEST_CASE(case01)
{
	std::array<char, 13> array{"Hello Boost!"};
	BOOST_CHECK_EQUAL(array[12], '\0');
	for (auto & x: array)
		std::cout << x;
	std::cout << std::endl; // This '\n' is not outputed.
	std::cout << "Hello C++!\n"; // This is not printed.
}

jamroot

import testing ;

unit-test test : test.cpp : <cxxstd>20 <define>BOOST_TEST_DYN_LINK
	<linkflags>-lboost_unit_test_framework ;

output:

$ b2
...found 13 targets...
...updating 7 targets...
gcc.compile.c++ bin/gcc-12/debug/cxxstd-20-iso/test.o
gcc.link bin/gcc-12/debug/cxxstd-20-iso/test
testing.unit-test bin/gcc-12/debug/cxxstd-20-iso/test.passed
Running 1 test case...
Hello Boost!...updated 7 targets...

fasxmut avatar Nov 11 '22 12:11 fasxmut