Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
RED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'NC='\033[0m'
PASSED=0FAILED=0
echo "Building hades..."cargo build --bin hades --quietHADES=$(cargo build --bin hades --message-format=json --quiet 2>/dev/null \ | python3 -c "import sys,json; [print(m['executable']) for l in sys.stdin for m in [json.loads(l)] if m.get('executable')]")
echo ""echo "Running example tests..."echo ""
test_example() { local file=$1 local dir=$(dirname "$file") local basename=$(basename "$file" .hd) local name="${file#examples/}" local name="${name%.hd}"
local expected_file="${dir}/.expected" local expect_failure=false [ -f "${dir}/.expect_failure" ] && expect_failure=true
local command="run"
echo -n "Testing $name... "
set +e OUTPUT=$("$HADES" $command "$file" 2>&1) EXIT_CODE=$? set -e
if [ -f "$expected_file" ]; then local expected expected=$(cat "$expected_file") if [ "$OUTPUT" = "$expected" ]; then echo -e "${GREEN}✓${NC}" PASSED=$((PASSED + 1)) else echo -e "${RED}✗${NC}" echo " Expected: $expected" echo " Got: $OUTPUT" FAILED=$((FAILED + 1)) fi elif [ "$expect_failure" = true ]; then if [ $EXIT_CODE -ne 0 ]; then echo -e "${GREEN}✓${NC}" PASSED=$((PASSED + 1)) else echo -e "${RED}✗${NC}" echo " Expected failure but exited 0" echo " Output: $OUTPUT" FAILED=$((FAILED + 1)) fi else if [ $EXIT_CODE -eq 0 ]; then echo -e "${GREEN}✓${NC}" PASSED=$((PASSED + 1)) else echo -e "${RED}✗${NC}" echo " File: $file" echo " Output: $OUTPUT" FAILED=$((FAILED + 1)) fi fi}
current_category=""
while IFS= read -r file; do category=$(echo "$file" | cut -d'/' -f2)
if [ "$current_category" != "$category" ]; then [ -n "$current_category" ] && echo "" category_display=$(echo "$category" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}') echo -e "${YELLOW}${category_display}:${NC}" current_category="$category" fi
test_example "$file" || truedone < <(find examples -name "main.hd" -type f | sort)
echo ""echo "================================"echo -e "${GREEN}Passed: $PASSED${NC}"if [ $FAILED -gt 0 ]; then echo -e "${RED}Failed: $FAILED${NC}" exit 1else echo -e "${GREEN}All tests passed!${NC}"fi