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

Support conditional expressions in REQUIRE #262

Closed
rherrmannr opened this issue Aug 2, 2019 · 3 comments
Closed

Support conditional expressions in REQUIRE #262

rherrmannr opened this issue Aug 2, 2019 · 3 comments

Comments

@rherrmannr
Copy link

Description

Conditional expression seems not be supported for REQUIRE(..) and REQUIRE_FALSE(..).

A simple example:

void fn(bool cond) {
	REQUIRE(cond ? true : false);
}

TEST_CASE("test") {
	fn(true);
}

Compiler output:

../Test.cpp: In function ‘void guardedexit::fn(bool)’:
../doctest.h:2101:13: error: could not convert ‘doctest::detail::ExpressionDecomposer((doctest::assertType::Enum)12).doctest::detail::ExpressionDecomposer::operator<< <bool>(cond)’ from ‘doctest::detail::Expression_lhs<const bool&>’ to ‘bool’
             << __VA_ARGS__))                                                                       \
../doctest.h:1868:9: note: in definition of macro ‘DOCTEST_WRAP_IN_TRY’
         x;                                                                                         \
         ^
../doctest.h:2107:9: note: in expansion of macro ‘DOCTEST_ASSERT_IMPLEMENT_2’
         DOCTEST_ASSERT_IMPLEMENT_2(assert_type, __VA_ARGS__);                                      \
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
../doctest.h:2123:30: note: in expansion of macro ‘DOCTEST_ASSERT_IMPLEMENT_1’
 #define DOCTEST_REQUIRE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE, __VA_ARGS__)
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
../doctest.h:2569:17: note: in expansion of macro ‘DOCTEST_REQUIRE’
 #define REQUIRE DOCTEST_REQUIRE
                 ^~~~~~~~~~~~~~~
../Test.cpp:46:2: note: in expansion of macro ‘REQUIRE’
  REQUIRE(cond ? true : false);
  ^~~~~~~
subdir.mk:21: recipe for target 'Test.o' failed
make: *** [Test.o] Error 1

Is it possible to add support for conditional expressions?

Extra information

  • doctest version: latest (2.3.3) and tag 1.2.9
  • Operating System: Ubuntu 18.04.1
  • Compiler+version: gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
@onqtam
Copy link
Member

onqtam commented Aug 5, 2019

You will need to wrap the expression in extra round braces like REQUIRE((cond ? true : false)) to make that work. The issue is that doctest uses a bunch of templates to decompose expressions so it is able to extract the left and right hand side of comparisons such as a == b.

I'll keep this issue open just to investigate if there is anything that could be done in the future, but I might just close it at some point.

@rherrmannr
Copy link
Author

Thanks for the fast response. This is very helpful for me 👍

@onqtam
Copy link
Member

onqtam commented Aug 12, 2019

I thought about it a bit more and it's unlikely that there is anything that can be done on the side of doctest for this one. I'm closing it...

@onqtam onqtam closed this as completed Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants