Skip to content

Commit 6451cb0

Browse files
author
shuxu.li
committed
refactor: Simplify test setup using a common CMake function
1 parent 0876746 commit 6451cb0

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

test/CMakeLists.txt

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ set(ICEBERG_TEST_RESOURCES "${CMAKE_SOURCE_DIR}/test/resources")
2828
configure_file("${CMAKE_SOURCE_DIR}/test/test_config.h.in"
2929
"${CMAKE_BINARY_DIR}/iceberg/test/test_config.h")
3030

31-
function(iceberg_add_test test_name)
31+
function(add_iceberg_test test_name)
32+
set(options USE_BUNDLE)
33+
set(oneValueArgs)
34+
set(multiValueArgs SOURCES)
3235
cmake_parse_arguments(ARG
33-
"USE_BUNDLE"
34-
"INCLUDE_DIR"
35-
"SRCS"
36+
"${options}"
37+
"${oneValueArgs}"
38+
"${multiValueArgs}"
3639
${ARGN})
3740

3841
add_executable(${test_name})
39-
if(ARG_INCLUDE_DIR)
40-
target_include_directories(${test_name} PRIVATE "${ARG_INCLUDE_DIR}")
41-
endif()
42+
target_include_directories(${test_name} PRIVATE "${CMAKE_BINARY_DIR}")
4243

43-
target_sources(${test_name} PRIVATE ${ARG_SRCS})
44+
target_sources(${test_name} PRIVATE ${ARG_SOURCES})
4445

4546
if(ARG_USE_BUNDLE)
4647
target_link_libraries(${test_name} PRIVATE iceberg_bundle_static GTest::gtest_main
@@ -53,8 +54,8 @@ function(iceberg_add_test test_name)
5354
add_test(NAME ${test_name} COMMAND ${test_name})
5455
endfunction()
5556

56-
iceberg_add_test(schema_test
57-
SRCS
57+
add_iceberg_test(schema_test
58+
SOURCES
5859
name_mapping_test.cc
5960
schema_test.cc
6061
schema_field_test.cc
@@ -67,58 +68,50 @@ iceberg_add_test(schema_test
6768
snapshot_test.cc
6869
schema_util_test.cc)
6970

70-
iceberg_add_test(table_test
71-
INCLUDE_DIR
72-
"${CMAKE_BINARY_DIR}"
73-
SRCS
71+
add_iceberg_test(table_test
72+
SOURCES
7473
test_common.cc
7574
json_internal_test.cc
7675
table_test.cc
7776
schema_json_test.cc)
7877

79-
iceberg_add_test(expression_test SRCS expression_test.cc literal_test.cc)
78+
add_iceberg_test(expression_test SOURCES expression_test.cc literal_test.cc)
8079

81-
iceberg_add_test(json_serde_test
82-
INCLUDE_DIR
83-
"${CMAKE_BINARY_DIR}"
84-
SRCS
80+
add_iceberg_test(json_serde_test
81+
SOURCES
8582
test_common.cc
8683
json_internal_test.cc
8784
metadata_serde_test.cc
8885
schema_json_test.cc)
8986

90-
iceberg_add_test(util_test
91-
SRCS
87+
add_iceberg_test(util_test
88+
SOURCES
9289
formatter_test.cc
9390
config_test.cc
9491
visit_type_test.cc)
9592

9693
if(ICEBERG_BUILD_BUNDLE)
97-
iceberg_add_test(avro_test
94+
add_iceberg_test(avro_test
9895
USE_BUNDLE
99-
INCLUDE_DIR
100-
"${CMAKE_BINARY_DIR}"
101-
SRCS
96+
SOURCES
10297
avro_data_test.cc
10398
avro_test.cc
10499
avro_schema_test.cc
105100
avro_stream_test.cc
106101
manifest_list_reader_test.cc
107102
test_common.cc)
108103

109-
iceberg_add_test(arrow_test
104+
add_iceberg_test(arrow_test
110105
USE_BUNDLE
111-
SRCS
106+
SOURCES
112107
arrow_test.cc
113108
arrow_fs_file_io_test.cc
114109
metadata_io_test.cc
115110
gzip_decompress_test.cc)
116111

117-
iceberg_add_test(catalog_test
112+
add_iceberg_test(catalog_test
118113
USE_BUNDLE
119-
INCLUDE_DIR
120-
"${CMAKE_BINARY_DIR}"
121-
SRCS
114+
SOURCES
122115
test_common.cc
123116
in_memory_catalog_test.cc)
124117
endif()

0 commit comments

Comments
 (0)