#!/usr/bin/env bash

if [ -z "$SAGE_TESTDIR" -a -n "$SAGE_ROOT" ]; then
    SAGE_TESTDIR="$DOT_SAGE"/tmp
fi
mkdir -p "$SAGE_TESTDIR"
SAGE_TEST_LOG="$SAGE_TESTDIR/test.log"
cd "$SAGE_TESTDIR"

cat "$SAGE_ROOT/local/bin/sage-banner" > "$SAGE_TEST_LOG"
echo `date` >> "$SAGE_TEST_LOG"

# Run doctests on documentation and library, which end with a summary
# report.  (We do this all in a single run of "sage -t" so we get a
# single summary.)  We test doc/common and all subdirectories of doc/
# whose names consist of two lowercase letters: those should match the
# various languages.
sage -t -sagenb "$@" \
    devel/doc/common \
    devel/doc/[a-z][a-z] \
    devel/sage/sage 2>&1 | tee -a "$SAGE_TEST_LOG"

if [ "$SAGE_TESTDIR" = "$SAGE_ROOT/tmp" ]; then
    cat "$SAGE_TEST_LOG" >> "$SAGE_ROOT"/test.log
fi

echo "Please see $SAGE_TEST_LOG for the complete log from this test."

exit 0
