| 12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/env bash
- # Standalone C++ tests for pure logic that needs no running service.
- #
- # Compiled and run inside the build image, so the dependencies are the ones the
- # real build uses and nothing has to be installed on the host - which matters on
- # zeus, where the host cannot build the project at all.
- set -uo pipefail
- cd "$(dirname "$0")/.."
- IMAGE="${BUILD_IMAGE:-smartbotic-automation-build-base:debian13}"
- if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then
- echo "build image $IMAGE not found - build it with packaging/Dockerfile.base" >&2
- exit 1
- fi
- fail=0
- for test_src in tests/cpp/*_test.cpp; do
- name=$(basename "$test_src" .cpp)
- # Each test names the sources it needs on a "// sources:" line, so adding a
- # test does not mean editing this script.
- sources=$(grep -m1 '^// sources:' "$test_src" | sed 's|^// sources:||')
- [ -z "$sources" ] && sources="lib/common/${name%_test}.cpp lib/common/string_utils.cpp"
- echo "=== $name"
- docker run --rm -v "$PWD":/src -w /src "$IMAGE" sh -c \
- "g++ -std=c++20 -I lib -o /tmp/$name $test_src $sources -lssl -lcrypto && /tmp/$name"
- [ $? -ne 0 ] && fail=$((fail + 1))
- done
- if [ $fail -ne 0 ]; then
- echo "$fail C++ test binary/binaries failed"
- exit 1
- fi
- echo "C++ tests passed"
|