Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 2.31 KB

Utilities.md

File metadata and controls

63 lines (45 loc) · 2.31 KB

Utilities

Contents

DateUtils

You can easily create and print C++11 dates and times.

For example:

std::chrono::system_clock::time_point dateTime =
    DateUtils::createUtcDateTime(2000, 1, 13, 3, 34, 45);

std::string dateTimeString = DateUtils::toString(dateTime);

snippet source | anchor

will produce:

Thu 2000-01-13 03:34:45 UTC

snippet source | anchor

Times are printed in UTC, as this is a testing utility and consistency across machines is desirable.

There is an overload of DateUtils::toString() that takes a format string, should you wish to print it differently.

ExceptionCollector

ExceptionCollector is a utility that allows you to have multiple exceptions thrown, without stopping the execution of the program, and then throw them all later.

ExceptionCollector exceptions;
for (int i = 1; i <= 4; ++i)
{
    exceptions.gather([&]() { /* Code that may throw errors here */ });
}
exceptions.release(); // All errors actually thrown together here

snippet source | anchor

Use with Approval Tests: See Approving multiple files in one test.


Back to User Guide