Skip to content

Commit a3940f2

Browse files
WillAyddongjoon-hyun
authored andcommitted
ORC-1936: Get build and example dir from build system rather than gtest
### What changes were proposed in this pull request? Rather than pulling the build and example directory from gtest arguments, this pulls it from the build system. ### Why are the changes needed? When orc is used as a subproject, the current method of grabbing the arguments from the build system fails ### How was this patch tested? Tests were run locally ### Was this patch authored or co-authored using generative AI tooling? No Closes #2291 from WillAyd/improve-gtest-cli. Authored-by: Will Ayd <william.ayd@icloud.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent e77aabb commit a3940f2

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

tools/test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ target_include_directories(tool-test PRIVATE
4545
${PROJECT_SOURCE_DIR}/tools-c++/src
4646
)
4747

48+
target_compile_definitions(tool-test PRIVATE
49+
"-DORC_EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/examples"
50+
"-DORC_BUILD_DIR=${PROJECT_BINARY_DIR}"
51+
)
52+
4853
add_dependencies(tool-test tool-set)
4954

5055
if (TEST_VALGRIND_MEMCHECK)

tools/test/ToolTest.cc

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,9 @@
2929
#include <string>
3030
#include <vector>
3131

32-
namespace {
33-
const char* exampleDirectory = 0;
34-
const char* buildDirectory = 0;
35-
} // namespace
36-
3732
GTEST_API_ int main(int argc, char** argv) {
3833
GOOGLE_PROTOBUF_VERIFY_VERSION;
3934
std::cout << "ORC version: " << ORC_VERSION << "\n";
40-
if (argc >= 2) {
41-
exampleDirectory = argv[1];
42-
} else {
43-
exampleDirectory = "../examples";
44-
}
45-
if (argc >= 3) {
46-
buildDirectory = argv[2];
47-
} else {
48-
buildDirectory = ".";
49-
}
50-
std::cout << "example dir = " << exampleDirectory << "\n";
51-
if (buildDirectory) {
52-
std::cout << "build dir = " << buildDirectory << "\n";
53-
}
5435
testing::InitGoogleTest(&argc, argv);
5536
int result = RUN_ALL_TESTS();
5637
google::protobuf::ShutdownProtobufLibrary();
@@ -77,12 +58,16 @@ int runProgram(const std::vector<std::string>& args, std::string& out, std::stri
7758
return WEXITSTATUS(status);
7859
}
7960

61+
#define ORC_TOOL_TEST_STRINGIFY(path) ORC_TOOL_TEST_STR(path)
62+
#define ORC_TOOL_TEST_STR(path) #path
63+
8064
/**
8165
* Get the name of the given example file.
8266
* @param name the simple name of the example file
8367
*/
8468
std::string findExample(const std::string& name) {
85-
std::string result = exampleDirectory;
69+
#define ORC_EXAMPLE_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_EXAMPLE_DIR)
70+
std::string result = ORC_EXAMPLE_DIR_STR;
8671
result += "/";
8772
result += name;
8873
return result;
@@ -93,7 +78,8 @@ std::string findExample(const std::string& name) {
9378
* @param name the simple name of the executable
9479
*/
9580
std::string findProgram(const std::string& name) {
96-
std::string result = buildDirectory;
81+
#define ORC_BUILD_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_BUILD_DIR)
82+
std::string result = ORC_BUILD_DIR_STR;
9783
result += "/";
9884
result += name;
9985
return result;

tools/test/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ exc = executable(
3636
gtest_dep,
3737
gmock_dep,
3838
],
39+
cpp_args: [
40+
'-DORC_EXAMPLE_DIR=@0@'.format(meson.project_source_root() / 'examples'),
41+
'-DORC_BUILD_DIR=@0@'.format(meson.project_build_root()),
42+
],
3943
)
4044
test('tool-test', exc)

0 commit comments

Comments
 (0)