ut icon indicating copy to clipboard operation
ut copied to clipboard

Feature: allow test name customisation when using parameters via | operator

Open lgrossi opened this issue 2 years ago • 1 comments

Expected Behavior

When using parametrization with | operator would be nice to be able to give each test a unique identifier, to make spot of issues easier and to avoid weird behaviors. E.g. when using parametrization with | the number of assertions is way higher than the same set of tests using for();

Actual Behavior

When comparing different ways of adding test parameters, we have:

suite<"more assertions"> a = [] {
	test("MyTest") = [](auto fixture) {
		expect(fixture > 0);
		expect(false);
	} | std::vector{1,2,3,4};
};

suite<"less assertions"> b = [] {
	for(auto fixture : std::vector{1,2,3,4}) {
        test("MyTest" + std::to_string(fixture)) = [&fixture]() {
			expect(fixture > 0);
            expect(false);
        };
    }
};

The first way, using | has two problems: it doesn't allow test name customisation, leaving to warnings during failures, and it creates way more assertions than the second approach. image image

Ideally would be nice that both ways have a consistent behavior and that no extra assertions get generated in the print.

Steps to Reproduce the Problem

Running the snapshot above should already give you that.

Specifications

  • Version: v1.1.9
  • Platform: Linux
  • Subsystem: Ubuntu

lgrossi avatar Aug 27 '23 10:08 lgrossi

This issue should be fixed by #640 (the tests will now have a unique name, and you can modify how the parameter is formatted). In https://github.com/boost-ext/ut/pull/659, I added your reproducer above as a regression test to the test suite, @lgrossi. Is there anything else left here?

tobiasleibner avatar Feb 04 '25 09:02 tobiasleibner