Tooling and Testing
Tooling and Testing
Compilation, warnings, sanitizers, formatting, static analysis, and test habits.
Recommended compiler flags
GCC / Clang
-std=c++23 -Wall -Wextra -Wpedantic -Wconversion -O2
Debug builds
-g -O0 -fsanitize=address,undefined
- CMake: de facto standard build system
- Ninja: fast backend often used with CMake
compile_commands.json: useful for IDEs and linters
clang-format
clang-tidy
- Include-what-you-use
Testing patterns
- Arrange, act, assert
- Prefer deterministic tests
- Test public behavior, not private implementation details
- Add regression tests for every bug fix
Helpful libraries
- Catch2
- GoogleTest
- doctest
Best-practice reminders
- Turn warnings into errors in CI when practical.
- Keep debug and release configurations separate.
- Use sanitizers early; they catch real bugs fast.
Useful clang-tidy checks
modernize-*
performance-*
bugprone-*
readability-*
Start broad, then suppress intentionally noisy rules in project configuration.
CMake workflow essentials
cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failure
- Keep builds out of the source tree.
- Generate
compile_commands.json for language tools.
- Let CI run formatting, static analysis, tests, and sanitizers separately.
Debugging checklist
- Reproduce with the smallest failing input.
- Turn on sanitizers before chasing complex theories.
- Inspect optimized-vs-debug differences only after you have a clear reproducer.