Tooling and Testing
Tooling and Testing
Compilation, warnings, sanitizers, formatting, static analysis, and test habits.
Tooling and Testing
Compilation, warnings, sanitizers, formatting, static analysis, and test habits.
-std=c++23 -Wall -Wextra -Wpedantic -Wconversion -O2
-g -O0 -fsanitize=address,undefined
compile_commands.json: useful for IDEs and lintersclang-formatclang-tidyclang-format -i src/main.cpp
clang-tidy src/main.cpp -- -std=c++23
Formatting keeps style consistent. Linting highlights suspicious patterns before they become bugs or review comments.
TEST(parse_port, rejects_empty_input) {
auto result = parse_port("");
ASSERT_FALSE(result.has_value());
}
g++ -std=c++23 -Wall -Wextra -Wpedantic -g -fsanitize=address,undefined src/main.cpp -o build/app
./build/app
clang-tidy src/main.cpp -- -std=c++23
ctest --test-dir build --output-on-failure
This sequence covers compilation, runtime checks, static analysis, and tests without requiring a huge build system.
clang-tidy checksmodernize-*performance-*bugprone-*readability-*Start broad, then suppress intentionally noisy rules in project configuration.
cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failure
compile_commands.json for language tools.clang-tidy: structural and style-oriented checksEven small projects benefit from one automated check that builds, runs tests, and fails on warnings or sanitizer findings. Catching issues before merge is much cheaper than debugging them later.
g++ -std=c++23 -Wall -Wextra -Wpedantic -g src/main.cpp -o build/app
Add warnings, debug info, and then a sanitizer-enabled variant. This gives you a minimal build matrix without introducing a full build system yet.
g++ -std=c++23 -Wall -Wextra -Wpedantic -g -fsanitize=address src/main.cpp -o build/app-check