#!/bin/bash

BINDIR="${CMAKE_BINARY_DIR}/tests/"
RET=0

# Next line is a hack
# Builds for epel6 doesn't have rpath setted and
# tests fails with a "libcreaterepo_c.so.0: cannot open shared
# object file: No such file or directory" error message.
export "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/:"

function runtest {
    gtester --verbose --keep-going "$1"
    if [ $? -ne 0 ]; then  RET=$(($RET+1)) ; fi
}

# Go to source dir (so test would be able to use testdata/ in this dir)
cd ${CMAKE_CURRENT_SOURCE_DIR}

# Iterate over compiled tests
for i in "$BINDIR"/test_*; do
    # Run only executable regular files with "test_" prefix
    if [ -f $i -a -x $i ]; then
        runtest "$i"
    fi
done

echo "Number of fails: $RET"
exit $RET
