#!/bin/bash
set -e
sudo apt-get update
sudo apt-get -y install \
   build-essential cmake lcov \
   zlib1g-dev libjpeg-dev libgnutls28-dev libssl-dev
cmake -S . -B build \
    -DCI_MODE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug \
    -DREQUIRE_CRYPTO_OPENSSL=1 -DREQUIRE_CRYPTO_GNUTLS=1 \
    -DENABLE_QTC=1 -DENABLE_COVERAGE=ON
cmake --build build --verbose -j$(nproc) -- -k
(cd build; ctest --verbose)
# lcov reports "inconsistent" when a function was never called but its
# first line was executed. This happens whenever a lambda that is never
# called is defined on the same line as code that runs, which is
# common in qpdf. The coverage data is correct in that case. Each lcov
# command repeats the check, so each one needs the flag.
lcov --capture --directory . --output-file coverage.info \
     --ignore-errors inconsistent
lcov --remove coverage.info '/usr/*' --output-file coverage.info \
     --ignore-errors inconsistent
lcov --list coverage.info --ignore-errors inconsistent
