import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; /// 관리자 지시 (10/19, 28 이 찾음): 통합 시험 · 캡처가 %TEMP%\jj_* 시험 폴더를 남겼다 - 시험 끝 (실패해도) 에 지운다. /// [base] 가 있으면 그 아래 (짧은 경로가 필요한 캡처). 반드시 시험 (testWidgets · test) 안에서 부른다 (addTearDown). /// [heldByApp]: 앱이 끝날 때까지 놓지 않는 폴더 (Edge 사용자 데이터 - Windows 판 플러그인에는 환경 닫기가 없다). /// 이름 앞에 jj_held_ 를 붙이고, tool/test_temp_check.ps1 은 이것을 실패로 세지 않고 앱이 끝난 뒤 실행 폴더와 함께 지운다 Directory testTempDir(String prefix, {String? base, bool heldByApp = false}) { final root = base == null || base.isEmpty ? Directory.systemTemp : (Directory(base)..createSync(recursive: true)); final dir = root.createTempSync(heldByApp ? 'jj_held_$prefix' : prefix); addTearDown(() => deleteTestTemp(dir)); if (base == null || base.isEmpty) expectInTaggedTemp(dir); return dir; } /// 관리자 지시 (10/20): tool/test_temp_check.ps1 이 TEMP · TMP 를 실행 폴더 (%TEMP%\t_jjrun_<표>) 로 돌리고 표를 JJ_TEST_TMP_TAG 로 넘긴다. /// 표가 있는데 임시 폴더가 그 밖에 생기면 (환경 변수가 시험 · 앱까지 오지 않음) 다른 세션 시험과 섞이므로 시험을 실패시킨다 void expectInTaggedTemp(Directory dir) { final tag = Platform.environment['JJ_TEST_TMP_TAG'] ?? ''; if (tag.isEmpty) return; expect(dir.absolute.path.toLowerCase(), contains('t_jjrun_$tag'.toLowerCase()), reason: 'TEMP 가 시험 실행 폴더로 오지 않음 (JJ_TEST_TMP_TAG=$tag)'); } /// 시험 폴더 지우기 - Windows 에서 앱 · WebView · 백신이 파일을 잠깐 잡고 있으면 몇 번 다시 해 본다 (기다림은 실제 시간: 가짜 시계 밖). /// 긴 경로는 \\?\ 로. 끝내 못 지우면 알리기만 하고 시험은 실패시키지 않는다 (tool/test_temp_check.ps1 이 남은 것을 잡는다) void deleteTestTemp(Directory dir) { final path = dir.absolute.path; final target = Platform.isWindows && !path.startsWith(r'\\?\') ? Directory('\\\\?\\$path') : dir; for (var i = 0; i < 20; i++) { try { if (!target.existsSync()) return; target.deleteSync(recursive: true); return; } on FileSystemException { sleep(const Duration(milliseconds: 250)); } } stderr.writeln('시험 임시 폴더를 지우지 못함: $path'); }