Skip to content

Commit d60eb1a

Browse files
fix: fix tests on windows
1 parent 569b586 commit d60eb1a

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ jobs:
3535
path: '%LOCALAPPDATA%\Pub\Cache'
3636
key: ${{ runner.os }}-${{ hashFiles('pubspec.yaml') }}
3737

38-
- name: Setup Dart VM
39-
uses: dart-lang/setup-dart@v1
38+
- uses: dart-lang/setup-dart@v1
4039

4140
- run: dart pub get
4241
- run: dart format --output=none --set-exit-if-changed .

test/file_handler_test.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:io' show Platform;
23

34
import 'package:file/memory.dart';
45
import 'package:path/path.dart' as path;
@@ -16,11 +17,20 @@ void main() {
1617
late Formatter formatter;
1718

1819
setUp(() {
19-
fs = MemoryFileSystem();
20+
fs = MemoryFileSystem(
21+
style: Platform.isWindows
22+
? FileSystemStyle.windows
23+
: FileSystemStyle.posix);
2024
logPath = path.join('logs', 'test.log');
2125
formatter = (record) => '${record.message}\n'.codeUnits;
2226
});
2327

28+
String normalizePath(String p) => path.normalize(p);
29+
30+
bool pathEquals(String path1, String path2) {
31+
return normalizePath(path1) == normalizePath(path2);
32+
}
33+
2434
test('creates log file and directory if they do not exist', () {
2535
final handler = FileHandler(
2636
const LogFileRotationPolicy.never(),
@@ -196,7 +206,7 @@ void main() {
196206
final files = directory
197207
.listSync()
198208
.where((f) => f.path.endsWith('.log'))
199-
.map((f) => f.path)
209+
.map((f) => normalizePath(f.path))
200210
.toList();
201211

202212
// Store newly created backup file
@@ -213,13 +223,13 @@ void main() {
213223
final remainingFiles = directory
214224
.listSync()
215225
.where((f) => f.path.endsWith('.log'))
216-
.map((f) => f.path)
226+
.map((f) => normalizePath(f.path))
217227
.toList();
218228

219229
// Extract timestamps from filenames to verify chronological order
220230
List<String> extractTimestamps(List<String> files) {
221231
return files
222-
.where((f) => f != logPath) // Exclude current log file
232+
.where((f) => !pathEquals(f, logPath))
223233
.map((f) {
224234
final match = RegExp(r'_(\d{14})\.log$').firstMatch(f);
225235
return match?.group(1) ?? '';

0 commit comments

Comments
 (0)