Skip to content

Commit b2a30a3

Browse files
[pigeon] Consolidate mock handler tests (flutter#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.
1 parent ff81b82 commit b2a30a3

File tree

17 files changed

+41
-487
lines changed

17 files changed

+41
-487
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+
## 10.1.5
2+
3+
* Fixes import in generated Dart test output when overriding package name.
4+
15
## 10.1.4
26

37
* Adds package name to method channel strings to avoid potential collisions between plugins.

packages/pigeon/lib/dart_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ if (replyList == null) {
599599
Root root,
600600
StringSink sink, {
601601
required String dartPackageName,
602+
required String dartOutputPackageName,
602603
}) {
603604
final Indent indent = Indent(sink);
604605
final String sourceOutPath = generatorOptions.sourceOutPath ?? '';
@@ -620,7 +621,7 @@ if (replyList == null) {
620621
} else {
621622
final String path =
622623
relativeDartPath.replaceFirst(RegExp(r'^.*/lib/'), '');
623-
indent.writeln("import 'package:$dartPackageName/$path';");
624+
indent.writeln("import 'package:$dartOutputPackageName/$path';");
624625
}
625626
for (final Api api in root.apis) {
626627
if (api.location == ApiLocation.host && api.dartHostTestHandler != null) {

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 = '10.1.4';
16+
const String pigeonVersion = '10.1.5';
1717

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

packages/pigeon/lib/pigeon_lib.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,16 @@ class DartTestGeneratorAdapter implements GeneratorAdapter {
510510
basePath: options.basePath ?? '',
511511
);
512512
const DartGenerator testGenerator = DartGenerator();
513+
// The test code needs the actual package name of the Dart output, even if
514+
// the package name has been overridden for other uses.
515+
final String outputPackageName =
516+
deducePackageName(options.dartOut ?? '') ?? options.getPackageName();
513517
testGenerator.generateTest(
514518
dartOptionsWithHeader,
515519
root,
516520
sink,
517521
dartPackageName: options.getPackageName(),
522+
dartOutputPackageName: outputPackageName,
518523
);
519524
}
520525

packages/pigeon/mock_handler_tester/.gitignore

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/pigeon/mock_handler_tester/.metadata

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/pigeon/mock_handler_tester/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/pigeon/mock_handler_tester/lib/main.dart

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/pigeon/mock_handler_tester/pubspec.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)