Skip to content

Commit

Permalink
Use GTest to structure unit tests.
Browse files Browse the repository at this point in the history
Organize tests into separate test functions and test cases. This
will make it easier to understand and maintain the test suite.
  • Loading branch information
buddly27 committed Feb 9, 2025
1 parent 8acae34 commit 6ff0a8e
Show file tree
Hide file tree
Showing 34 changed files with 899 additions and 781 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Create Build Environment
run: |
sudo apt update
sudo apt install -y ninja-build
sudo apt install -y libgtest-dev ninja-build
cmake -E make_directory ${{github.workspace}}/build
- name: Configure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Create Build Environment
run: |
brew install ninja
brew install ninja googletest
cmake -E make_directory ${{github.workspace}}/build
- name: Configure
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ env:
CMAKE_BUILD_TYPE: Release
CMAKE_GENERATOR: Visual Studio 17 2022
CMAKE_GENERATOR_PLATFORM: x64
CMAKE_TOOLCHAIN_FILE: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
CTEST_OUTPUT_ON_FAILURE: True
VCPKG_DEFAULT_TRIPLET: x64-windows

# Avoid the just-in-time debugger where possible when running tests.
ARCH_AVOID_JIT: True
Expand All @@ -28,7 +30,9 @@ jobs:
- uses: actions/checkout@v4

- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
run: |
vcpkg install gtest
cmake -E make_directory ${{github.workspace}}/build
- name: Configure
working-directory: ${{github.workspace}}/build
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ add_subdirectory(src)

# Build and setup tests if required.
if (BUILD_TESTS)
find_package(GTest REQUIRED)
include(GoogleTest)

enable_testing()
add_subdirectory(test)
endif()
Expand Down
7 changes: 6 additions & 1 deletion doc/sphinx/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Glossary

.. seealso:: https://doxygen.nl/

GTest
Google Test is a testing and mocking framework for C++.

.. seealso:: http://google.github.io/googletest/

reStructuredText
Lightweight markup language.

Expand All @@ -31,4 +36,4 @@ Glossary
Python documentation generator which converts :term:`reStructuredText`
files into HTML and other formats.

.. seealso:: https://www.sphinx-doc.org/
.. seealso:: https://www.sphinx-doc.org/
5 changes: 4 additions & 1 deletion doc/sphinx/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Then build the documentation as follows::
Running tests
=============

Ensure that :term:`GTest` is installed.

Once the library and all tests are built, you can run the tests using
:term:`Ctest` within the build folder as follows::

Expand All @@ -100,7 +102,8 @@ Once the library and all tests are built, you can run the tests using
You can increase the verbosity and filter in one or several tests as follows::

ctest -VV
ctest -R testArchDemangle -VV
ctest -R DemangleTest.Bool -VV
ctest -R DemangleTest.* -VV

.. note::

Expand Down
147 changes: 2 additions & 145 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,145 +1,2 @@
add_library(archTest
testArchAbi.cpp
testArchUtil.cpp
)

target_include_directories(archTest
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

target_link_libraries(archTest
PUBLIC
arch
)

if (WIN32)
# Expand 'add_test' to copy dependent DLLs in the same folder after
# building target to ensure that tests can run properly on Windows.
macro(add_test NAME)
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
$<TARGET_RUNTIME_DLLS:${NAME}>
$<TARGET_FILE_DIR:${NAME}>
COMMAND_EXPAND_LISTS
)
_add_test(${NAME} ${ARGV})
endmacro()
endif()

add_library(testArchAbiPlugin testArchAbiPlugin.cpp)

target_link_libraries(testArchAbiPlugin
PUBLIC
arch
archTest
)

add_executable(testArchAbi testArchAbi.cpp)
target_link_libraries(testArchAbi
PRIVATE
arch
testArchAbiPlugin
)
add_test(testArchAbi testArchAbi)

add_executable(testArchPRead testArchPRead.cpp)
target_link_libraries(testArchPRead
PRIVATE
arch
)

add_executable(testArchAttributes testAttributes.cpp)
target_link_libraries(testArchAttributes
PRIVATE
arch
)
add_test(testArchAttributes testArchAttributes)

add_executable(testArchDemangle testDemangle.cpp)
target_link_libraries(testArchDemangle
PRIVATE
arch
)
add_test(testArchDemangle testArchDemangle)

add_executable(testArchErrno testErrno.cpp)
target_link_libraries(testArchErrno
PRIVATE
arch
)
add_test(testArchErrno testArchErrno)

add_executable(testArchError testError.cpp)
target_link_libraries(testArchError
PRIVATE
arch
archTest
)
add_test(testArchError testArchError)

add_executable(testArchFileSystem testFileSystem.cpp)
target_link_libraries(testArchFileSystem
PRIVATE
arch
)
add_test(testArchFileSystem testArchFileSystem)

add_executable(testArchFunction testFunction.cpp)
target_link_libraries(testArchFunction
PRIVATE
arch
)
add_test(testArchFunction testArchFunction)

add_executable(testArchMath testMath.cpp)
target_link_libraries(testArchMath
PRIVATE
arch
)
add_test(testArchMath testArchMath)

add_executable(testArchStackTrace testStackTrace.cpp)
target_link_libraries(testArchStackTrace
PRIVATE
arch
archTest
)
add_test(testArchStackTrace testArchStackTrace)

add_executable(testArchSymbols testSymbols.cpp)
target_link_libraries(testArchSymbols
PRIVATE
arch
)
add_test(testArchSymbols testArchSymbols)

add_executable(testArchSystemInfo testSystemInfo.cpp)
target_link_libraries(testArchSystemInfo
PRIVATE
arch
)
add_test(testArchSystemInfo testArchSystemInfo)

add_executable(testArchThreads testThreads.cpp)
target_link_libraries(testArchThreads
PRIVATE
arch
)
add_test(testArchThreads testArchThreads)

add_executable(testArchTiming testTiming.cpp)
target_link_libraries(testArchTiming
PRIVATE
arch
)
add_test(testArchTiming testArchTiming)

add_executable(testArchVsnprintf testVsnprintf.cpp)
target_link_libraries(testArchVsnprintf
PRIVATE
arch
)
add_test(testArchVsnprintf testArchVsnprintf)
add_subdirectory(utility)
add_subdirectory(unit)
67 changes: 0 additions & 67 deletions test/testArchAbi.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions test/testArchPRead.cpp

This file was deleted.

Loading

0 comments on commit 6ff0a8e

Please sign in to comment.