1
1
import 'dart:async' ;
2
+ import 'dart:io' show Platform;
2
3
3
4
import 'package:file/memory.dart' ;
4
5
import 'package:path/path.dart' as path;
@@ -16,11 +17,20 @@ void main() {
16
17
late Formatter formatter;
17
18
18
19
setUp (() {
19
- fs = MemoryFileSystem ();
20
+ fs = MemoryFileSystem (
21
+ style: Platform .isWindows
22
+ ? FileSystemStyle .windows
23
+ : FileSystemStyle .posix);
20
24
logPath = path.join ('logs' , 'test.log' );
21
25
formatter = (record) => '${record .message }\n ' .codeUnits;
22
26
});
23
27
28
+ String normalizePath (String p) => path.normalize (p);
29
+
30
+ bool pathEquals (String path1, String path2) {
31
+ return normalizePath (path1) == normalizePath (path2);
32
+ }
33
+
24
34
test ('creates log file and directory if they do not exist' , () {
25
35
final handler = FileHandler (
26
36
const LogFileRotationPolicy .never (),
@@ -196,7 +206,7 @@ void main() {
196
206
final files = directory
197
207
.listSync ()
198
208
.where ((f) => f.path.endsWith ('.log' ))
199
- .map ((f) => f.path)
209
+ .map ((f) => normalizePath ( f.path) )
200
210
.toList ();
201
211
202
212
// Store newly created backup file
@@ -213,13 +223,13 @@ void main() {
213
223
final remainingFiles = directory
214
224
.listSync ()
215
225
.where ((f) => f.path.endsWith ('.log' ))
216
- .map ((f) => f.path)
226
+ .map ((f) => normalizePath ( f.path) )
217
227
.toList ();
218
228
219
229
// Extract timestamps from filenames to verify chronological order
220
230
List <String > extractTimestamps (List <String > files) {
221
231
return files
222
- .where ((f) => f != logPath) // Exclude current log file
232
+ .where ((f) => ! pathEquals (f, logPath))
223
233
.map ((f) {
224
234
final match = RegExp (r'_(\d{14})\.log$' ).firstMatch (f);
225
235
return match? .group (1 ) ?? '' ;
0 commit comments