Skip to content

Commit c8d8af9

Browse files
authored
Integrate Googletest as Test Framework (#13)
Per the discussion in #12, we agreed on using GTest as iceberg-cpp's unit test framework. Signed-off-by: Junwang Zhao <[email protected]>
1 parent 4962852 commit c8d8af9

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ option(ICEBERG_BUILD_TESTS "Build tests" ON)
3939
option(ICEBERG_ARROW "Build Arrow" ON)
4040

4141
include(GNUInstallDirs)
42+
include(FetchContent)
43+
4244
set(ICEBERG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
4345
set(ICEBERG_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
4446
set(ICEBERG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
4547
set(ICEBERG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake")
4648
set(ICEBERG_INSTALL_DOCDIR "share/doc/${PROJECT_NAME}")
49+
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")
4750

4851
if(WIN32 AND NOT MINGW)
4952
set(MSVC_TOOLCHAIN TRUE)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ C++ implementation of [Apache Iceberg™](https://iceberg.apache.org/).
2828

2929
## Build
3030

31-
### Build and Install Core Libraries
31+
### Build, Run Test and Install Core Libraries
3232

3333
```bash
3434
cd iceberg-cpp
3535
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON
3636
cmake --build build
37+
ctest --test-dir build --output-on-failure
3738
cmake --install build
3839
```
3940

@@ -44,6 +45,7 @@ cmake --install build
4445
```bash
4546
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_ARROW=ON
4647
cmake --build build
48+
ctest --test-dir build --output-on-failure
4749
cmake --install build
4850
```
4951

@@ -52,6 +54,7 @@ cmake --install build
5254
```bash
5355
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON
5456
cmake --build build
57+
ctest --test-dir build --output-on-failure
5558
cmake --install build
5659
```
5760

ci/scripts/build_iceberg.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cmake \
3131
-DICEBERG_BUILD_SHARED=ON \
3232
${source_dir}
3333
cmake --build . --target install
34+
ctest --output-on-failure -C Debug
3435

3536
popd
3637

src/iceberg/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# under the License.
1717

1818
set(ICEBERG_SOURCES demo_table.cc)
19-
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")
2019

2120
add_iceberg_lib(iceberg
2221
SOURCES

test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
18+
fetchcontent_declare(googletest
19+
GIT_REPOSITORY https://github.com/google/googletest.git
20+
GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2
21+
FIND_PACKAGE_ARGS
22+
NAMES
23+
GTest)
24+
fetchcontent_makeavailable(googletest)
25+
26+
add_subdirectory(core)

test/core/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
add_executable(core_unittest)
19+
target_sources(core_unittest PRIVATE core_unittest.cc)
20+
target_link_libraries(core_unittest PRIVATE iceberg_static GTest::gtest_main)
21+
target_include_directories(core_unittest PRIVATE "${ICEBERG_INCLUDES}")
22+
add_test(NAME core_unittest COMMAND core_unittest)

test/core/core_unittest.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include <gtest/gtest.h>
21+
22+
#include "iceberg/demo_table.h"
23+
24+
TEST(TableTest, TestTableCons) {
25+
auto table = iceberg::DemoTable();
26+
EXPECT_EQ(table.print(), "DemoTable");
27+
}

0 commit comments

Comments
 (0)