#!/bin/bash

set -e

cd tests

# Prepare for running with installed kvazaar binary.
sed -i "s|../libtool execute ||g" "util.sh"
sed -i "s|../src/kvazaar|/usr/bin/kvazaar|g" "util.sh"

output=$(mktemp)

# Run all tests from upstream.
for filename in $(find ./test_*.sh | sort); do
    if [ "$filename" = "test_external_symbols.sh" ]; then
        # Skip test that checks built .a file for correct symbols. Will not work
        # from a binary installation.
        continue
    fi

    set +e
    ./"$filename" > "$output" 2>&1
    status=$?
    set -e
    if [ $status -ne 0 ]; then
        echo "Test $filename failed, exit code $status"
        cat "$output"
        exit 255
    fi
done
