-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
gaaclarke
commented
May 8, 2020
•
edited
Loading
edited
- cleaned up objc generation
- added ability to generate mock handlers
- added pigeon.dart
7c1f29d
to
5f74659
Compare
@@ -0,0 +1,147 @@ | |||
// Autogenerated from Pigeon (v0.1.0), do not edit directly. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
packages/pigeon/lib/pigeon_lib.dart
Outdated
@@ -30,7 +30,11 @@ const List<String> _validTypes = <String>[ | |||
/// Metadata to mark an API which will be implemented on the host platform. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
packages/pigeon/pigeons/message.dart
Outdated
@@ -15,7 +15,7 @@ class SearchReply { | |||
String error; | |||
} | |||
|
|||
@HostApi() | |||
@HostApi(mockDartHandler: 'MockApi') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
packages/pigeon/lib/pigeon_lib.dart
Outdated
const HostApi(); | ||
const HostApi({this.mockDartHandler}); | ||
|
||
/// The name of the interface to generate to receive Pigeon messages locally |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packages/pigeon/lib/pigeon_lib.dart
Outdated
|
||
/// The name of the interface to generate to receive Pigeon messages locally | ||
/// for testing. | ||
final String mockDartHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dartTestHandler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as noted above
There was a problem hiding this comment.
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
@xster I think I addressed all the comments. There may still be a question about |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
packages/pigeon/lib/pigeon_lib.dart
Outdated
|
||
/// The name of the interface to generate to receive Pigeon messages locally | ||
/// for testing. | ||
final String mockDartHandler; |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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
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. |