#!/bin/sh
# Execute a real suite and check that all three output files are produced.
set -eu

cd "$AUTOPKGTEST_TMP"

cat > smoke.robot <<'EOF'
*** Test Cases ***
Passing Test
    Log    Hello from autopkgtest
    Should Be Equal    ${1}    ${1}

Test With Tag
    [Tags]    smoke
    Should Contain    Robot Framework    Robot
EOF

robot --outputdir results smoke.robot

for f in output.xml log.html report.html; do
    test -s "results/$f" || { echo "ERROR: results/$f missing or empty" >&2; exit 1; }
done

# An HTML log with its JavaScript inlined is far bigger than this
for f in log.html report.html; do
    size=$(wc -c < "results/$f")
    echo "results/$f: $size bytes"
    test "$size" -gt 50000 || {
        echo "ERROR: results/$f is only $size bytes, JavaScript likely missing" >&2
        exit 1
    }
done

# Nothing should still be pointing at an external script
if grep -q '<script[^>]*src=' results/log.html results/report.html; then
    echo "ERROR: unresolved external script reference in generated output" >&2
    grep -n '<script[^>]*src=' results/log.html results/report.html >&2
    exit 1
fi

# Rebot should be able to read the output back and regenerate the reports
rebot --outputdir rebot-results results/output.xml
test -s rebot-results/log.html
test -s rebot-results/report.html

echo "smoke test passed"
