run-cpp-tests.sh 1.3 KB

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