I'm performing some validation tests on several XML files, some of which contain hyphens in the name. I've created a parameterized test case containing the file names (excluding extensions) but GoogleTest fails because
Note: test names must be non-empty, unique, and may only contain ASCII alphanumeric characters or underscore. Because PrintToString adds quotes to std::string and C strings, it won't work for these types.
class ValidateTemplates :public testing::TestWithParam<string>
{
public:
struct PrintToStringParamName
{
template <class ParamType>
string operator() (const testing::TestParamInfo<ParamType>& info) const
{
auto file_name = static_cast<string>(info.param);
// Remove the file extension because googletest's PrintToString may only
// contain ASCII alphanumeric characters or underscores
size_t last_index = file_name.find_last_of(".");
return file_name.substr(0, last_index);
}
};
};
INSTANTIATE_TEST_CASE_P(
ValidateTemplates,
ValidateTemplates,
testing::ValuesIn(list_of_files),
ValidateTemplates::PrintToStringParamName());
I had the idea of printing the filename with non-alphanumeric characters swapped out for underscores in PrintToStringParamName. But I'd rather keep the parameterized names the same as the file names if possible.
Is there a way to get around this limitation somehow? I can't permanently change the file names and I can't use another testing framework.