boostorg / boostorg/core

[lwt] Allow to specify custom source location for a check

Open
#139 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
156
Forks
116
PR merge metrics
No merged PRs in 30d

Description

Suppose we have a common utility class that performs a check on the passed value:

```
template< typename T >
class checker
{
T& m_expected;

public:
void operator() (T const& res) const noexcept
{
BOOST_TEST_EQ(res, m_expected);
}
};
```

and then we use this class in multiple tests with different types and expected values.

```
void check_stuff()
{
checker checker1(10);
checker1(20);

checker checker2(30);
checker2(40);
}
```

The problem is if any of these checks fail, the output always shows the location of the `BOOST_TEST_EQ` line, not the location of the particular use of `checker`.

Proposed solution 1:

Make `test_with_impl` API public, so that the user is able to define his own `BOOST_TEST_EQ`-like macro that will pass a custom source location. This leaves the implementation of such source location tracking mechanism to the user.

Proposed solution 2:

Add a new set of macros that will use a custom source location that was saved previously by a new macro (let's call it `BOOST_TEST_CHECKPOINT`). The user will use `BOOST_TEST_CHECKPOINT` to save the location of the original use of the `checker`. Alternatively (or additionally) we could provide a non-macro API to the same effect. Usage example:

```
void check_stuff()
{
checker checker1(10); BOOST_TEST_CHECKPOINT;
checker1(20);

checker checker2(30); BOOST_TEST_CHECKPOINT;
checker2(40);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.