@@ -121,11 +121,14 @@ void main() {
121121 group ('Tools' , () {
122122 Class toolUser;
123123 Class _NonCanonicalToolUser , CanonicalToolUser , PrivateLibraryToolUser ;
124+ Class ImplementingClassForTool , CanonicalPrivateInheritedToolUser ;
124125 Method invokeTool;
125126 Method invokeToolNoInput;
126127 Method invokeToolMultipleSections;
127128 Method invokeToolNonCanonical, invokeToolNonCanonicalSubclass;
128129 Method invokeToolPrivateLibrary, invokeToolPrivateLibraryOriginal;
130+ Method invokeToolParentDoc, invokeToolParentDocOriginal;
131+ final RegExp packageInvocationIndexRegexp = new RegExp (r'PACKAGE_INVOCATION_INDEX: (\d+)' );
129132
130133 setUpAll (() {
131134 _NonCanonicalToolUser = fakeLibrary.allClasses
@@ -134,6 +137,10 @@ void main() {
134137 .firstWhere ((c) => c.name == 'CanonicalToolUser' );
135138 PrivateLibraryToolUser = fakeLibrary.allClasses
136139 .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' );
137144 toolUser = exLibrary.classes.firstWhere ((c) => c.name == 'ToolUser' );
138145 invokeTool =
139146 toolUser.allInstanceMethods.firstWhere ((m) => m.name == 'invokeTool' );
@@ -151,24 +158,48 @@ void main() {
151158 (invokeToolPrivateLibrary.definingEnclosingElement as Class )
152159 .allInstanceMethods
153160 .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' );
154165 packageGraph.allLocalModelElements.forEach ((m) => m.documentation);
155166 });
156167
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+ });
172203 });
173204
174205 test ('can invoke a tool and pass args and environment' , () {
0 commit comments