From b2a30a372ca3cd3d1d03735c5c4a64110380ffc1 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 4 Aug 2023 12:40:04 -0700 Subject: [PATCH] [pigeon] Consolidate mock handler tests (#4642) Eliminates the `mock_handler_tester` sub-package, which existed just for a single unit test file and required duplicate `pigeons/message.dart` output generation with bespoke test wrappers, folding that test into the shared harness and generation system. This also eliminates an entire test suite from the test harness since it's now part of the rest of the Dart unit testing. This surfaced an edge-case problem with the new package name override, which is that if the override doesn't match the actual dart output location, generated Dart test output won't compile because the import will be wrong. This addresses that by passing the actual package as well to the test generator. --- packages/pigeon/CHANGELOG.md | 4 + packages/pigeon/lib/dart_generator.dart | 3 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/pigeon_lib.dart | 5 + .../pigeon/mock_handler_tester/.gitignore | 44 --- packages/pigeon/mock_handler_tester/.metadata | 10 - packages/pigeon/mock_handler_tester/README.md | 3 - .../pigeon/mock_handler_tester/lib/main.dart | 9 - .../pigeon/mock_handler_tester/pubspec.yaml | 20 - .../mock_handler_tester/test/message.dart | 357 ------------------ .../test/genered_dart_test_code_test.dart} | 12 +- .../test/test_message.gen.dart} | 20 +- packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/test/dart_generator_test.dart | 13 +- packages/pigeon/tool/run_tests.dart | 1 - packages/pigeon/tool/shared/test_suites.dart | 22 -- packages/pigeon/tool/test.dart | 1 - 17 files changed, 41 insertions(+), 487 deletions(-) delete mode 100644 packages/pigeon/mock_handler_tester/.gitignore delete mode 100644 packages/pigeon/mock_handler_tester/.metadata delete mode 100644 packages/pigeon/mock_handler_tester/README.md delete mode 100644 packages/pigeon/mock_handler_tester/lib/main.dart delete mode 100644 packages/pigeon/mock_handler_tester/pubspec.yaml delete mode 100644 packages/pigeon/mock_handler_tester/test/message.dart rename packages/pigeon/{mock_handler_tester/test/widget_test.dart => platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart} (83%) rename packages/pigeon/{mock_handler_tester/test/test.dart => platform_tests/shared_test_plugin_code/test/test_message.gen.dart} (86%) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index cdf4c488f2..1cd0806090 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.1.5 + +* Fixes import in generated Dart test output when overriding package name. + ## 10.1.4 * Adds package name to method channel strings to avoid potential collisions between plugins. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 2c40a8ddec..d712ee5468 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -599,6 +599,7 @@ if (replyList == null) { Root root, StringSink sink, { required String dartPackageName, + required String dartOutputPackageName, }) { final Indent indent = Indent(sink); final String sourceOutPath = generatorOptions.sourceOutPath ?? ''; @@ -620,7 +621,7 @@ if (replyList == null) { } else { final String path = relativeDartPath.replaceFirst(RegExp(r'^.*/lib/'), ''); - indent.writeln("import 'package:$dartPackageName/$path';"); + indent.writeln("import 'package:$dartOutputPackageName/$path';"); } for (final Api api in root.apis) { if (api.location == ApiLocation.host && api.dartHostTestHandler != null) { diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index b7b9107b80..62113aeef6 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '10.1.4'; +const String pigeonVersion = '10.1.5'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 2fca07a05b..ae5d7ad346 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -510,11 +510,16 @@ class DartTestGeneratorAdapter implements GeneratorAdapter { basePath: options.basePath ?? '', ); const DartGenerator testGenerator = DartGenerator(); + // The test code needs the actual package name of the Dart output, even if + // the package name has been overridden for other uses. + final String outputPackageName = + deducePackageName(options.dartOut ?? '') ?? options.getPackageName(); testGenerator.generateTest( dartOptionsWithHeader, root, sink, dartPackageName: options.getPackageName(), + dartOutputPackageName: outputPackageName, ); } diff --git a/packages/pigeon/mock_handler_tester/.gitignore b/packages/pigeon/mock_handler_tester/.gitignore deleted file mode 100644 index f3c205341e..0000000000 --- a/packages/pigeon/mock_handler_tester/.gitignore +++ /dev/null @@ -1,44 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -**/ios/Flutter/.last_build_id -.dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies -.packages -.pub-cache/ -.pub/ -/build/ - -# Web related -lib/generated_plugin_registrant.dart - -# Symbolication related -app.*.symbols - -# Obfuscation related -app.*.map.json - -# Exceptions to above rules. -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/packages/pigeon/mock_handler_tester/.metadata b/packages/pigeon/mock_handler_tester/.metadata deleted file mode 100644 index bb4f09ae75..0000000000 --- a/packages/pigeon/mock_handler_tester/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: e6b697a9df5e9ce933024be3334e86b599c60e71 - channel: unknown - -project_type: app diff --git a/packages/pigeon/mock_handler_tester/README.md b/packages/pigeon/mock_handler_tester/README.md deleted file mode 100644 index 698b506511..0000000000 --- a/packages/pigeon/mock_handler_tester/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# mock_handler_tester - -A test bed for testing the code generated by `dartHostTestHandler`. diff --git a/packages/pigeon/mock_handler_tester/lib/main.dart b/packages/pigeon/mock_handler_tester/lib/main.dart deleted file mode 100644 index b8ddfeba46..0000000000 --- a/packages/pigeon/mock_handler_tester/lib/main.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; - -void main() { - runApp(Container()); -} diff --git a/packages/pigeon/mock_handler_tester/pubspec.yaml b/packages/pigeon/mock_handler_tester/pubspec.yaml deleted file mode 100644 index 69eba8468a..0000000000 --- a/packages/pigeon/mock_handler_tester/pubspec.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: mock_handler_tester -description: A testbed for testing dartHostTestHandler. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 1.0.0+1 - -environment: - sdk: ">=2.18.0 <4.0.0" - flutter: ">=3.3.0" - -dependencies: - cupertino_icons: ^1.0.2 - flutter: - sdk: flutter - -dev_dependencies: - flutter_test: - sdk: flutter - -flutter: - uses-material-design: true diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart deleted file mode 100644 index 3a330815b3..0000000000 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Autogenerated from Pigeon (v10.1.4), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import - -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; - -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; - -/// This comment is to test enum documentation comments. -/// -/// This comment also tests multiple line comments. -/// -/// //////////////////////// -/// This comment also tests comments that start with '/' -/// //////////////////////// -enum MessageRequestState { - pending, - success, - failure, -} - -/// This comment is to test class documentation comments. -/// -/// This comment also tests multiple line comments. -class MessageSearchRequest { - MessageSearchRequest({ - this.query, - this.anInt, - this.aBool, - }); - - /// This comment is to test field documentation comments. - String? query; - - /// This comment is to test field documentation comments. - int? anInt; - - /// This comment is to test field documentation comments. - bool? aBool; - - Object encode() { - return [ - query, - anInt, - aBool, - ]; - } - - static MessageSearchRequest decode(Object result) { - result as List; - return MessageSearchRequest( - query: result[0] as String?, - anInt: result[1] as int?, - aBool: result[2] as bool?, - ); - } -} - -/// This comment is to test class documentation comments. -class MessageSearchReply { - MessageSearchReply({ - this.result, - this.error, - this.state, - }); - - /// This comment is to test field documentation comments. - /// - /// This comment also tests multiple line comments. - String? result; - - /// This comment is to test field documentation comments. - String? error; - - /// This comment is to test field documentation comments. - MessageRequestState? state; - - Object encode() { - return [ - result, - error, - state?.index, - ]; - } - - static MessageSearchReply decode(Object result) { - result as List; - return MessageSearchReply( - result: result[0] as String?, - error: result[1] as String?, - state: result[2] != null - ? MessageRequestState.values[result[2]! as int] - : null, - ); - } -} - -/// This comment is to test class documentation comments. -class MessageNested { - MessageNested({ - this.request, - }); - - /// This comment is to test field documentation comments. - MessageSearchRequest? request; - - Object encode() { - return [ - request?.encode(), - ]; - } - - static MessageNested decode(Object result) { - result as List; - return MessageNested( - request: result[0] != null - ? MessageSearchRequest.decode(result[0]! as List) - : null, - ); - } -} - -class _MessageApiCodec extends StandardMessageCodec { - const _MessageApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageSearchReply.decode(readValue(buffer)!); - case 129: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// This comment is to test api documentation comments. -/// -/// This comment also tests multiple line comments. -class MessageApi { - /// Constructor for [MessageApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - MessageApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _MessageApiCodec(); - - /// This comment is to test documentation comments. - /// - /// This comment also tests multiple line comments. - Future initialize() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.initialize', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - /// This comment is to test method documentation comments. - Future search(MessageSearchRequest arg_request) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.search', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_request]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as MessageSearchReply?)!; - } - } -} - -class _MessageNestedApiCodec extends StandardMessageCodec { - const _MessageNestedApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageNested) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchReply) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageNested.decode(readValue(buffer)!); - case 129: - return MessageSearchReply.decode(readValue(buffer)!); - case 130: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// This comment is to test api documentation comments. -class MessageNestedApi { - /// Constructor for [MessageNestedApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - MessageNestedApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _MessageNestedApiCodec(); - - /// This comment is to test method documentation comments. - /// - /// This comment also tests multiple line comments. - Future search(MessageNested arg_nested) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageNestedApi.search', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_nested]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as MessageSearchReply?)!; - } - } -} - -class _MessageFlutterSearchApiCodec extends StandardMessageCodec { - const _MessageFlutterSearchApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is MessageSearchReply) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is MessageSearchRequest) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return MessageSearchReply.decode(readValue(buffer)!); - case 129: - return MessageSearchRequest.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// This comment is to test api documentation comments. -abstract class MessageFlutterSearchApi { - static const MessageCodec codec = _MessageFlutterSearchApiCodec(); - - /// This comment is to test method documentation comments. - MessageSearchReply search(MessageSearchRequest request); - - static void setup(MessageFlutterSearchApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageFlutterSearchApi.search', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageFlutterSearchApi.search was null.'); - final List args = (message as List?)!; - final MessageSearchRequest? arg_request = - (args[0] as MessageSearchRequest?); - assert(arg_request != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageFlutterSearchApi.search was null, expected non-null MessageSearchRequest.'); - final MessageSearchReply output = api.search(arg_request!); - return output; - }); - } - } - } -} diff --git a/packages/pigeon/mock_handler_tester/test/widget_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart similarity index 83% rename from packages/pigeon/mock_handler_tester/test/widget_test.dart rename to packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart index bb0af44843..a0632cf348 100644 --- a/packages/pigeon/mock_handler_tester/test/widget_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/genered_dart_test_code_test.dart @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// This file specifically tests the test code generated by dartTestOut. + import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_test_plugin_code/src/generated/message.gen.dart'; -import 'message.dart'; -import 'test.dart'; +import 'test_message.gen.dart'; class Mock implements TestHostApi { List log = []; @@ -74,14 +76,14 @@ void main() { TestHostApi.setup(mock); expect( await const BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.initialize', + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize', StandardMessageCodec(), ).send([null]), isEmpty, ); try { await const BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.search', + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search', StandardMessageCodec(), ).send([null]) as List?; expect(true, isFalse); // should not reach here @@ -90,7 +92,7 @@ void main() { expect( error.toString(), contains( - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageApi.search was null, expected non-null MessageSearchRequest.', + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search was null, expected non-null MessageSearchRequest.', ), ); } diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart similarity index 86% rename from packages/pigeon/mock_handler_tester/test/test.dart rename to packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart index a6cf4682bd..ff3a3d9c89 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/test_message.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v10.1.4), do not edit directly. +// Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports @@ -12,7 +12,7 @@ import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'message.dart'; +import 'package:shared_test_plugin_code/src/generated/message.gen.dart'; class _TestHostApiCodec extends StandardMessageCodec { const _TestHostApiCodec(); @@ -61,7 +61,8 @@ abstract class TestHostApi { static void setup(TestHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.initialize', codec, + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize', + codec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger @@ -78,7 +79,8 @@ abstract class TestHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageApi.search', codec, + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search', + codec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger @@ -88,12 +90,12 @@ abstract class TestHostApi { .setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageApi.search was null.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search was null.'); final List args = (message as List?)!; final MessageSearchRequest? arg_request = (args[0] as MessageSearchRequest?); assert(arg_request != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageApi.search was null, expected non-null MessageSearchRequest.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search was null, expected non-null MessageSearchRequest.'); final MessageSearchReply output = api.search(arg_request!); return [output]; }); @@ -149,7 +151,7 @@ abstract class TestNestedApi { static void setup(TestNestedApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.mock_handler_tester.MessageNestedApi.search', + 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search', codec, binaryMessenger: binaryMessenger); if (api == null) { @@ -160,11 +162,11 @@ abstract class TestNestedApi { .setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageNestedApi.search was null.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search was null.'); final List args = (message as List?)!; final MessageNested? arg_nested = (args[0] as MessageNested?); assert(arg_nested != null, - 'Argument for dev.flutter.pigeon.mock_handler_tester.MessageNestedApi.search was null, expected non-null MessageNested.'); + 'Argument for dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search was null, expected non-null MessageNested.'); final MessageSearchReply output = api.search(arg_nested!); return [output]; }); diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index a59786e19a..90c81d7287 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 10.1.4 # This must match the version in lib/generator_tools.dart +version: 10.1.5 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 9fbd5b53ff..be31794a74 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -686,6 +686,7 @@ void main() { root, testCodeSink, dartPackageName: DEFAULT_PACKAGE_NAME, + dartOutputPackageName: DEFAULT_PACKAGE_NAME, ); final String testCode = testCodeSink.toString(); expect(testCode, contains(r"import 'fo\'o.dart';")); @@ -1351,7 +1352,10 @@ void main() { expect(code, contains('void doit(int? foo);')); }); - test('uses defined package name', () { + test('uses output package name for imports', () { + const String overriddenPackageName = 'custom_name'; + const String outputPackageName = 'some_output_package'; + assert(outputPackageName != DEFAULT_PACKAGE_NAME); final Directory tempDir = Directory.systemTemp.createTempSync('pigeon'); try { final Directory foo = Directory(path.join(tempDir.path, 'lib', 'foo')); @@ -1371,10 +1375,12 @@ name: foobar ), root, sink, - dartPackageName: DEFAULT_PACKAGE_NAME, + dartPackageName: overriddenPackageName, + dartOutputPackageName: outputPackageName, ); final String code = sink.toString(); - expect(code, contains("import 'package:test_package/foo/bar.dart';")); + expect( + code, contains("import 'package:$outputPackageName/foo/bar.dart';")); } finally { tempDir.deleteSync(recursive: true); } @@ -1598,6 +1604,7 @@ name: foobar root, sink, dartPackageName: DEFAULT_PACKAGE_NAME, + dartOutputPackageName: DEFAULT_PACKAGE_NAME, ); final String testCode = sink.toString(); diff --git a/packages/pigeon/tool/run_tests.dart b/packages/pigeon/tool/run_tests.dart index 9b0ce7aecb..0d7523bae9 100644 --- a/packages/pigeon/tool/run_tests.dart +++ b/packages/pigeon/tool/run_tests.dart @@ -160,7 +160,6 @@ Future> _modifiedFiles( Future main(List args) async { // Run most tests on Linux, since Linux tends to be the easiest and cheapest. const List linuxHostTests = [ - mockHandlerTests, commandLineTests, androidJavaUnitTests, androidJavaLint, diff --git a/packages/pigeon/tool/shared/test_suites.dart b/packages/pigeon/tool/shared/test_suites.dart index 658c4c083f..5e45c31ff5 100644 --- a/packages/pigeon/tool/shared/test_suites.dart +++ b/packages/pigeon/tool/shared/test_suites.dart @@ -50,7 +50,6 @@ const String windowsUnitTests = 'windows_unittests'; const String windowsIntegrationTests = 'windows_integration_tests'; const String dartUnitTests = 'dart_unittests'; const String flutterUnitTests = 'flutter_unittests'; -const String mockHandlerTests = 'mock_handler_tests'; const String commandLineTests = 'command_line_tests'; const Map testSuites = { @@ -101,9 +100,6 @@ const Map testSuites = { macOSSwiftIntegrationTests: TestInfo( function: _runMacOSSwiftIntegrationTests, description: 'Integration tests on generated Swift code on macOS.'), - mockHandlerTests: TestInfo( - function: _runMockHandlerTests, - description: 'Unit tests on generated Dart mock handler code.'), commandLineTests: TestInfo( function: _runCommandLineTests, description: 'Tests running pigeon with various command-line options.'), @@ -310,24 +306,6 @@ Future _runIOSSwiftIntegrationTests() async { return _runMobileIntegrationTests('iOS', _testPluginRelativePath); } -Future _runMockHandlerTests() async { - const String unitTestsPath = './mock_handler_tester'; - final int generateCode = await runPigeon( - input: './pigeons/message.dart', - dartOut: './mock_handler_tester/test/message.dart', - dartTestOut: './mock_handler_tester/test/test.dart', - ); - if (generateCode != 0) { - return generateCode; - } - - final int testCode = await runFlutterCommand(unitTestsPath, 'test'); - if (testCode != 0) { - return testCode; - } - return 0; -} - Future _runWindowsUnitTests() async { const String examplePath = './$_testPluginRelativePath/example'; final int compileCode = await runFlutterBuild(examplePath, 'windows'); diff --git a/packages/pigeon/tool/test.dart b/packages/pigeon/tool/test.dart index 9e31363a97..3667f44e78 100644 --- a/packages/pigeon/tool/test.dart +++ b/packages/pigeon/tool/test.dart @@ -57,7 +57,6 @@ ${parser.usage}'''); const List dartTests = [ dartUnitTests, flutterUnitTests, - mockHandlerTests, commandLineTests, ]; const List androidTests = [