@@ -121,11 +121,14 @@ void main() {
121
121
group ('Tools' , () {
122
122
Class toolUser;
123
123
Class _NonCanonicalToolUser , CanonicalToolUser , PrivateLibraryToolUser ;
124
+ Class ImplementingClassForTool , CanonicalPrivateInheritedToolUser ;
124
125
Method invokeTool;
125
126
Method invokeToolNoInput;
126
127
Method invokeToolMultipleSections;
127
128
Method invokeToolNonCanonical, invokeToolNonCanonicalSubclass;
128
129
Method invokeToolPrivateLibrary, invokeToolPrivateLibraryOriginal;
130
+ Method invokeToolParentDoc, invokeToolParentDocOriginal;
131
+ final RegExp packageInvocationIndexRegexp = new RegExp (r'PACKAGE_INVOCATION_INDEX: (\d+)' );
129
132
130
133
setUpAll (() {
131
134
_NonCanonicalToolUser = fakeLibrary.allClasses
@@ -134,6 +137,10 @@ void main() {
134
137
.firstWhere ((c) => c.name == 'CanonicalToolUser' );
135
138
PrivateLibraryToolUser = fakeLibrary.allClasses
136
139
.firstWhere ((c) => c.name == 'PrivateLibraryToolUser' );
140
+ ImplementingClassForTool = fakeLibrary.allClasses
141
+ .firstWhere ((c) => c.name == 'ImplementingClassForTool' );
142
+ CanonicalPrivateInheritedToolUser = fakeLibrary.allClasses
143
+ .firstWhere ((c) => c.name == 'CanonicalPrivateInheritedToolUser' );
137
144
toolUser = exLibrary.classes.firstWhere ((c) => c.name == 'ToolUser' );
138
145
invokeTool =
139
146
toolUser.allInstanceMethods.firstWhere ((m) => m.name == 'invokeTool' );
@@ -151,24 +158,48 @@ void main() {
151
158
(invokeToolPrivateLibrary.definingEnclosingElement as Class )
152
159
.allInstanceMethods
153
160
.firstWhere ((m) => m.name == 'invokeToolPrivateLibrary' );
161
+ invokeToolParentDoc = CanonicalPrivateInheritedToolUser .allInstanceMethods
162
+ .firstWhere ((m) => m.name == 'invokeToolParentDoc' );
163
+ invokeToolParentDocOriginal = ImplementingClassForTool .allInstanceMethods
164
+ .firstWhere ((m) => m.name == 'invokeToolParentDoc' );
154
165
packageGraph.allLocalModelElements.forEach ((m) => m.documentation);
155
166
});
156
167
157
- test ('does _not_ invoke a tool multiple times unnecessarily' , () {
158
- RegExp packageInvocationIndexRegexp =
159
- new RegExp (r'PACKAGE_INVOCATION_INDEX: (\d+)' );
160
- expect (invokeToolNonCanonical.isCanonical, isFalse);
161
- expect (invokeToolNonCanonicalSubclass.isCanonical, isTrue);
162
- expect (
163
- packageInvocationIndexRegexp
164
- .firstMatch (invokeToolNonCanonical.documentation)
165
- .group (1 ),
166
- equals (packageInvocationIndexRegexp
167
- .firstMatch (invokeToolNonCanonicalSubclass.documentation)
168
- .group (1 )));
169
- expect (invokeToolPrivateLibrary.documentation, isNot (contains ('{@tool' )));
170
- expect (
171
- invokeToolPrivateLibraryOriginal.documentation, contains ('{@tool' ));
168
+ test ('invokes tool when inherited documentation is the only means for it to be seen' , () {
169
+ // Verify setup of the test is correct.
170
+ expect (invokeToolParentDoc.isCanonical, isTrue);
171
+ expect (invokeToolParentDoc.documentationComment, isNull);
172
+ // Error message here might look strange due to toString() on Methods, but if this
173
+ // fails that means we don't have the correct invokeToolParentDoc instance.
174
+ expect (invokeToolParentDoc.documentationFrom, contains (invokeToolParentDocOriginal));
175
+ // Tool should be substituted out here.
176
+ expect (invokeToolParentDoc.documentation, isNot (contains ('{@tool' )));
177
+ });
178
+
179
+ group ('does _not_ invoke a tool multiple times unnecessarily' , () {
180
+ test ('non-canonical subclass case' , () {
181
+ expect (invokeToolNonCanonical.isCanonical, isFalse);
182
+ expect (invokeToolNonCanonicalSubclass.isCanonical, isTrue);
183
+ expect (
184
+ packageInvocationIndexRegexp
185
+ .firstMatch (invokeToolNonCanonical.documentation)
186
+ .group (1 ),
187
+ equals (packageInvocationIndexRegexp
188
+ .firstMatch (invokeToolNonCanonicalSubclass.documentation)
189
+ .group (1 )));
190
+ expect (invokeToolPrivateLibrary.documentation, isNot (contains ('{@tool' )));
191
+ expect (
192
+ invokeToolPrivateLibraryOriginal.documentation, contains ('{@tool' ));
193
+ });
194
+
195
+ test ('Documentation borrowed from implementer case' , () {
196
+ expect (packageInvocationIndexRegexp
197
+ .firstMatch (invokeToolParentDoc.documentation)
198
+ .group (1 ),
199
+ equals (packageInvocationIndexRegexp
200
+ .firstMatch (invokeToolParentDocOriginal.documentation)
201
+ .group (1 )));
202
+ });
172
203
});
173
204
174
205
test ('can invoke a tool and pass args and environment' , () {
0 commit comments