Catch2: Provide support for std::chrono::duration comparisons

Created on 7 Oct 2017  路  10Comments  路  Source: catchorg/Catch2

I have a timed-section-impl structure which wraps some section of arbitrary functional code (i.e. std::function) in a timed block. However, I get the following failure afterwards.

REQUIRE(after >= (before + timeout));
REQUIRE(after < (before + timeout * 2));

Where before and after are both high_resolution_clock::now() results, before and after the functional callback, respectively.

First is, the requirement is failing properly. However, the expansion doesn't know what to do with duration operands.

<path/to>/tests/timed_section_
impl.hpp(37): FAILED:
  REQUIRE( after >= (before + timeout) )
with expansion:
  {?} >= {?}
Feature Request

Most helpful comment

@dan-ryan Personally, I have not had a need for it in awhile, to be honest.

@horenmar The documentation links are broken, BTW.

All 10 comments

We should be able to do that, but it will likely end up disabled by default, we would have to drag the <chrono> header into every file otherwise.

_It actually might be a good idea to make all std stringification specializations optional_

@horenmar Thanks! I consider this a LOW priority, however, as contrasted with threading support. That one is a HUGE deal right now.

This is now in the Catch 2 branch.

@horenmar Wow, thanks! I was going to suggest, I would be okay with a second include shimming in std::chrono support if it adds that much overhead.

Something like:

#include <catch/catch_std_chrono.hpp>

It is disabled by default, see documentation

This is now in the single include, too.
@mwpowellhtx does this close your issue?

@philsquared Looks good, thanks so much.

Thanks!

Anyone else having trouble turning this option on?

@dan-ryan Personally, I have not had a need for it in awhile, to be honest.

@horenmar The documentation links are broken, BTW.

Was this page helpful?
0 / 5 - 0 ratings