30 lines
1.4 KiB
Dart
30 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// 관리자 지시 (10/19, 28 이 찾음): 통합 시험 · 캡처가 %TEMP%\jj_* 시험 폴더를 남겼다 - 시험 끝 (실패해도) 에 지운다.
|
|
/// [base] 가 있으면 그 아래 (짧은 경로가 필요한 캡처). 반드시 시험 (testWidgets · test) 안에서 부른다 (addTearDown).
|
|
Directory testTempDir(String prefix, {String? base}) {
|
|
final root = base == null || base.isEmpty ? Directory.systemTemp : (Directory(base)..createSync(recursive: true));
|
|
final dir = root.createTempSync(prefix);
|
|
addTearDown(() => deleteTestTemp(dir));
|
|
return dir;
|
|
}
|
|
|
|
/// 시험 폴더 지우기 - 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');
|
|
}
|