Skip to content
Shell
1.1 KB
Raw Blame
#!/bin/bash
# Get test status for a project directory
# Usage: get-test-status.sh /path/to/project
# Returns: Formatted test status with emoji and color

PROJECT_DIR="${1:-$(pwd)}"
STATUS_FILE="$PROJECT_DIR/.test-status"

# Check if status file exists and is recent (less than 5 minutes old)
if [ -f "$STATUS_FILE" ]; then
    file_age=$(( $(date +%s) - $(stat -f %m "$STATUS_FILE" 2>/dev/null || stat -c %Y "$STATUS_FILE" 2>/dev/null) ))

    if [ $file_age -lt 300 ]; then
        status=$(cat "$STATUS_FILE")

        # Format output with colors
        if [[ "$status" == "pass"* ]]; then
            green=$(printf '\033[38;5;34m')
            reset=$(printf '\033[0m')
            echo "${green}✅${reset}"
        elif [[ "$status" == "fail"* ]]; then
            red=$(printf '\033[38;5;196m')
            reset=$(printf '\033[0m')
            # Extract failure count if available
            if [[ "$status" =~ fail:([0-9]+) ]]; then
                count="${BASH_REMATCH[1]}"
                echo "${red}❌(${count})${reset}"
            else
                echo "${red}❌${reset}"
            fi
        fi
    fi
fi