#!/bin/sh

set -e

if [ -n "$SALSA_CI" ]; then
    # pixbuf-fail triggers oom-killer in salsa-ci
    flaky_tests_regex='^gdk-pixbuf/pixbuf-\(randomly-modified\|fail\)\.test$'
else
    flaky_tests_regex='^gdk-pixbuf/pixbuf-randomly-modified\.test$'
fi

namespace=gdk-pixbuf/

# Deliberately word-splitting:
# shellcheck disable=SC2046
set -- $(
    gnome-desktop-testing-runner -l "$namespace" |
    cut -f1 -d' ' |
    grep -v "$flaky_tests_regex"
)

if [ -z "$*" ]; then
    echo "Error: no installed-tests found matching $namespace" >&2
    exit 1
fi

exec gnome-desktop-testing-runner \
--report-directory="$AUTOPKGTEST_ARTIFACTS" \
--tap \
-- \
"$@"
