#!/bin/bash -ex

findexe() {
    while [ ${#} -gt 0 ]; do
        while read -r -d: path; do
            [ -f "${path}/${1}" ] \
                && [ -x "${path}/${1}" ] \
                && echo "${path}/${1}" && return 0
        done <<< "${PATH}:"
        shift
    done
    return 1
}

LC_ALL=$(locale -a | grep -i '^en_US\.utf') \
         || LC_ALL=$(locale -a | grep -i '^c\.utf')

export LC_ALL

mkdir build
cd build

export CFLAGS="-g -coverage"

if ! meson ..; then
    cat meson-logs/meson-log.txt >&2
    exit 1
fi

ninja=$(findexe ninja ninja-build)
"${ninja}" test

bash <(curl --retry 10 -s https://codecov.io/bash) 2>&1 \
       | grep -E -v "has arcs (to entry|from exit) block"

# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
