#!/bin/bash -ex

function findexe() {
  while [ $# -gt 0 ]; do
    while read -d: path; do
        [ -f "$path/$1" -a -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 -s https://codecov.io/bash) 2>&1 \
  | egrep -v "has arcs (to entry|from exit) block"
