|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:file/memory.dart';
|
| 6 | +import 'package:file_testing/file_testing.dart'; |
6 | 7 | import 'package:flutter_tools/src/artifacts.dart';
|
7 | 8 | import 'package:flutter_tools/src/base/file_system.dart';
|
8 | 9 | import 'package:flutter_tools/src/base/logger.dart';
|
@@ -54,12 +55,33 @@ environment:
|
54 | 55 | flutter: ">=1.20.0"
|
55 | 56 | ''';
|
56 | 57 |
|
| 58 | +/// Returns a `pubspec.yaml` where `$platform` uses `dartPluginClass: 'none'`. |
| 59 | +String samplePluginPubspecWithDartPluginClassNone({required String platform}) => |
| 60 | + ''' |
| 61 | +name: path_provider_$platform |
| 62 | +description: $platform implementation of the path_provider plugin |
| 63 | +// version: 2.0.1 |
| 64 | +// homepage: https://github.com/flutter/plugins/tree/main/packages/path_provider/path_provider_$platform |
| 65 | +flutter: |
| 66 | + plugin: |
| 67 | + implements: path_provider |
| 68 | + platforms: |
| 69 | + $platform: |
| 70 | + dartPluginClass: none |
| 71 | + pluginClass: none |
| 72 | +environment: |
| 73 | + sdk: ^3.7.0-0 |
| 74 | + flutter: ">=1.20.0" |
| 75 | +'''; |
| 76 | + |
57 | 77 | void main() {
|
58 | 78 | group('Dart plugin registrant', () {
|
59 | 79 | late FileSystem fileSystem;
|
| 80 | + late BufferLogger logger; |
60 | 81 |
|
61 | 82 | setUp(() {
|
62 | 83 | fileSystem = MemoryFileSystem.test();
|
| 84 | + logger = BufferLogger.test(); |
63 | 85 | });
|
64 | 86 |
|
65 | 87 | testWithoutContext('skipped based on environment.generateDartPluginRegistry', () async {
|
@@ -158,6 +180,59 @@ name: path_provider_example
|
158 | 180 | },
|
159 | 181 | );
|
160 | 182 |
|
| 183 | + for (final platform in ['linux', 'macos', 'windows']) { |
| 184 | + testUsingContext( |
| 185 | + '$platform treats dartPluginClass: "none" as omitted', |
| 186 | + () async { |
| 187 | + final Directory projectDir = fileSystem.directory('project')..createSync(); |
| 188 | + final environment = Environment.test( |
| 189 | + fileSystem.currentDirectory, |
| 190 | + projectDir: projectDir, |
| 191 | + artifacts: Artifacts.test(), |
| 192 | + fileSystem: fileSystem, |
| 193 | + logger: BufferLogger.test(), |
| 194 | + processManager: FakeProcessManager.any(), |
| 195 | + defines: <String, String>{ |
| 196 | + kTargetFile: projectDir.childDirectory('lib').childFile('main.dart').absolute.path, |
| 197 | + }, |
| 198 | + generateDartPluginRegistry: true, |
| 199 | + ); |
| 200 | + |
| 201 | + writePackageConfigFiles( |
| 202 | + directory: projectDir, |
| 203 | + mainLibName: 'path_provider_example', |
| 204 | + packages: <String, String>{'path_provider_$platform': '/path_provider_$platform'}, |
| 205 | + languageVersions: <String, String>{'path_provider_example': '2.12'}, |
| 206 | + ); |
| 207 | + |
| 208 | + projectDir.childFile('pubspec.yaml').writeAsStringSync(_kSamplePubspecFile); |
| 209 | + |
| 210 | + projectDir.childDirectory('lib').childFile('main.dart').createSync(recursive: true); |
| 211 | + |
| 212 | + environment.fileSystem.currentDirectory |
| 213 | + .childDirectory('path_provider_$platform') |
| 214 | + .childFile('pubspec.yaml') |
| 215 | + ..createSync(recursive: true) |
| 216 | + ..writeAsStringSync(samplePluginPubspecWithDartPluginClassNone(platform: platform)); |
| 217 | + |
| 218 | + final FlutterProject testProject = FlutterProject.fromDirectoryTest(projectDir); |
| 219 | + await DartPluginRegistrantTarget.test(testProject).build(environment); |
| 220 | + |
| 221 | + final File generatedMain = projectDir |
| 222 | + .childDirectory('.dart_tool') |
| 223 | + .childDirectory('flutter_build') |
| 224 | + .childFile('dart_plugin_registrant.dart'); |
| 225 | + expect(generatedMain, isNot(exists)); |
| 226 | + expect(logger.warningText, contains('Use of `dartPluginClass: none`')); |
| 227 | + }, |
| 228 | + overrides: { |
| 229 | + Logger: () => logger, |
| 230 | + ProcessManager: () => FakeProcessManager.any(), |
| 231 | + Pub: ThrowingPub.new, |
| 232 | + }, |
| 233 | + ); |
| 234 | + } |
| 235 | + |
161 | 236 | testUsingContext(
|
162 | 237 | 'regenerates dart_plugin_registrant.dart',
|
163 | 238 | () async {
|
|
0 commit comments