@echo off
setlocal

echo ========================================
echo    MOSIS SANDBOX TEST RUNNER
echo ========================================
echo.

REM Check if build exists
if not exist "build\Debug\sandbox-test.exe" (
    echo Build not found. Building...
    echo.

    REM Check VCPKG_ROOT
    if "%VCPKG_ROOT%"=="" (
        echo ERROR: VCPKG_ROOT environment variable not set
        exit /b 1
    )

    REM Configure
    echo Configuring CMake...
    cmake -B build -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake
    if errorlevel 1 (
        echo ERROR: CMake configure failed
        exit /b 1
    )

    REM Build
    echo Building...
    cmake --build build --config Debug
    if errorlevel 1 (
        echo ERROR: Build failed
        exit /b 1
    )
    echo.
)

REM Run tests
echo Running tests...
echo.

cd build\Debug
sandbox-test.exe %*
set TEST_RESULT=%errorlevel%

cd ..\..

echo.
if %TEST_RESULT% equ 0 (
    echo ========================================
    echo    ALL TESTS PASSED
    echo ========================================
) else (
    echo ========================================
    echo    SOME TESTS FAILED
    echo ========================================
)

exit /b %TEST_RESULT%
