#!/usr/bin/env python3
#exonware/xwsyntax/tests/0.core/runner.py
"""
Core test runner for xwsyntax
Outputs both terminal and Markdown formats.
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.0.1
Generation Date: 29-Oct-2025
"""

import sys
import pytest
from pathlib import Path
from datetime import datetime
# ⚠️ CRITICAL: Configure UTF-8 encoding for Windows console using xwsystem utility
from exonware.xwsystem.console.cli import ensure_utf8_console
ensure_utf8_console()


def main():
    """Core test runner - 20% tests for 80% value."""
    # Add src to Python path
    src_path = Path(__file__).parent.parent.parent / "src"
    sys.path.insert(0, str(src_path))
    print("🎯 Core Tests - Fast, High-Value Checks")
    # Run core tests
    exit_code = pytest.main([
        "-v",
        "--tb=short",
        "--maxfail=1",  # Stop on first failure
        str(Path(__file__).parent),
        "-m", "xwsyntax_core"
    ])
    # Status output
    if exit_code == 0:
        status = "✅ Core tests PASSED"
    else:
        status = "❌ Core tests FAILED"
    print(status)
    # Save Markdown output
    output_file = Path(__file__).parent / "runner_out.md"
    markdown_content = f"""# Core Test Results
**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/runner.py`
**Markers:** `xwsyntax_core`
**Options:**
- Verbose output (`-v`)
- Short traceback (`--tb=short`)
- Stop on first failure (`--maxfail=1`)
---
## Result
{status}
**Exit Code:** {exit_code}
---
*Generated by eXonware test runner - Production Excellence Edition*
"""
    output_file.write_text(markdown_content, encoding='utf-8')
    print(f"\n📝 Results saved to: {output_file}")
    sys.exit(exit_code)
if __name__ == "__main__":
    main()
