#!/usr/bin/env python3
"""
#exonware/xwsystem/tests/0.core/caching/runner.py

Core test runner for caching module - Fast, High-Value Checks.

Company: eXonware.com
Author: Eng. Muhammad AlShehri
Email: connect@exonware.com
Version: 0.0.1.388
Generation Date: 01-Nov-2025

Usage:
    python tests/0.core/caching/runner.py
"""

import sys
import pytest
from pathlib import Path
from datetime import datetime

# Add src to Python path
src_path = Path(__file__).parent.parent.parent.parent / "src"
sys.path.insert(0, str(src_path))


def main():
    """Core test runner - 20% tests for 80% value."""
    print("🎯 Core Caching Tests - Fast, High-Value Checks")
    print(f"📂 Test Directory: {Path(__file__).parent.absolute()}")
    print()

    # Run core tests
    exit_code = pytest.main([
        "-v",
        "--tb=short",
        "-x",  # Stop on first failure
        str(Path(__file__).parent),
        "-m", "xsystem_core and xsystem_caching"
    ])

    # Status output
    if exit_code == 0:
        status = "✅ Core caching tests PASSED"
    else:
        status = "❌ Core caching tests FAILED"

    print()
    print(status)

    # Save Markdown output
    output_file = Path(__file__).parent / "runner_out.md"
    markdown_content = f"""# Core Caching Test Results

**Module:** Caching
**Layer:** 0.core
**Generated:** {datetime.now().strftime("%d-%b-%Y %H:%M:%S")}
**Status:** {'PASSED' if exit_code == 0 else 'FAILED'}

---

## Test Execution

**Command:** `python tests/0.core/caching/runner.py`

**Markers:** `xsystem_core and xsystem_caching`

**Options:**
- Verbose output (`-v`)
- Short traceback (`--tb=short`)
- Stop on first failure (`-x`)

---

## Result

{status}

**Exit Code:** {exit_code}

---

*Generated by eXonware test runner - Excellence Edition*
"""

    output_file.write_text(markdown_content, encoding='utf-8')
    print(f"📝 Results saved to: {output_file.absolute()}")

    sys.exit(exit_code)


if __name__ == "__main__":
    main()
