#! /bin/bash
# 
# Run separately LinkedWarrantTest
#
# Argument, if present, is a starting _directory_ under java/test, e.g. "jmri/managers"
#  
# The list of test files that fail goes into /failed_files.txt
#
# Assumes that a build step i.e. "ant tests" has already taken place, so that 
# individual test classes are ready to run. 
#

rm -f ./failed_files.txt
touch ./failed_files.txt

# Find all matching test files
test_files=$(find java/test/$1 -name \*Test.java -exec grep -q jmri.skipLinkedWarrantTest {} \; -print)

# Error if none found
if [ -z "$test_files" ]; then
    echo "ERROR: No tests with jmri.skipLinkedWarrantTest found."
    exit 2
fi

for jmri_test in $test_files
    do jmri_test=${jmri_test#java/test/} 
        jmri_test=${jmri_test%\.java}
        date
        echo ${jmri_test}
        ./runtest.csh ${jmri_test} || echo ${jmri_test} >> ./failed_files.txt
done

# error exit if any failed
if [ -s ./failed_files.txt ]; then echo "The following files failed"; cat ./failed_files.txt; exit 1; fi
