#!/bin/sh # SPDX-License-Identifier: LGPL-3.0-only # SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® # Runs the tests built with clang's source-based coverage and reports it for nostro's own sources, then lists every # line no test ran. Needs crafter-build, llvm-profdata, llvm-cov and llvm-readelf on PATH. A toolchain without compiler-rt's profile # runtime takes its libclang_rt.profile archive as the first argument. Leaves the profiles and the annotated sources in # build/coverage/. set -eu cd "$(dirname "$0")/.." out=build/coverage rm -rf "$out" mkdir -p "$out" if [ $# -gt 0 ]; then LLVM_PROFILE_FILE="$PWD/$out/%p.profraw" crafter-build test --banks=bunq --coverage "--profile-runtime=$1" else LLVM_PROFILE_FILE="$PWD/$out/%p.profraw" crafter-build test --banks=bunq --coverage fi llvm-profdata merge -sparse "$out"/*.profraw -o "$out/nostro.profdata" # Each test's newest build with coverage mappings in it: a plain build can be newer, and a test whose sources did not # change is not linked again. set -- for test in tests/Should*/; do name=$(basename "$test") for binary in $(ls -t bin/"$name"-*/"$name"); do if llvm-readelf -S "$binary" | grep -q __llvm_covfun; then if [ $# -eq 0 ]; then set -- "$binary" else set -- "$@" -object "$binary" fi break fi done done ignore='(lib/json\.hpp|/tests/|/Crafter\.|/app/|/usr/)' llvm-cov report "$@" -instr-profile="$out/nostro.profdata" -ignore-filename-regex="$ignore" | tee "$out/report.txt" llvm-cov show "$@" -instr-profile="$out/nostro.profdata" -ignore-filename-regex="$ignore" -format=text > "$out/sources.txt" awk '/^\/.*:$/ { file = $0 } /^ *[0-9]+\| *0\|/ { split($0, part, "|"); gsub(/ /, "", part[1]); print "not run: " file part[1] }' "$out/sources.txt" # The toolkit and the app are built only for what depends on them, so a source of theirs that no test links would be # missing from the report, not listed in it as never run: each of their implementation units has to be there. The # window's (Nostro.Ui.Shell) are not among them: no test opens a window. missing=0 for source in implementations/Nostro.Ui-*.cpp implementations/Nostro.App-*.cpp; do if ! grep -q "^$source " "$out/report.txt"; then echo "not in the report: $source, which no test links" missing=1 fi done [ "$missing" = 0 ]