(I set reply-to for a reason. Please keep discussion on the list.)
On 2013-02-11 18:42, Joey Oravec wrote:
> It may be difficult if you're relying on the default printer.
Huh? I don't see where "the default printer" has anything to do with my
question. I'm talking about the test names, which are generated by
TypeParameterizedTest::Register passed to MakeAndRegisterTestInfo.
In fact, from my reading of the applicable code, it is not possible to
provide a name using the existing mechanisms, since the parameter suffix
comes from String::Format("%d", index) and cannot be changed once the
test object is constructed.
> The challenge you'd face in convincing people to change the naming is that
> macros are used to auto generate functions, objects, and variables from
> that name so there are constraints (just like on your test name and class).
I don't see that the parameter participates in an identifier name
anywhere. (I can imagine that would be very difficult, since currently I
see nothing preventing a type parameter from being something crazy like
'typename Foo<Bar, 5>'.)
> It would also impose a lot of changes to how you specify the test in a
> commandline arg for filtering.
Again, I don't see the problem... so you might pass "MyTest/int" instead
of "MyTest/0" as the filter argument. The filtering itself doesn't
change. This is only a problem if you are relying on some scripted
external mechanism for invoking the tests... in which case, just don't
use the feature.
>> Is it possible to give more meaningful names to typed tests than "/0",
>> "/1", etc.? (And no, I don't want prefixes, I want to get rid of the
>> useless index value, e.g. "MyTest/int-Works".)
So, I managed to achieve what I want by tinkering with gtest's guts (and
in the process, made typed tests more convenient). Please see
http://github.com/mwoehlke/gtest/tree/typed-tests-with-named-parameters.
Using this, I can do:
TYPED_TEST_CASE_WITH_NAMES(Matrix, float, double);
TYPED_TEST(Matrix, Identity) { /* ... */ }
...and get tests with names like:
Matrix/float.Identity
Matrix/double.Identity
Even better, it should have no effect on users of TYPED_TEST_CASE.
There are caveats, of course... the type names cannot contain ','s (use
typedefs to work around), and TYPED_TEST_CASE_WITH_NAMES must be used in
the global namespace (no anonymous namespaces). The latter is because I
was not able to figure out how to correctly declare the template
specialization otherwise. (Although I didn't spend a huge lot of time;
nesting it in an extra class that can be typedef'd into scope might work.
This may need to be conditionally disabled if support for ancient
compilers is needed, but that should be okay. (Only the new macro itself
should need to be hidden.)
--
Matthew