This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new c8d8af9  Integrate Googletest as Test Framework (#13)
c8d8af9 is described below

commit c8d8af964f21095f4346ac31d728fe5a79a35d08
Author: Junwang Zhao <[email protected]>
AuthorDate: Mon Jan 13 10:22:35 2025 +0800

    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]>
---
 CMakeLists.txt                 |  3 +++
 README.md                      |  5 ++++-
 ci/scripts/build_iceberg.sh    |  1 +
 src/iceberg/CMakeLists.txt     |  1 -
 test/CMakeLists.txt            | 10 ++++++++++
 test/{ => core}/CMakeLists.txt |  6 ++++++
 test/core/core_unittest.cc     | 27 +++++++++++++++++++++++++++
 7 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82c6045..fd2c737 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,11 +39,14 @@ option(ICEBERG_BUILD_TESTS "Build tests" ON)
 option(ICEBERG_ARROW "Build Arrow" ON)
 
 include(GNUInstallDirs)
+include(FetchContent)
+
 set(ICEBERG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
 set(ICEBERG_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
 set(ICEBERG_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
 set(ICEBERG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake")
 set(ICEBERG_INSTALL_DOCDIR "share/doc/${PROJECT_NAME}")
+set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")
 
 if(WIN32 AND NOT MINGW)
   set(MSVC_TOOLCHAIN TRUE)
diff --git a/README.md b/README.md
index 7009aee..baf46b4 100644
--- a/README.md
+++ b/README.md
@@ -28,12 +28,13 @@ C++ implementation of [Apache 
Iceberg™](https://iceberg.apache.org/).
 
 ## Build
 
-### Build and Install Core Libraries
+### Build, Run Test and Install Core Libraries
 
 ```bash
 cd iceberg-cpp
 cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install 
-DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON
 cmake --build build
+ctest --test-dir build --output-on-failure
 cmake --install build
 ```
 
@@ -44,6 +45,7 @@ cmake --install build
 ```bash
 cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install -DICEBERG_ARROW=ON
 cmake --build build
+ctest --test-dir build --output-on-failure
 cmake --install build
 ```
 
@@ -52,6 +54,7 @@ cmake --install build
 ```bash
 cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install 
-DCMAKE_PREFIX_PATH=/path/to/arrow -DICEBERG_ARROW=ON
 cmake --build build
+ctest --test-dir build --output-on-failure
 cmake --install build
 ```
 
diff --git a/ci/scripts/build_iceberg.sh b/ci/scripts/build_iceberg.sh
index b5f7481..d08e0b2 100755
--- a/ci/scripts/build_iceberg.sh
+++ b/ci/scripts/build_iceberg.sh
@@ -31,6 +31,7 @@ cmake \
     -DICEBERG_BUILD_SHARED=ON \
     ${source_dir}
 cmake --build . --target install
+ctest --output-on-failure -C Debug
 
 popd
 
diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt
index a84f3f9..4bebe4e 100644
--- a/src/iceberg/CMakeLists.txt
+++ b/src/iceberg/CMakeLists.txt
@@ -16,7 +16,6 @@
 # under the License.
 
 set(ICEBERG_SOURCES demo_table.cc)
-set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")
 
 add_iceberg_lib(iceberg
                 SOURCES
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 13a8339..c8c7fdf 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -14,3 +14,13 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+
+fetchcontent_declare(googletest
+                     GIT_REPOSITORY https://github.com/google/googletest.git
+                     GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # 
release-1.15.2
+                     FIND_PACKAGE_ARGS
+                     NAMES
+                     GTest)
+fetchcontent_makeavailable(googletest)
+
+add_subdirectory(core)
diff --git a/test/CMakeLists.txt b/test/core/CMakeLists.txt
similarity index 73%
copy from test/CMakeLists.txt
copy to test/core/CMakeLists.txt
index 13a8339..5512017 100644
--- a/test/CMakeLists.txt
+++ b/test/core/CMakeLists.txt
@@ -14,3 +14,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+
+add_executable(core_unittest)
+target_sources(core_unittest PRIVATE core_unittest.cc)
+target_link_libraries(core_unittest PRIVATE iceberg_static GTest::gtest_main)
+target_include_directories(core_unittest PRIVATE "${ICEBERG_INCLUDES}")
+add_test(NAME core_unittest COMMAND core_unittest)
diff --git a/test/core/core_unittest.cc b/test/core/core_unittest.cc
new file mode 100644
index 0000000..501f73d
--- /dev/null
+++ b/test/core/core_unittest.cc
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "iceberg/demo_table.h"
+
+TEST(TableTest, TestTableCons) {
+  auto table = iceberg::DemoTable();
+  EXPECT_EQ(table.print(), "DemoTable");
+}

Reply via email to