Describe the bug
When compiler flags are such that __FILE__ macro is replaced with a relative file path (on MSVC no /Z7, /Zi or /ZI and no /FC) then it might be replaced with just a filename with no path separators. In this case tags for tests with --filenames-as-tags do not contain '#' symbol.
The bug is present in the 2.x branch, but not in the main branch where the relevant code has been redesigned.
The culprit is the following code in catch_session.cpp:
void applyFilenamesAsTags(Catch::IConfig const& config) {
auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
for (auto& testCase : tests) {
auto tags = testCase.tags;
std::string filename = testCase.lineInfo.file;
auto lastSlash = filename.find_last_of("\\/");
if (lastSlash != std::string::npos) {
filename.erase(0, lastSlash);
filename[0] = '#';
}
auto lastDot = filename.find_last_of('.');
if (lastDot != std::string::npos) {
filename.erase(lastDot);
}
tags.push_back(std::move(filename));
setTags(testCase, tags);
}
}
Adding the following nonintrusive but uninspired adjustment resolves the issue:
void applyFilenamesAsTags(Catch::IConfig const& config) {
auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
for (auto& testCase : tests) {
auto tags = testCase.tags;
std::string filename = testCase.lineInfo.file;
auto lastSlash = filename.find_last_of("\\/");
if (lastSlash != std::string::npos) {
filename.erase(0, lastSlash);
filename[0] = '#';
}
else
{
filename.insert(0, "#");
}
auto lastDot = filename.find_last_of('.');
if (lastDot != std::string::npos) {
filename.erase(lastDot);
}
tags.push_back(std::move(filename));
setTags(testCase, tags);
}
}
Expected behavior
Symbol # always prefixes filename tags.
Reproduction steps
Compiler flags (MSVC): no /Z7, /Zi, /ZI, /FC
Catch flags: [#test_file] --filenames-as-tags
Place test_file.cpp with any test cases in the root project directory and try to run them.
In the current 2.x branch no tests would be found.
The text was updated successfully, but these errors were encountered:
Describe the bug
When compiler flags are such that __FILE__ macro is replaced with a relative file path (on MSVC no /Z7, /Zi or /ZI and no /FC) then it might be replaced with just a filename with no path separators. In this case tags for tests with --filenames-as-tags do not contain '#' symbol.
The bug is present in the 2.x branch, but not in the main branch where the relevant code has been redesigned.
The culprit is the following code in catch_session.cpp:
Adding the following nonintrusive but uninspired adjustment resolves the issue:
Expected behavior
Symbol # always prefixes filename tags.
Reproduction steps
Compiler flags (MSVC): no /Z7, /Zi, /ZI, /FC
Catch flags: [#test_file] --filenames-as-tags
Place test_file.cpp with any test cases in the root project directory and try to run them.
In the current 2.x branch no tests would be found.
The text was updated successfully, but these errors were encountered: