Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# SplashKit Development

## macOS
Expand All @@ -20,31 +21,79 @@
git clone --recursive -j2 https://github.com/<username>/splashkit-core.git
```

3. Build the test project:
3. Initialise submodules if they weren't included during clone:

- In a terminal application, go into the cloned directory of your SplashKit
fork, and type:
```sh
git submodule update --init --recursive
```

4. Build the test project:

- In a terminal application, go into the cloned directory of your SplashKit fork, and type:

```sh
cd projects/cmake
cmake .
make
```

4. Run the test program by executing
- For Apple Silicon (arm64) Macs, you may need to specify the architecture:

```sh
cd projects/cmake
# Clean any previous build files if you encounter errors
./clean.sh
cmake . -DCMAKE_OSX_ARCHITECTURES=arm64
make
```

5. Run the test program by executing:

```sh
cd ../../bin
./sktest
```

5. Add features to code in
6. Generate Code Coverage Report (requires lcov)

SplashKit includes a CMake preset for generating code coverage reports using lcov. To use it:

```sh
# Install lcov if you don't have it
brew install lcov

# Navigate to the cmake directory from the repository root
cd projects/cmake

# Configure the project with coverage flags
cmake --preset macOSCoverage -S .

# Build the project
cmake --build --preset macOSCoverage

# Run the tests to generate coverage data
cd ../../bin && ./skunit_tests

# Generate the coverage report
cd ..
lcov --capture --directory projects/cmake/build/macOSCoverage --output-file coverage.info --ignore-errors inconsistent,unsupported,format,count --include "/coresdk/src/coresdk/" --include "/coresdk/src/backend/"

# Create an HTML report
genhtml coverage.info --output-directory coverage_report --ignore-errors inconsistent,corrupt,unsupported,category

# Open the report
open coverage_report/index.html
```

The report will show which parts of your code are covered by tests and which parts are not covered. This helps identify areas that need additional testing.

7. Add features to code in:

```sh
./coresdk
```

6. Add test code into `coresdk/src/test`. Now you should be good to go.
8. Add test code into `coresdk/src/test`. Now you should be good to go.

## Linux

Expand Down
63 changes: 62 additions & 1 deletion projects/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ set(SK_BIN "${CMAKE_CURRENT_SOURCE_DIR}/../../bin")
# FLAGS
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")

# Option to use GCOV for coverage when compiling and linking
option(USE_COVERAGE "Enable coverage during the build" OFF)
if(USE_COVERAGE)
add_compile_options(--coverage)
add_link_options(--coverage)
endif()

# Includes for CTest/Catch2 integration
include(CTest)
include("${CMAKE_CURRENT_SOURCE_DIR}/catch/Catch.cmake")
Expand Down Expand Up @@ -325,4 +332,58 @@ catch_discover_tests(skunit_tests)
#### END sktest EXECUTABLE ####

install(TARGETS SplashKitBackend DESTINATION lib)
install(FILES ${INCLUDE_FILES} DESTINATION include/SplashKitBackend)
install(FILES ${INCLUDE_FILES} DESTINATION include/SplashKitBackend)

# Coverage collection with LCOV
# Get absolute path to SK_SRC so we can pass it to LCOV
# and collect coverage only for src files
get_filename_component(SRC_ABS ${SK_SRC} ABSOLUTE)
message(SRC_ABS="${SRC_ABS}")

if(USE_COVERAGE)
if(APPLE OR MSYS)
find_program(GCOVR gcovr REQUIRED)
else()
find_program(LCOV lcov REQUIRED)
set(LCOV_BASE lcov-base.info)
set(LCOV_TEST lcov-test.info)
set(LCOV_LOG lcov.log)
set(LCOV_ERR lcov.err)
endif()
set(LCOV_TOTAL lcov.info)
endif()

# lcov coverage targets
# Collect baseline coverage before running tests
add_custom_target(lcov-init-coverage
COMMENT "Collecting initial coverage with lcov"
COMMAND lcov --capture --initial --directory ${CMAKE_CURRENT_BINARY_DIR} --include "'${SRC_ABS}*'"
--output-file ${LCOV_BASE} 2>${LCOV_ERR} >${LCOV_LOG}
)
add_dependencies(lcov-init-coverage lcov-reset-coverage)

add_custom_target(lcov-reset-coverage
COMMENT "Reset all coverage counters to zero with lcov"
COMMAND lcov --quiet --zerocounters --directory ${CMAKE_CURRENT_BINARY_DIR}
--output-file ${LCOV_BASE}
COMMAND lcov --quiet --zerocounters --directory ${CMAKE_CURRENT_BINARY_DIR}
--output-file ${LCOV_TEST}
COMMAND lcov --quiet --zerocounters --directory ${CMAKE_CURRENT_BINARY_DIR}
--output-file ${LCOV_TOTAL}
)

# Collect post-test coverage data
add_custom_target(lcov-capture-coverage
COMMENT "Capture coverage data with lcov"
DEPENDS ${LCOV_BASE}
COMMAND lcov --capture --directory ${CMAKE_CURRENT_BINARY_DIR} --output-file ${LCOV_TEST} --include "'${SRC_ABS}*'"
2>${LCOV_ERR} >${LCOV_LOG}
COMMAND lcov --add-tracefile ${LCOV_BASE} --add-tracefile ${LCOV_TEST} --output-file ${LCOV_TOTAL}
>>${LCOV_LOG}
)

# gcovr post-test coverage target
add_custom_target(gcovr-capture-coverage
COMMENT "Capture coverage data with gcovr"
COMMAND gcovr --root ../../.. --lcov ${LCOV_TOTAL} --filter ".*/coresdk/src/.*"
)
24 changes: 22 additions & 2 deletions projects/cmake/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"USE_COVERAGE": "OFF"
}
},
{
"name": "LinuxCoverage",
"displayName": "Linux with coverage",
"description": "Linux gcc g++",
"inherits": "Linux",
"cacheVariables": {
"USE_COVERAGE": "ON"
}
},
{
Expand All @@ -33,7 +43,17 @@
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"USE_COVERAGE": "OFF"
}
},
{
"name": "macOSCoverage",
"displayName": "macOS with coverage",
"description": "macOS clang",
"inherits": "macOS",
"cacheVariables": {
"USE_COVERAGE": "ON"
}
}
]
Expand Down
Loading