Skip to content

Commit 46f3efd

Browse files
Allow cloc tests to be run from default location.
Change-Id: Ic5f8e34ff261b45100c98a6065b1aeaab3c4d665
1 parent b4f79e0 commit 46f3efd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

unit_tests/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,13 @@ int main(int argc, char **argv) {
272272

273273
#ifdef WIN32
274274
#include <direct.h>
275-
_chdir(hardwarePrefix[productFamily]);
275+
if (_chdir(hardwarePrefix[productFamily])) {
276+
std::cout << "chdir into " << hardwarePrefix[productFamily] << " directory failed.\nThis might cause test failures." << std::endl;
277+
}
276278
#elif defined(__linux__)
277279
#include <unistd.h>
278280
if (chdir(hardwarePrefix[productFamily]) != 0) {
279-
std::cout << "chdir failed! Ignoring." << std::endl;
281+
std::cout << "chdir into " << hardwarePrefix[productFamily] << " directory failed.\nThis might cause test failures." << std::endl;
280282
}
281283
#endif
282284

unit_tests/offline_compiler/main.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ std::string getRunPath(char *argv0) {
4343

4444
auto pos = res.rfind(fSeparator);
4545
if (pos != std::string::npos)
46-
return res.substr(0, pos);
46+
res = res.substr(0, pos);
47+
48+
if (res == "." || pos == std::string::npos) {
49+
#if defined(__linux__)
50+
res = getcwd(nullptr, 0);
51+
#else
52+
res = _getcwd(nullptr, 0);
53+
#endif
54+
}
4755

4856
return res;
4957
}
@@ -96,6 +104,18 @@ int main(int argc, char **argv) {
96104
nTestFiles.append(testFiles);
97105
testFiles = nTestFiles;
98106

107+
#ifdef WIN32
108+
#include <direct.h>
109+
if (_chdir(devicePrefix.c_str())) {
110+
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
111+
}
112+
#elif defined(__linux__)
113+
#include <unistd.h>
114+
if (chdir(devicePrefix.c_str()) != 0) {
115+
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
116+
}
117+
#endif
118+
99119
if (useDefaultListener == false) {
100120
::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
101121
::testing::TestEventListener *defaultListener = listeners.default_result_printer();

0 commit comments

Comments
 (0)