#!/bin/bash

# Script to run doc-tests for the Wasot compiler
# Doc-tests verify that code examples in documentation are correct and up-to-date

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_ROOT"

echo "🔍 Running Wasot Compiler Doc-Tests"
echo "==================================="
echo

# Run doc-tests with timing
echo "📚 Executing documentation examples..."
start_time=$(date +%s)

cargo test --doc

end_time=$(date +%s)
duration=$((end_time - start_time))

echo
echo "✅ Doc-tests completed successfully in ${duration}s"
echo
echo "📖 Doc-tests verify that:"
echo "   • All code examples in documentation compile and run correctly"
echo "   • API usage examples are up-to-date and functional"
echo "   • Documentation provides reliable, executable examples"
echo
echo "💡 To add new doc-tests:"
echo "   • Add /// examples in doc comments with \`\`\`rust blocks"
echo "   • Use \`\`\`no_run for examples that shouldn't execute"
echo "   • Include realistic usage patterns in your examples"