Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data test cases fail with bool initializer list #217

Closed
ShadowIce opened this issue Apr 18, 2019 · 5 comments
Closed

Data test cases fail with bool initializer list #217

ShadowIce opened this issue Apr 18, 2019 · 5 comments
Assignees
Milestone

Comments

@ShadowIce
Copy link

@ShadowIce ShadowIce commented Apr 18, 2019

If a data test case uses boolean values directly passed to make in the BOOST_DATA_TEST_CASE macro the resulting value will be more or less random. This happens when compiling it on macOS / clang 10.0.1 / boost 1.7.0, but not on Windows with VS2017. It also doesn't happen with any other data types except bool.

constexpr bool ExpectedValues[] = { false, true, true, true, false, false};
BOOST_DATA_TEST_CASE(BoostDataTest
	, boost::unit_test::data::make({ false, true, true, true, false, false }) ^
	  boost::unit_test::data::make(ExpectedValues)
	, value, expectedValue)
{
	BOOST_TEST(value == expectedValue);
}

It doesn't happen if I rewrite it like this:

constexpr bool ExpectedValues[] = { false, true, true, true, false, false};
auto DataValues = boost::unit_test::data::make({ false, true, true, true, false, false });
BOOST_DATA_TEST_CASE(BoostDataTest2
	,  DataValues ^
	  boost::unit_test::data::make(ExpectedValues)
	, value, expectedValue)
{
	BOOST_TEST(value == expectedValue);
}
@raffienficiaud raffienficiaud added this to the 1.71 milestone May 13, 2019
@raffienficiaud raffienficiaud added 1.71 and removed 1.71 labels May 13, 2019
@raffienficiaud raffienficiaud added 1.72 and removed 1.71 labels Aug 3, 2019
@raffienficiaud raffienficiaud modified the milestones: 1.71, 1.72 Aug 3, 2019
@b-spencer

This comment has been minimized.

Copy link

@b-spencer b-spencer commented Oct 7, 2019

This appears to happen because the boost::unit_test::data::monomorphic::init_list<bool> specialization that captures the data set uses a vector<bool> itself. Thus, its iterators dereference to a proxy type that only references the original value from the initial data set, and it is those proxies that get captured in the bound function during test setup.

One fix that seems to work is to introduce a wrapper structure inside init_list<bool> with a bool conversion operator, and then store the data set in a vector of that instead. Its iterators return non-proxy values, and then it should work.

@raffienficiaud

This comment has been minimized.

Copy link
Member

@raffienficiaud raffienficiaud commented Oct 7, 2019

Thanks for the hints, it helped a lot. I've made a fix in the branch topic/GH-217-init-list-boolean, it would be great if you can test it.

@b-spencer

This comment has been minimized.

Copy link

@b-spencer b-spencer commented Oct 9, 2019

Great! I will take a look and try it. It might be a few days, though.

@b-spencer

This comment has been minimized.

Copy link

@b-spencer b-spencer commented Oct 15, 2019

The fix on that topic branch seems to work for me. Thanks!

raffienficiaud added a commit that referenced this issue Oct 20, 2019
* topic/GH-217-init-list-boolean:
  Change log
  Avoiding any proxying of the boolean values
@raffienficiaud raffienficiaud added develop and removed fix-proposed labels Oct 20, 2019
@raffienficiaud raffienficiaud self-assigned this Oct 20, 2019
@raffienficiaud

This comment has been minimized.

Copy link
Member

@raffienficiaud raffienficiaud commented Oct 21, 2019

In master, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.