Testing#

Clang Format#

Source code is tested against the .clang-format file for linting errors. The workflow file responsible for clang format testing is .github/workflows/cpp-clang-format-lint.yml.

Test clang-format locally.
find ./ -iname *.cpp -o -iname *.h -iname *.m -iname *.mm | xargs clang-format -i

Sphinx#

Sunshine uses Sphinx for documentation building. Sphinx, along with other required python dependencies are included in the ./docs/requirements.txt file. Python is required to build sphinx docs. Installation and setup of python will not be covered here.

Doxygen is used to generate the XML files required by Sphinx. Doxygen can be obtained from Doxygen downloads. Ensure that the doxygen executable is in your path.

See also

Sphinx is configured to use the graphviz extension. To obtain the dot executable from the Graphviz library, see the library’s downloads section.

The config file for Sphinx is docs/source/conf.py. This is already included in the repo and should not be modified.

The config file for Doxygen is docs/Doxyfile. This is already included in the repo and should not be modified.

Test with Sphinx
cd docs
make html

Alternatively

cd docs
sphinx-build -b html source build
Lint with rstcheck
rstcheck -r .
Check formatting with rstfmt
rstfmt --check --diff -w 120 .
Format inplace with rstfmt
rstfmt -w 120 .

Unit Testing#

Sunshine uses Google Test for unit testing. Google Test is included in the repo as a submodule. The test sources are located in the ./tests directory.

The tests need to be compiled into an executable, and then run. The tests are built using the normal build process, but can be disabled by setting the BUILD_TESTS CMake option to OFF.

To run the tests, execute the following command from the build directory:

pushd tests
./test_sunshine
popd
pushd tests
./test_sunshine
popd
pushd tests
test_sunshine.exe
popd

To see all available options, run the tests with the –help option.

pushd tests
./test_sunshine --help
popd
pushd tests
./test_sunshine --help
popd
pushd tests
test_sunshine.exe --help
popd

Some tests rely on Python to run. CMake will search for Python and enable the docs tests if it is found, otherwise cmake will fail. You can manually disable the tests by setting the TESTS_ENABLE_PYTHON_TESTS CMake option to OFF.

Tip

See the googletest FAQ for more information on how to use Google Test.

We use gcovr to generate code coverage reports, and Codecov to analyze the reports for all PRs and commits.

Codecov will fail a PR if the total coverage is reduced too much, or if not enough of the diff is covered by tests. In some cases, the code cannot be covered when running the tests inside of GitHub runners. For example, any test that needs access to the GPU will not be able to run. In these cases, the coverage can be omitted by adding comments to the code. See the gcovr documentation for more information.

Even if your changes cannot be covered in the CI, we still encourage you to write the tests for them. This will allow maintainers to run the tests locally.