add overload Catch::makeTestInvoker() which takes std::function<void()>.
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
I have a test case which looks similar to the following:
```
TEST_CASE("name", "[tag]") {
std::vector const time= {...};
std::vector const other= {...};
for (size_t t = 0, T = time.size(); t < T; ++t) {
for (size_t k = 0, K = other.size(); k < K; ++k) {
check(t,k);
}
}
}
```
I'd like to be able to make check(t,k) a separate test. I believed if Catch::makeTestInvoker() were overloaded to take a std::function I would be able to do something like:
```
void manual_register_test() {
std::vector const time= {...};
std::vector const other= {...};
for (size_t t = 0, T = time.size(); t < T; ++t) {
for (size_t k = 0, K = other.size(); k < K; ++k) {
auto const check_tk = [=]() { check(t,k); };
std::string name_check_tk = /*...*/;
REGISTER_TEST_CASE(check_tk, name_tk, "[tag]");
}
}
}
```
From what I can tell adding code similar to the following would do:
```
class test_invoker_std_function : public Catch::ITestInvoker {
std::function f_;
void invoke() const override { f_(); }
public:
test_invoker_std_function(std::function f) : f_(f) {}
};
auto makeTestInvoker(std::function f) noexcept -> Catch::ITestInvoker* {
return new (std::nothrow) test_invoker_std_function(f);
}
```
Contributor guide
Research direction
Start by locating Catch::makeTestInvoker(), Catch::ITestInvoker, and REGISTER_TEST_CASE in the codebase, then trace how manually registered test cases are created and invoked. Confirm how a std::function would fit that path and define done as supporting the demonstrated loop-generated test cases with distinct names and tags.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100