Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11911 closed Bugs (worksforme)

BOOST_TEST macro's argument must be put between brackets

Reported by: anonymous Owned by: Gennadiy Rozental
Milestone: To Be Determined Component: test
Version: Boost 1.60.0 Severity: Problem
Keywords: Cc:

Description

This program doesn't work

#define BOOST_TEST_MODULE test
#include <boost/test/included/unit_test.hpp>

struct B {};
struct A {
	bool operator ==(const B &b) {
		return true;
	}
};

BOOST_AUTO_TEST_CASE(test_case) {
	A a;
	B b;
	BOOST_TEST(a == b);
	// BOOST_TEST((a == b)); // this version works
}

Change History (3)

comment:1 by Gennadiy Rozental, 7 years ago

Resolution: worksforme
Status: newclosed
  1. Don't name your test case test_case
  2. make operator== const
  3. Add BOOST_TEST_DONT_PRINT_LOG_VALUE(A) BOOST_TEST_DONT_PRINT_LOG_VALUE(B)

or implement operator<< for A and B

And this example works fine for me with single brackets.

comment:2 by anonymous, 7 years ago

About const, I forgot it in this short example and the name of the test case was randomly picked.

But, about the different behaviour when there are brackets around the condition and when not, it feels inconsistent to me. Also, I got some very cryptic error messages from the compiler referring to boost's files. I'm ok with boost trying to print the object it is testing if this is a generally expected behaviour in unit test frameworks. However a static_assert with a comprehensible error message in case this can't be done should be useful and save much debugging time.

Thank you for the help.

comment:3 by Gennadiy Rozental, 7 years ago

Try branch assert-printability

Note: See TracTickets for help on using tickets.