JJ_MKVMaker/tool/test_temp_check.ps1

45 lines
2.3 KiB
PowerShell

# 전체 시험 + 임시 폴더 흔적 검사 (관리자 지시 10/17): 시험이 %TEMP%\jj_* 폴더를 남기지 않는지.
# - 시험 전 · 뒤의 %TEMP% 를 비교해, 새로 남은 폴더 중 이름 앞부분이 시험 소스 (test\*.dart) 의 createTemp('jj…') 와 같은 것만 본다
# (앱 · 다른 프로그램이 만든 jj_mkvmaker 등은 세지 않음). 하나라도 남으면 이름을 보이고 실패 (exit 2).
# - 시험 파일들은 동시에 돌아 파일마다 스스로 확인할 수 없어 (누가 만든 폴더인지 모름) 전체 실행 앞뒤로 본다.
# - 다른 worktree · 세션이 같은 시험을 동시에 돌리면 그쪽 폴더가 섞일 수 있다 (이름으로 확인).
# - 이미 있던 폴더는 건드리지 않는다 (지우지 않음).
# 사용 (app 폴더에서): powershell -ExecutionPolicy Bypass -File tool\test_temp_check.ps1 [flutter test 인자…]
$ErrorActionPreference = 'Stop'
$app = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$temp = [System.IO.Path]::GetTempPath()
# 시험 소스가 쓰는 임시 폴더 이름 앞부분 (createTemp('jj_x_') · createTempSync('jj_x_'))
$prefixes = @(Get-ChildItem (Join-Path $app 'test') -Recurse -Filter *.dart |
ForEach-Object { [regex]::Matches((Get-Content $_.FullName -Raw -Encoding utf8), 'createTemp(?:Sync)?\(''(jj[^''$]*)''') } |
ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique)
if ($prefixes.Count -eq 0) { throw '시험 소스에서 임시 폴더 이름을 찾지 못했습니다' }
function Get-TestTemp {
@(Get-ChildItem $temp -Directory -Filter 'jj*' -ErrorAction SilentlyContinue | ForEach-Object { $_.Name })
}
$before = @{}
foreach ($n in Get-TestTemp) { $before[$n] = $true }
Push-Location $app
try {
flutter test @args
$code = $LASTEXITCODE
} finally {
Pop-Location
}
# 시험이 끝난 뒤 지우기가 늦게 끝나는 것 (백신 · 색인) 을 잠깐 기다린다
Start-Sleep -Seconds 3
$left = @(Get-TestTemp | Where-Object { -not $before.ContainsKey($_) } | Where-Object {
$n = $_
@($prefixes | Where-Object { $n.StartsWith($_) }).Count -gt 0
})
if ($left.Count -gt 0) {
Write-Host ("시험이 남긴 임시 폴더 {0}개 (%TEMP%):" -f $left.Count)
$left | Sort-Object | ForEach-Object { Write-Host " $_" }
if ($code -eq 0) { exit 2 }
} else {
Write-Host '임시 폴더 흔적: 새로 남은 것 0'
}
exit $code