#!/bin/sh
# Minimal runner for GNOME-style installed-tests on Steam Runtime v1
# Copyright 2021 Collabora Ltd.
# SPDX-License-Identifier: MIT

set -eu

any=
fail=0

tests="$(find "/usr/share/installed-tests/$1" -name '*.test')"

for t in $tests; do
    any=1
    cmd=$(sed -n 's/^Exec=//p' "$t")

    if [ -z "$cmd" ]; then
        echo "ERROR: No command found in $t" >&2
        fail=1
    elif "$cmd"; then
        echo "# OK: $t -> $cmd"
    else
        echo "FAIL: exit status $? from $t -> $cmd" >&2
        fail=1
    fi
done

if [ -z "$any" ]; then
    echo "No tests found!" >&2
    exit 1
fi

exit "$fail"
