Accept both slashes in test harness on Win32

This fixes tests when __FILE__ produces output separated with / instead
of \, like on my Windows+MSYS2+GCC config

Fixes #563
pull/572/head
nabijaczleweli 2020-03-23 01:24:47 +01:00 committed by whitequark
parent e355a095c4
commit aeaece53e1
1 changed files with 7 additions and 5 deletions

View File

@ -23,8 +23,10 @@ namespace Platform {
#ifdef TEST_BUILD_ON_WINDOWS #ifdef TEST_BUILD_ON_WINDOWS
static const char *VALID_BUILD_PATH_SEPS = "/\\";
static char BUILD_PATH_SEP = '\\'; static char BUILD_PATH_SEP = '\\';
#else #else
static const char *VALID_BUILD_PATH_SEPS = "/";
static char BUILD_PATH_SEP = '/'; static char BUILD_PATH_SEP = '/';
#endif #endif
@ -33,7 +35,7 @@ static std::string BuildRoot() {
if(!rootDir.empty()) return rootDir; if(!rootDir.empty()) return rootDir;
rootDir = __FILE__; rootDir = __FILE__;
rootDir.erase(rootDir.rfind(BUILD_PATH_SEP) + 1); rootDir.erase(rootDir.find_last_of(VALID_BUILD_PATH_SEPS) + 1);
return rootDir; return rootDir;
} }
@ -156,7 +158,7 @@ Platform::Path Test::Helper::GetAssetPath(std::string testFile, std::string asse
assetName.insert(assetName.rfind('.'), "." + mangle); assetName.insert(assetName.rfind('.'), "." + mangle);
} }
testFile.erase(0, BuildRoot().size()); testFile.erase(0, BuildRoot().size());
testFile.erase(testFile.rfind(BUILD_PATH_SEP) + 1); testFile.erase(testFile.find_last_of(VALID_BUILD_PATH_SEPS) + 1);
return HostRoot().Join(Platform::Path::FromPortable(testFile + assetName)); return HostRoot().Join(Platform::Path::FromPortable(testFile + assetName));
} }
@ -354,7 +356,7 @@ int main(int argc, char **argv) {
for(Test::Case &testCase : *testCasesPtr) { for(Test::Case &testCase : *testCasesPtr) {
std::string testCaseName = testCase.fileName; std::string testCaseName = testCase.fileName;
testCaseName.erase(0, BuildRoot().size()); testCaseName.erase(0, BuildRoot().size());
testCaseName.erase(testCaseName.rfind(BUILD_PATH_SEP)); testCaseName.erase(testCaseName.find_last_of(VALID_BUILD_PATH_SEPS));
testCaseName += BUILD_PATH_SEP + testCase.caseName; testCaseName += BUILD_PATH_SEP + testCase.caseName;
std::smatch filterMatch; std::smatch filterMatch;