#!/bin/sh
set -e

# Ensure we’re in a clean build directory
mkdir -p build
cd build

# Ensure CTest temporary directory exists
mkdir -p Testing/Temporary

# Modified build config (compared to the debian/rules file)
# - Static linkage to access private API within the tests
# - Enable unit tests
# Capturing all warnings. Otherwise ctest below fails.
cmake -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_C_VISIBILITY_PRESET=hidden \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DUA_BUILD_UNIT_TESTS=ON \
      -DUA_NAMESPACE_ZERO=FULL \
      -DUA_NODESET_DIR=$(pwd)/../nodeset \
      -DUA_ENABLE_DATATYPES_ALL=ON \
      -DUA_ENABLE_HARDENING=ON \
      -DUA_ENABLE_ENCRYPTION="MBEDTLS" \
      -DUA_ENABLE_PUBSUB=ON \
      -DUA_ENABLE_PUBSUB_ENCRYPTION=ON \
      -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON \
      .. 2>&1 | tee cmake.log

# Build
make -j$(nproc)

# Run the tests.
# Exclude the tests which require raw Ethernet capabilities.
ctest --output-on-failure -E "_eth"
