@@ -119,6 +119,21 @@ void main() {
119119 });
120120 });
121121
122+ test ('warns when a non-standalone builder does not see "part"' , () async {
123+ var srcs =
124+ _createPackageStub (pkgName, testLibContent: _testLibContentNoPart);
125+ var builder = new GeneratorBuilder ([const CommentGenerator ()]);
126+ var logs = < String > [];
127+ await testBuilder (
128+ builder,
129+ srcs,
130+ onLog: (log) {
131+ logs.add (log.message);
132+ },
133+ );
134+ expect (logs, ['Missing "part \' test_lib.g.dart\' ;".' ]);
135+ });
136+
122137 test ('defaults to formatting generated code with the DartFormatter' ,
123138 () async {
124139 await testBuilder (new GeneratorBuilder ([new UnformattedCodeGenerator ()]),
@@ -167,16 +182,16 @@ Future _generateTest(CommentGenerator gen, String expectedContent) async {
167182 generateFor: new Set .from (['$pkgName |lib/test_lib.dart' ]),
168183 outputs: {
169184 '$pkgName |lib/test_lib.g.dart' : expectedContent,
170- });
185+ },
186+ onLog: (log) => fail ('Unexpected log message: ${log .message }' ));
171187}
172188
173189/// Creates a package using [pkgName] .
174190Map <String , String > _createPackageStub (String pkgName,
175191 {String testLibContent, String testLibPartContent}) {
176192 return {
177193 '$pkgName |lib/test_lib.dart' : testLibContent ?? _testLibContent,
178- '$pkgName |lib/test_lib_part.dart' :
179- testLibPartContent ?? _testLibPartContent,
194+ '$pkgName |lib/test_lib.g.dart' : testLibPartContent ?? _testLibPartContent,
180195 };
181196}
182197
@@ -200,14 +215,20 @@ const pkgName = 'pkg';
200215
201216const _testLibContent = r'''
202217library test_lib;
203- part 'test_lib_part.dart';
218+ part 'test_lib.g.dart';
219+ final int foo = 42;
220+ class Person { }
221+ ''' ;
222+
223+ const _testLibContentNoPart = r'''
224+ library test_lib;
204225final int foo = 42;
205226class Person { }
206227''' ;
207228
208229const _testLibContentWithError = r'''
209230library test_lib;
210- part 'test_lib_part .dart';
231+ part 'test_lib.g .dart';
211232class MyError { }
212233class MyGoodError { }
213234''' ;
0 commit comments