$ErrorActionPreference = 'Continue'

$repo = Join-Path $env:USERPROFILE 'TibiaPilotNG'
$python = Join-Path $repo '.venv\Scripts\python.exe'
$result = 'C:\ProgramData\TibiaPilotNG\bbot-qa.json'
$testOutput = 'C:\ProgramData\TibiaPilotNG\bbot-qa-tests.txt'
Set-Location $repo

& $python -m pytest `
    tests/unit/importers/test_bbot.py `
    tests/unit/gameplay/core/tasks/test_bbot_compat.py `
    tests/unit/gameplay/core/middlewares/test_radar.py `
    tests/unit/gameplay/test_bbot_runtime.py `
    tests/unit/gameplay/healing/test_potions.py `
    tests/unit/utils/test_mouse.py `
    tests/unit/utils/test_keyboard.py `
    -q --disable-warnings *> $testOutput
$tests = $LASTEXITCODE

& $python -m compileall -q main.py src
$compile = $LASTEXITCODE

[pscustomobject]@{tests = $tests; compile = $compile} |
    ConvertTo-Json -Compress |
    Set-Content $result -Encoding ascii

if ($tests -or $compile) {
    exit 1
}
