Skip to content

Commit 82158e8

Browse files
authored
[pigeon] Fix pigeon test generation missing wrapResponse method. (#5903)
Pigeon was not generating the wrapResponse method, and therefore failing compilation of the generated tests. Fixes: flutter/flutter#141499
1 parent bf0752a commit 82158e8

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 16.0.1
2+
3+
* [dart] Fixes test generation for missing wrapResponse method if only host Api.
4+
15
## 16.0.0
26

37
* [java] Adds `VoidResult` type for `Void` returns.

packages/pigeon/lib/dart_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ if (${_varNamePrefix}replyList == null) {
704704
if (hasHostApi) {
705705
_writeCreateConnectionError(indent);
706706
}
707-
if (hasFlutterApi) {
707+
if (hasFlutterApi || generatorOptions.testOutPath != null) {
708708
_writeWrapResponse(generatorOptions, root, indent);
709709
}
710710
}

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'ast.dart';
1313
/// The current version of pigeon.
1414
///
1515
/// This must match the version in pubspec.yaml.
16-
const String pigeonVersion = '16.0.0';
16+
const String pigeonVersion = '16.0.1';
1717

1818
/// Read all the content from [stdin] to a String.
1919
String readStdin() {

packages/pigeon/lib/pigeon_lib.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ class DartGeneratorAdapter implements GeneratorAdapter {
474474
final DartOptions dartOptionsWithHeader = _dartOptionsWithCopyrightHeader(
475475
options.dartOptions,
476476
options.copyrightHeader,
477+
testOutPath: options.dartTestOut,
477478
basePath: options.basePath ?? '',
478479
);
479480
const DartGenerator generator = DartGenerator();

packages/pigeon/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
5-
version: 16.0.0 # This must match the version in lib/generator_tools.dart
5+
version: 16.0.1 # This must match the version in lib/generator_tools.dart
66

77
environment:
88
sdk: ">=3.0.0 <4.0.0"

packages/pigeon/test/dart_generator_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,4 +1746,36 @@ name: foobar
17461746
contains(
17471747
'\'Unable to establish connection on channel: "\$channelName".\''));
17481748
});
1749+
1750+
test('generate wrapResponse if is generating tests', () {
1751+
final Root root = Root(
1752+
apis: <Api>[
1753+
Api(
1754+
name: 'Api',
1755+
location: ApiLocation.host,
1756+
dartHostTestHandler: 'ApiMock',
1757+
methods: <Method>[
1758+
Method(
1759+
name: 'foo',
1760+
returnType: const TypeDeclaration.voidDeclaration(),
1761+
parameters: <Parameter>[])
1762+
])
1763+
],
1764+
classes: <Class>[],
1765+
enums: <Enum>[],
1766+
);
1767+
1768+
final StringBuffer mainCodeSink = StringBuffer();
1769+
const DartGenerator generator = DartGenerator();
1770+
generator.generate(
1771+
const DartOptions(
1772+
testOutPath: 'test.dart',
1773+
),
1774+
root,
1775+
mainCodeSink,
1776+
dartPackageName: DEFAULT_PACKAGE_NAME,
1777+
);
1778+
final String mainCode = mainCodeSink.toString();
1779+
expect(mainCode, contains('List<Object?> wrapResponse('));
1780+
});
17491781
}

0 commit comments

Comments
 (0)