Skip to content

Commit 6c3c000

Browse files
authored
Merge pull request #41 from diffCheckOrg/test_suite
test suite framework 🧪
2 parents b281a67 + 159d63e commit 6c3c000

33 files changed

+645
-152
lines changed

.github/workflows/cpp-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- name: Cmake Configure
2222
run: |
23-
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=OFF
23+
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=OFF -DBUILD_TESTS=OFF -DRUN_TESTS=OFF
2424
2525
- name: CMake Build
26-
run: ${{github.workspace}}/cmake/build.bat
26+
run: cmake --build build --config Release

.github/workflows/pypi-build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ jobs:
3232

3333
- name: Cmake Configure
3434
run: |
35-
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON
35+
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON -DBUILD_TESTS=OFF -DRUN_TESTS=OFF
3636
- name: CMake Build
37-
run: ${{github.workspace}}/cmake/build.bat
37+
run: cmake --build build --config Release
38+
39+
#FIXME: here we are probably missing to copy the dlls and pyds before building the wheel
3840

3941
- name: Build wheel
4042
run: |

.github/workflows/test-pass.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "test-pass"
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
10+
jobs:
11+
windows:
12+
runs-on: windows-latest
13+
14+
env:
15+
BUILD_TYPE: Release
16+
VCPKG_FILE: c:/vcpkg/scripts/buildsystems/vcpkg.cmake
17+
DF_TEST_DATA_DIR: ${{ github.workspace }}/tests/test_data
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
lfs: true # enable lfs support
24+
25+
- name: Setup conda environment
26+
uses: conda-incubator/setup-miniconda@v2
27+
with:
28+
auto-update-conda: true
29+
python-version: 3.9.1
30+
31+
- name: Create diff_check conda environment
32+
run: conda env create -f environment.yml
33+
34+
- name: Activate diff_check conda environment
35+
run: conda activate diff_check
36+
37+
- name: Verify Python version
38+
run: conda run --name diff_check --no-capture-output python --version
39+
40+
- name: Cmake Configure
41+
run: |
42+
conda run --name diff_check --no-capture-output cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON -DBUILD_TESTS=ON -DRUN_TESTS=OFF
43+
44+
- name: CMake Build
45+
run: conda run --name diff_check --no-capture-output cmake --build build --config Release
46+
47+
- name: Copying the dlls for python tests and c++ tests
48+
run: |
49+
copy ${{github.workspace}}/build/bin/Release/diffCheck.dll ${{github.workspace}}/build/df_tests/Release
50+
copy ${{github.workspace}}/build/bin/Release/Open3D.dll ${{github.workspace}}/build/df_tests/Release
51+
52+
copy ${{github.workspace}}/build/bin/Release/diffCheck.dll ${{github.workspace}}/tests/integration_tests/pybinds_tests
53+
copy ${{github.workspace}}/build/bin/Release/Open3D.dll ${{github.workspace}}/tests/integration_tests/pybinds_tests
54+
copy ${{github.workspace}}/build/Release/*.pyd ${{github.workspace}}/tests/integration_tests/pybinds_tests
55+
56+
- name: Run tests with cmake
57+
run: |
58+
conda run --name diff_check ctest --test-dir build --output-on-failure -C Release --verbose

CMakeLists.txt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
77
include(external_tools)
88
include(options)
99

10+
# disabling warnings
11+
if (MSVC)
12+
add_compile_options(/wd4003)
13+
endif()
14+
1015
# check that the -DCMAKE_BUILD_TYPE is set
1116
if(NOT CMAKE_BUILD_TYPE)
1217
message(STATUS "Setting build type to 'Release' as none was specified.")
@@ -147,7 +152,7 @@ if (BUILD_PYTHON_MODULE)
147152

148153
pybind11_add_module(${PYBINDMODULE_NAME} src/diffCheckBindings.cc)
149154

150-
target_link_libraries(${PYBINDMODULE_NAME} PRIVATE ${SHARED_LIB_NAME})
155+
target_link_libraries(${PYBINDMODULE_NAME} PUBLIC ${SHARED_LIB_NAME})
151156
target_include_directories(${PYBINDMODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
152157

153158
# copy the pyd file to the pypi directory
@@ -157,29 +162,12 @@ if (BUILD_PYTHON_MODULE)
157162
${PYPI_DIR}
158163
)
159164
copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
160-
161165
endif()
162166

163167
#--------------------------------------------------------------------------
164168
# Tests
165169
#--------------------------------------------------------------------------
166-
include(CTest)
167-
enable_testing()
168-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest)
169-
set(TESTS_OUT_DIR ${CMAKE_BINARY_DIR}/df_tests/)
170-
set(TEST_OUT_DIR_BINARY ${TESTS_OUT_DIR}/${CMAKE_BUILD_TYPE})
171-
172-
# add new test suites .cc here
173-
set(UNIT_TESTS df_test_suites)
174-
add_executable(${UNIT_TESTS}
175-
tests/unit_tests/DFPointCloudTest.cc
176-
tests/entryTest.cc
177-
)
178-
set_target_properties(${UNIT_TESTS} PROPERTIES
179-
RUNTIME_OUTPUT_DIRECTORY ${TESTS_OUT_DIR}
180-
)
181-
target_link_libraries(${UNIT_TESTS} gtest gtest_main)
182-
target_link_libraries(${UNIT_TESTS} ${SHARED_LIB_NAME})
170+
if(BUILD_TESTS)
171+
include(tests)
172+
endif()
183173

184-
add_test(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS})
185-
copy_dlls(${TEST_OUT_DIR_BINARY} ${UNIT_TESTS})

CONTRIBUTING.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,48 @@ dfVisualizerPtr->Run();
319319
```
320320

321321

322-
### CTesting (TO BE UPDATED)
323-
Tests in df are all `.cc` files added to the `tests` source files, all the data needs to be contained in `tests/test_data`. Finally add your `.cc` files in the cmake:
322+
### Test suite
323+
In df we use `CTest` as a test framework managed by Cmake in the file `cmake/tests.cmake` to run c++ tests with `GoogleTest` and for python in `PyTest`.
324324

325-
https://github.com/diffCheckOrg/diffCheck/blob/efb10e0b5685a1ef1537d0309388f642075d3244/CMakeLists.txt#L170-L173
326-
327-
To run the tests from terminal
328-
```
329-
ctest --test-dir .\build\ -C Release -V
325+
Tests are in the `tests` folder:
326+
```terminal
327+
F:\DIFFCHECK\TESTS
328+
│ allCppTests.cc
329+
330+
├───integration_tests <-- mainly python interfaces
331+
│ ├───ghcomponents_tests <-- relative to gh components
332+
│ │ .gitkeep
333+
│ │
334+
│ ├───package_tests <-- relative to the pypi package
335+
│ │ .gitkeep
336+
│ │
337+
│ └───pybinds_tests <-- strictly pybinding
338+
│ │ diffCheck.dll
339+
│ │ diffcheck_bindings.cp39-win_amd64.pyd
340+
│ │ Open3D.dll
341+
│ │ test_pybind_pyver.py
342+
│ │ test_pybind_units.py
343+
344+
├───test_data <-- here is where we put some .ply data
345+
│ roof_quarter.ply
346+
347+
└───unit_tests <-- c++ backend, one for each header
348+
DFLog.cc
349+
DFPointCloudTest.cc
330350
```
331-
or
351+
352+
To run the tests, you can use the following commands:
353+
```terminal
354+
cmake -S . -B build -A x64 -DBUILD_PYTHON_MODULE=ON -DBUILD_TESTS=ON -DRUN_TESTS=ON
355+
cmake --build build --config Release
332356
```
333-
.\build\df_tests\<config>\df_tests.exe
334-
```
357+
358+
## Write C++ tests
359+
To write a test, you need to create a new file in the `tests/unit_tests` folder. Next add your file in the executable `${CPP_UNIT_TESTS}` in the `cmake/tests.cmake`.
360+
e.g.:
361+
https://github.com/diffCheckOrg/diffCheck/blob/e080a93cdd73d96efb0686f80bf13730e0b8efa3/cmake/tests.cmake#L13-L17
362+
363+
## Write Python tests
364+
To write a test, you need to create a new file in the `tests/integration_tests` folder. Write a new `.py` test file and add it in the `cmake/tests.cmake` in the `add_test` function.
365+
e.g.:
366+
https://github.com/diffCheckOrg/diffCheck/blob/e080a93cdd73d96efb0686f80bf13730e0b8efa3/cmake/tests.cmake#L45-L48

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
</p>
44
<p align="center">
55
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/cpp-build.yml/badge.svg">
6+
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/test-pass.yml/badge.svg">
67
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/gh-build.yml/badge.svg">
78
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/pypi-build.yml/badge.svg">
89
<img href="https://pypi.org/project/diffCheck/" src="https://img.shields.io/pypi/v/diffCheck">

ScreenCamera_2024-06-30-00-00-53.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

ScreenCamera_2024-06-30-11-58-46.json

Lines changed: 0 additions & 41 deletions
This file was deleted.
-87.4 KB
Binary file not shown.
-40.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)