Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pigeon]: version 0.1.0 (objc and testing features) #152

Merged
merged 7 commits into from
May 27, 2020

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented May 8, 2020

  • cleaned up objc generation
  • added ability to generate mock handlers
  • added pigeon.dart

@gaaclarke gaaclarke force-pushed the pigeon-0.1.0 branch 3 times, most recently from 7c1f29d to 5f74659 Compare May 11, 2020 17:06
@@ -0,0 +1,147 @@
// Autogenerated from Pigeon (v0.1.0), do not edit directly.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file gets regenerated when running run_tests.sh. I still don't have the time to invest in creating a mechanism to generate these during standard execution of the tests.

@gaaclarke gaaclarke marked this pull request as ready for review May 11, 2020 17:07
@gaaclarke gaaclarke requested a review from xster May 11, 2020 17:09
Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General approach LGTM. The naming and docs need some more tweaking.

@@ -30,7 +30,11 @@ const List<String> _validTypes = <String>[
/// Metadata to mark an API which will be implemented on the host platform.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a bit more explicit? Since this is our canonical code doc that people can cmd+click into when they see the annotation.

Something like

Annotates a platform implemented Pigeon API class.

This class groups a collection of Dart↔platform interop methods. These methods are to be 
invoked by a Dart-side program and are to be received by a platform-side program (such 
as in Android or iOS) by an implementation class inheriting this class. 

or some such?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


* Added pigeon.dart.
* Fixed some Obj-C linter problems.
* Added the ability to generate a mock handler in Dart.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, we should be careful with the terminology to avoid confusion. What you're adding here isn't quite a mock which is a stand-in for a real object and that just registers calls. What this PR does doesn't replace the real object. It just adds a matched object that "works" and that's different from the real implementation. i.e. it's a fake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is merit to what you are saying but mock is the terminology used by channels, that's why I chose it (https://api.flutter.dev/flutter/services/MethodChannel/setMockMethodCallHandler.html)

@@ -15,7 +15,7 @@ class SearchReply {
String error;
}

@HostApi()
@HostApi(mockDartHandler: 'MockApi')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this creates a second class which is exactly the same as the FlutterSearchApi class a bit further down in this file which will make people ask why there's 2 ways of doing the same thing. This file should have more docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly the same but close. I added a comment at the top.

SearchReply search(SearchRequest arg);
}

void MockApiSetup(MockApi api) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not call it mock since it's not mocking Api and ApiSetup. If you're still using the real Api and using this as the receiving side, let's just call it ApiTestHandler in this example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"mock handler" is already used terminology for the same concept elsewhere: https://api.flutter.dev/flutter/services/MethodChannel/setMockMethodCallHandler.html

Copy link
Member

@xster xster May 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see where you're going. That thing is a mock though. It's taking a production class and swapping it out for an alternate one which records and stubs interactions.

This doesn't replace a production class. It's used in parallel with the production class and is a separate "working" class that has a different behavior than the real one.

It'd be like we had client and server and we want to test client. We can have a mockClient which is what we all want but since we can't do it easily for existing tests, we're using client with a fakeServer. But if we do, we can't make the fakeServer be named mockClient. That would be really confusing.

We can call this TestHost[name of API] for instance. Since we're specifically doing the 'host' part of the class annotated by HostApi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this class to TestHostApi.

SearchReply search(SearchRequest arg);
}

void MockApiSetup(MockApi api) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, can we fix this and the normal static setup method to use camel case naming?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to MockApi.setup().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I like it. What about the production class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, same.

SearchReply search(SearchRequest arg);
}

void MockApiSetup(MockApi api) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this specific static method, it should be a verb rather than a noun. Perhaps flip the naming to put setup in front. e.g. setupApiTestHandler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to MockApi.setup().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

const HostApi();
const HostApi({this.mockDartHandler});

/// The name of the interface to generate to receive Pigeon messages locally
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some more details. Such as

This interface will be placed along side the [HostApi] class. You can implement this
interface and invoke `setup[name of this test handler]` to receive calls from your real 
[HostApi] class in Dart instead of the host platform code as is the case typically. 

Generally, opt to use a mock of the real [HostApi], such as via mockito, in unit testing. 
But generating this Dart side test handler could sometimes be useful in integration testing. 

Defaults to `null` in which case no test handler will be generated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/// The name of the interface to generate to receive Pigeon messages locally
/// for testing.
final String mockDartHandler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dartTestHandler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as noted above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still call this dartHostTestHandler

- added ability to generate mock handlers
- added pigeon.dart
@gaaclarke gaaclarke requested a review from xster May 15, 2020 21:10
@gaaclarke
Copy link
Member Author

@xster I think I addressed all the comments. There may still be a question about mockDartHandler let me know if that's still the case and what you decided you'd like it to be. It will be a bit of a pain to change it and want to make sure to get it right.

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % the field name on the annotation

final SearchReply output = api.search(input);
return output._toMap();
});
static void setup(FlutterSearchApi api) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! We should note the need to call this in the package's README

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised though that it's in this abstract FlutterSearchApi class rather than being in Api.

@@ -128,3 +128,20 @@ class Api {
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR but I don' think we should do it soon. We should doc annotate the output classes, especially since we decided that the person writing the pigeon file might not be the person consuming these Dart/Java/ObjC classes and the latter could use some help in knowing what to do with these.

const HostApi();
const HostApi({this.mockDartHandler});

/// The name of an interface generated next to the [HostApi] class. Implement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here and elsewhere, there's a bunch of double spaces.


/// The name of the interface to generate to receive Pigeon messages locally
/// for testing.
final String mockDartHandler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still call this dartHostTestHandler

@@ -0,0 +1,3 @@
# mock_handler_tester

A test bed for testing the code generated by `mockDartHandler`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you rename it, keep the name consistent here and below

@gaaclarke
Copy link
Member Author

Landing before build-ipa's task finish. They seem to be fubar, saying stuff about upgrading xcode but showing no progress. Those tests previously passed before my renaming of the field.

@gaaclarke gaaclarke merged commit 18b52ae into flutter:master May 27, 2020
stuartmorgan pushed a commit to stuartmorgan/packages that referenced this pull request Apr 30, 2021
stuartmorgan pushed a commit that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants