Skip to content

Commit 2150446

Browse files
committed
Use paths relative to executable location to find subprocess executables
1 parent 9ee345e commit 2150446

17 files changed

Lines changed: 75 additions & 16 deletions

File tree

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Fixed bugs:
77

88
Other:
99
* Updated to crypto++ 8.1
10+
* Unit tests can now be run from any directory
1011

1112

1213
Version 0.10.0

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build_script:
3636
- cmd: cmake --build . --config %CONFIGURATION%
3737
- cmd: .\test\gitversion\gitversion-test.exe
3838
# cpp-utils-test disables ThreadDebuggingTest_ThreadName.*_thenIsCorrect because the appveyor image is too old to support the API needed for that
39-
- cmd: cd .\test\cpp-utils\ && .\cpp-utils-test.exe --gtest_filter=-ThreadDebuggingTest_ThreadName.*_thenIsCorrect && cd ..\..
39+
- cmd: .\test\cpp-utils\cpp-utils-test.exe --gtest_filter=-ThreadDebuggingTest_ThreadName.*_thenIsCorrect
4040
#- cmd: .\test\fspp\fspp-test.exe
4141
- cmd: .\test\parallelaccessstore\parallelaccessstore-test.exe
4242
- cmd: .\test\blockstore\blockstore-test.exe

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
if (BUILD_TESTING)
22
include_directories(../src)
33

4+
add_subdirectory(my-gtest-main)
45
add_subdirectory(gitversion)
56
add_subdirectory(cpp-utils)
67
if (NOT MSVC)

test/blobstore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(SOURCES
2727
)
2828

2929
add_executable(${PROJECT_NAME} ${SOURCES})
30-
target_link_libraries(${PROJECT_NAME} googletest blobstore)
30+
target_link_libraries(${PROJECT_NAME} my-gtest-main googletest blobstore)
3131
add_test(${PROJECT_NAME} ${PROJECT_NAME})
3232

3333
target_enable_style_warnings(${PROJECT_NAME})

test/blockstore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ set(SOURCES
4242
)
4343

4444
add_executable(${PROJECT_NAME} ${SOURCES})
45-
target_link_libraries(${PROJECT_NAME} googletest blockstore)
45+
target_link_libraries(${PROJECT_NAME} my-gtest-main googletest blockstore)
4646
add_test(${PROJECT_NAME} ${PROJECT_NAME})
4747

4848
target_enable_style_warnings(${PROJECT_NAME})

test/cpp-utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ target_activate_cpp14(${PROJECT_NAME}_exit_signal)
6969
target_link_libraries(${PROJECT_NAME}_exit_signal cpp-utils)
7070

7171
add_executable(${PROJECT_NAME} ${SOURCES})
72-
target_link_libraries(${PROJECT_NAME} googletest cpp-utils)
72+
target_link_libraries(${PROJECT_NAME} my-gtest-main googletest cpp-utils)
7373
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_exit_status ${PROJECT_NAME}_exit_signal)
7474
add_test(${PROJECT_NAME} ${PROJECT_NAME})
7575

test/cpp-utils/assert/backtrace_test.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
#include <csignal>
33
#include "cpp-utils/assert/backtrace.h"
44
#include "cpp-utils/process/subprocess.h"
5+
#include <boost/filesystem.hpp>
6+
#include "my-gtest-main.h"
57

68
using std::string;
79
using testing::HasSubstr;
10+
namespace bf = boost::filesystem;
811

912
namespace {
1013
std::string call_process_exiting_with(const std::string& kind, const std::string& signal = "") {
1114
#if defined(_MSC_VER)
12-
constexpr const char* executable = "cpp-utils-test_exit_signal.exe";
15+
auto executable = get_executable().parent_path() / "cpp-utils-test_exit_signal.exe";
1316
#else
14-
constexpr const char* executable = "./test/cpp-utils/cpp-utils-test_exit_signal";
17+
auto executable = get_executable().parent_path() / "cpp-utils-test_exit_signal";
1518
#endif
16-
const std::string command = std::string(executable) + " \"" + kind + "\" \"" + signal + "\" 2>&1";
19+
if (!bf::exists(executable)) {
20+
throw std::runtime_error(executable.string() + " not found.");
21+
}
22+
const std::string command = executable.string() + " \"" + kind + "\" \"" + signal + "\" 2>&1";
1723
auto result = cpputils::Subprocess::call(command);
1824
return result.output;
1925
}

test/cpp-utils/process/SubprocessTest.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
#include <cpp-utils/process/subprocess.h>
22
#include <gtest/gtest.h>
3+
#include <boost/filesystem.hpp>
34

45
#include <cpp-utils/lock/ConditionBarrier.h>
6+
#include "my-gtest-main.h"
57

68
using cpputils::Subprocess;
79
using cpputils::SubprocessError;
10+
using std::string;
11+
namespace bf = boost::filesystem;
812

913
namespace {
1014
std::string exit_with_message_and_status(const char* message, int status) {
1115
#if defined(_MSC_VER)
12-
constexpr const char* executable = "cpp-utils-test_exit_status.exe";
16+
auto executable = get_executable().parent_path() / "cpp-utils-test_exit_status.exe";
1317
#else
14-
constexpr const char* executable = "./test/cpp-utils/cpp-utils-test_exit_status";
18+
auto executable = get_executable().parent_path() / "cpp-utils-test_exit_status";
1519
#endif
16-
return std::string(executable) + " \"" + message + "\" " + std::to_string(status);
20+
if (!bf::exists(executable)) {
21+
throw std::runtime_error(executable.string() + " not found.");
22+
}
23+
return executable.string() + " \"" + message + "\" " + std::to_string(status);
1724
}
1825
}
1926

test/cryfs-cli/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ set(SOURCES
1616
)
1717

1818
add_executable(${PROJECT_NAME} ${SOURCES})
19-
target_link_libraries(${PROJECT_NAME} googletest cryfs-cli cryfs-unmount fspp-fuse)
19+
target_link_libraries(${PROJECT_NAME} my-gtest-main googletest cryfs-cli cryfs-unmount fspp-fuse)
2020
add_test(${PROJECT_NAME} ${PROJECT_NAME})
2121

2222
target_enable_style_warnings(${PROJECT_NAME})

test/cryfs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ set(SOURCES
2424
)
2525

2626
add_executable(${PROJECT_NAME} ${SOURCES})
27-
target_link_libraries(${PROJECT_NAME} googletest cryfs)
27+
target_link_libraries(${PROJECT_NAME} my-gtest-main googletest cryfs)
2828
add_test(${PROJECT_NAME} ${PROJECT_NAME})
2929

3030
target_enable_style_warnings(${PROJECT_NAME})

0 commit comments

Comments
 (0)