Tooling and Testing

Tooling and Testing

Compilation, warnings, sanitizers, formatting, static analysis, and test habits.

Tooling and Testing

GCC / Clang

-std=c++23 -Wall -Wextra -Wpedantic -Wconversion -O2

Debug builds

-g -O0 -fsanitize=address,undefined

Build tools

Formatting and linting

Fast workflow example

clang-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.

Testing patterns

Tiny Arrange-Act-Assert example

TEST(parse_port, rejects_empty_input) {
	auto result = parse_port("");
	ASSERT_FALSE(result.has_value());
}

Helpful libraries

Best-practice reminders

End-to-end local quality loop

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.

Useful clang-tidy checks

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

Practical tool selection

Debugging checklist

CI habit worth adopting early

Even 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.

Example in practice

g++ -std=c++23 -Wall -Wextra -Wpedantic -g src/main.cpp -o build/app

Try this variation

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