Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebastianbach/cpp-check-suite
Checks for C++ code.
https://github.com/sebastianbach/cpp-check-suite
asan clang-format clang-tidy coverage cpp cppcheck ubsan valgrind
Last synced: about 1 month ago
JSON representation
Checks for C++ code.
- Host: GitHub
- URL: https://github.com/sebastianbach/cpp-check-suite
- Owner: SebastianBach
- License: mit
- Created: 2024-05-30T12:33:29.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-30T13:25:15.000Z (7 months ago)
- Last Synced: 2024-05-31T14:50:55.124Z (7 months ago)
- Topics: asan, clang-format, clang-tidy, coverage, cpp, cppcheck, ubsan, valgrind
- Language: CMake
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Sample project showing how to use sanitizers and analyzers to check C++ code.
# Install Dependencies
Example platform is Linux/Ubuntu using GCC:
```shell
sudo apt-get updatesudo apt-get install build-essential cmake cppcheck clang-format clang-tidy valgrind
pip install gcovr
```# Checks
## Compiler Warnings
Enable extensive compiler warnings-as-errors with the custom **cmake** option ```ENABLE_WARNINGS```.
```shell
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_WARNINGS=ON ..
cmake --build . -j
```## Cppcheck
Use **cppcheck** with the ``compile_commands.json`` file generated by **cmake**.
```shell
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
cppcheck --project=compile_commands.json --cppcheck-build-dir=./temp/cppcheck --error-exitcode=1 --enable=all
```## clang-format
Use **[clang-format](https://clang.llvm.org/docs/ClangFormat.html)** to check the code style.
```shell
clang-format --dry-run -Werror --style=file src/bad_code.cpp
```## clang-tidy
Use **[clang-tidy](https://clang.llvm.org/extra/clang-tidy/)** to analyze code patterns.
Clang tidy can be used by **cmake** via [CXX_CLANG_TIDY](https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html) enabled with:
```shell
cmake -DENABLE_CLANG_TIDY=ON ..
cmake --build .
```## ASAN (AddressSanitizer)
Use the **[AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html)** to check for memory issues at runtime.
```shell
cmake -DENABLE_ASAN=ON ..
cmake --build .
ctest --output-on-failure
```## UBSAN (UndefinedBehaviorSanitizer)
Use the **[UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html)** to check for cases of [undefined behaviour](https://en.cppreference.com/w/cpp/language/ub) at runtime.
Enable and run with:
```shell
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_UBSAN=ON ..
cmake --build . -j
ctest --output-on-failure
```## Valgrind
Use **[Valgrind](https://valgrind.org/)** to check for memory issues at runtime.
```shell
cmake -DUSE_VALGRIND=ON ..
cmake --build .
ctest -T memcheck --output-on-failure
```## Coverage
Create a coverage report using **[gcovr](https://gcovr.com/en/stable/)** to see how much of the code is executed during tests.
```shell
cmake -DENABLE_COVERAGE=ON ..
cmake --build . -j
ctestcd ..
gcovr -r . --html --html-details -o build/coverage/coverage.html
```