Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 052272d

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Avoid dependency on file system order in modular_test/loader_test
Change-Id: Ic7d5197c9d914998dcd761c42763d9e9e36ad507 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103624 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent d705469 commit 052272d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pkg/modular_test/lib/src/loader.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ Future<ModularTest> loadTest(Uri uri) async {
4343
String specString;
4444
Module mainModule;
4545
Map<String, Uri> packages = {};
46-
await for (var entry in folder.list(recursive: false)) {
46+
var entries = folder.listSync(recursive: false).toList()
47+
// Sort to avoid dependency on file system order.
48+
..sort(_compareFileSystemEntity);
49+
for (var entry in entries) {
4750
var entryUri = entry.uri;
4851
if (entry is File) {
4952
var fileName = entryUri.path.substring(testUri.path.length);
@@ -247,3 +250,20 @@ class InvalidTestError extends Error {
247250
InvalidTestError(this.message);
248251
String toString() => "Invalid test: $message";
249252
}
253+
254+
/// Comparator to sort directories before files.
255+
int _compareFileSystemEntity(FileSystemEntity a, FileSystemEntity b) {
256+
if (a is Directory) {
257+
if (b is Directory) {
258+
return a.path.compareTo(b.path);
259+
} else {
260+
return -1;
261+
}
262+
} else {
263+
if (b is Directory) {
264+
return 1;
265+
} else {
266+
return a.path.compareTo(b.path);
267+
}
268+
}
269+
}

0 commit comments

Comments
 (0)