Skip to content

Commit d3cee92

Browse files
committed
Integrate Test Framework
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 158d509 commit d3cee92

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ include(BuildUtils)
4343
include(ExternalProject)
4444
include(FindPackageHandleStandardArgs)
4545
include(GNUInstallDirs)
46+
include(FetchContent)
4647

4748
set(ICEBERG_API_DIR "${CMAKE_SOURCE_DIR}/api")
4849
set(ICEBERG_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ 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
mkdir build && cd build
3636
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/iceberg -DICEBERG_BUILD_STATIC=ON -DICEBERG_BUILD_SHARED=ON
3737
cmake --build .
38+
ctest --build .
3839
cmake --install .
3940
```
4041

cmake_modules/FindGTestAlt.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
find_package(GTest)
19+
20+
if(GTest_FOUND)
21+
return()
22+
endif()
23+
24+
fetchcontent_declare(googletest
25+
GIT_REPOSITORY https://github.com/google/googletest.git
26+
GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2
27+
)
28+
fetchcontent_makeavailable(googletest)

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
18+
include(FindGTestAlt)
19+
20+
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_gtest)
19+
target_sources(core_gtest PRIVATE core_gtest.cc)
20+
target_link_libraries(core_gtest PRIVATE iceberg_core_static GTest::gtest_main)
21+
target_include_directories(core_gtest PRIVATE "${ICEBERG_API_DIR}")
22+
add_test(NAME core_gtest COMMAND core_gtest)

test/core/core_gtest.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/table.h"
23+
24+
TEST(TableTest, TestTableCons) {
25+
auto table = iceberg::Table::create();
26+
EXPECT_EQ(table->print(), "DemoTable");
27+
}

0 commit comments

Comments
 (0)