Skip to content

Commit 5757500

Browse files
authored
Make test file systems/platforms used in asset_bundle_test.dart less dependent on the host platform (#141657)
Part of work on flutter/flutter#141214. See [this discussion](flutter/flutter#141214 (comment)) for the inspiration for this PR. ## Issue Many tests in [packages/flutter_tools/test/general.shard/asset_bundle_test.dart](https://github.com/flutter/flutter/blob/4cd0a3252d2b45e243714b3ce93c5b2313bce671/packages/flutter_tools/test/general.shard/asset_bundle_test.dart) aren't hermetic. When setting up fake `FileSystem` and `Platform` objects, the host OS is referenced: https://github.com/flutter/flutter/blob/f2745e97d53c6a29c7d40003dfaa4fc4c688cdd2/packages/flutter_tools/test/general.shard/asset_bundle_test.dart#L35-L40 https://github.com/flutter/flutter/blob/f2745e97d53c6a29c7d40003dfaa4fc4c688cdd2/packages/flutter_tools/test/general.shard/asset_bundle_test.dart#L43 To improve hermeticity here, we could instead run each once _per_ valid combination of file system style and platform. However, it is unclear if these tests even depend on the file system style (integration tests should catch most cases where this might matter). As a result, I think it's sufficient to improve hermeticity by always assuming a Linux environment, which is generally our default (as `MemoryFileSystem` does, and most of our fakes of `Platform` do by default). In general, if a test needs to run other kinds of environments, it should make this clear, ideally through the test name.
1 parent f5442bf commit 5757500

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

packages/flutter_tools/test/general.shard/asset_bundle_test.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@ void main() {
3333
late Platform platform;
3434

3535
setUp(() async {
36-
testFileSystem = MemoryFileSystem(
37-
style: globals.platform.isWindows
38-
? FileSystemStyle.windows
39-
: FileSystemStyle.posix,
40-
);
36+
testFileSystem = MemoryFileSystem();
4137
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
4238
logger = BufferLogger.test();
43-
platform = FakePlatform(operatingSystem: globals.platform.operatingSystem);
39+
platform = FakePlatform();
4440
});
4541

4642
testUsingContext('nonempty', () async {
@@ -49,6 +45,7 @@ void main() {
4945
expect(ab.entries.length, greaterThan(0));
5046
}, overrides: <Type, Generator>{
5147
FileSystem: () => testFileSystem,
48+
Platform: () => platform,
5249
ProcessManager: () => FakeProcessManager.any(),
5350
});
5451

@@ -75,6 +72,7 @@ void main() {
7572

7673
}, overrides: <Type, Generator>{
7774
FileSystem: () => testFileSystem,
75+
Platform: () => platform,
7876
ProcessManager: () => FakeProcessManager.any(),
7977
});
8078

@@ -120,6 +118,7 @@ flutter:
120118
]));
121119
}, overrides: <Type, Generator>{
122120
FileSystem: () => testFileSystem,
121+
Platform: () => platform,
123122
ProcessManager: () => FakeProcessManager.any(),
124123
});
125124

@@ -150,6 +149,7 @@ flutter:
150149
'assets/foo/fizz.txt']));
151150
}, overrides: <Type, Generator>{
152151
FileSystem: () => testFileSystem,
152+
Platform: () => platform,
153153
ProcessManager: () => FakeProcessManager.any(),
154154
});
155155

@@ -192,6 +192,7 @@ name: example''')
192192
'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt']));
193193
}, overrides: <Type, Generator>{
194194
FileSystem: () => testFileSystem,
195+
Platform: () => platform,
195196
ProcessManager: () => FakeProcessManager.any(),
196197
});
197198

@@ -217,6 +218,7 @@ flutter:
217218
expect(bundle.needsBuild(), false);
218219
}, overrides: <Type, Generator>{
219220
FileSystem: () => testFileSystem,
221+
Platform: () => platform,
220222
ProcessManager: () => FakeProcessManager.any(),
221223
});
222224

@@ -252,6 +254,7 @@ flutter:
252254
expect(bundle.needsBuild(), false);
253255
}, overrides: <Type, Generator>{
254256
FileSystem: () => testFileSystem,
257+
Platform: () => platform,
255258
ProcessManager: () => FakeProcessManager.any(),
256259
});
257260

@@ -282,6 +285,7 @@ flutter:
282285
expect(bundle.needsBuild(), false);
283286
}, overrides: <Type, Generator>{
284287
FileSystem: () => testFileSystem,
288+
Platform: () => platform,
285289
ProcessManager: () => FakeProcessManager.any(),
286290
});
287291

@@ -330,6 +334,7 @@ flutter:
330334
expect(bundle.deferredComponentsEntries['component1']!.length, 3);
331335
}, overrides: <Type, Generator>{
332336
FileSystem: () => testFileSystem,
337+
Platform: () => platform,
333338
ProcessManager: () => FakeProcessManager.any(),
334339
});
335340

@@ -515,14 +520,12 @@ flutter:
515520

516521
group('AssetBundle.build (web builds)', () {
517522
late FileSystem testFileSystem;
523+
late Platform testPlatform;
518524

519525
setUp(() async {
520-
testFileSystem = MemoryFileSystem(
521-
style: globals.platform.isWindows
522-
? FileSystemStyle.windows
523-
: FileSystemStyle.posix,
524-
);
526+
testFileSystem = MemoryFileSystem();
525527
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
528+
testPlatform = FakePlatform();
526529
});
527530

528531
testUsingContext('empty pubspec', () async {
@@ -550,6 +553,7 @@ flutter:
550553
);
551554
}, overrides: <Type, Generator>{
552555
FileSystem: () => testFileSystem,
556+
Platform: () => testPlatform,
553557
ProcessManager: () => FakeProcessManager.any(),
554558
});
555559

@@ -605,6 +609,7 @@ flutter:
605609
reason: 'JSON-encoded binary content should be identical to BIN file.');
606610
}, overrides: <Type, Generator>{
607611
FileSystem: () => testFileSystem,
612+
Platform: () => testPlatform,
608613
ProcessManager: () => FakeProcessManager.any(),
609614
});
610615
});
@@ -657,6 +662,7 @@ assets:
657662
expect(license, bundle.entries['NOTICES']);
658663
}, overrides: <Type, Generator>{
659664
FileSystem: () => MemoryFileSystem.test(),
665+
Platform: () => FakePlatform(),
660666
ProcessManager: () => FakeProcessManager.any(),
661667
});
662668

@@ -678,6 +684,7 @@ flutter:
678684
expect(bundle.additionalDependencies.single.path, contains('DOES_NOT_EXIST_RERUN_FOR_WILDCARD'));
679685
}, overrides: <Type, Generator>{
680686
FileSystem: () => MemoryFileSystem.test(),
687+
Platform: () => FakePlatform(),
681688
ProcessManager: () => FakeProcessManager.any(),
682689
});
683690

@@ -699,6 +706,7 @@ flutter:
699706
expect(bundle.additionalDependencies, isEmpty);
700707
}, overrides: <Type, Generator>{
701708
FileSystem: () => MemoryFileSystem.test(),
709+
Platform: () => FakePlatform(),
702710
ProcessManager: () => FakeProcessManager.any(),
703711
});
704712

0 commit comments

Comments
 (0)