@@ -174,10 +174,11 @@ text that should be removed from the file. */''';
174
174
const existingLicenseText = '''// This is some multiline license text to
175
175
// remove that does not contain a stored value.''' ;
176
176
const replacementLicenseText =
177
- '''// This is some <value4 > multiline license
177
+ '''// This is some <value > multiline license
178
178
// text that should be added to the file.''' ;
179
179
180
- final replacementInfo = await _getTestReplacementInfo (
180
+ // Contains existing license
181
+ var replacementInfo = await _getTestReplacementInfo (
181
182
testFile: testFile10,
182
183
existingLicenseText: existingLicenseText,
183
184
replacementLicenseText: replacementLicenseText,
@@ -200,6 +201,20 @@ text that should be removed from the file. */''';
200
201
replacementInfo.replacementHeader,
201
202
equals (expectedReplacementHeader),
202
203
);
204
+
205
+ // Missing existing license
206
+ replacementInfo = await _getTestReplacementInfo (
207
+ testFile: testFile10,
208
+ existingLicenseText: existingLicenseText,
209
+ replacementLicenseText: replacementLicenseText,
210
+ );
211
+
212
+ expect (replacementInfo.existingHeader, equals (expectedExistingHeader));
213
+
214
+ expect (
215
+ replacementInfo.replacementHeader,
216
+ equals (expectedReplacementHeader),
217
+ );
203
218
});
204
219
205
220
test ('stored value preserved in replacement header' , () async {
@@ -334,19 +349,19 @@ text that should be added to the file. */''',
334
349
final config = LicenseConfig .fromYamlFile (configFile);
335
350
final header = LicenseHeader ();
336
351
337
- final contentsBeforeUpdate = testFile1.readAsStringSync ();
352
+ // missing license
353
+ final contentsBeforeUpdate = testFile9.readAsStringSync ();
338
354
final results = await header.bulkUpdate (
339
355
directory: testDirectory,
340
356
config: config,
341
357
);
342
- final contentsAfterUpdate = testFile1 .readAsStringSync ();
358
+ final contentsAfterUpdate = testFile9 .readAsStringSync ();
343
359
344
360
final includedPaths = results.includedPaths;
345
361
expect (includedPaths, isNotNull);
346
362
expect (includedPaths.length, equals (9 ));
347
363
// Order is not guaranteed
348
364
expect (includedPaths.contains (testFile1.path), true );
349
- expect (contentsBeforeUpdate, isNot (equals (contentsAfterUpdate)));
350
365
expect (includedPaths.contains (testFile2.path), true );
351
366
expect (includedPaths.contains (testFile3.path), true );
352
367
expect (includedPaths.contains (testFile7.path), true );
@@ -369,6 +384,11 @@ text that should be added to the file. */''',
369
384
expect (updatedPaths.contains (testFile10.path), true );
370
385
expect (updatedPaths.contains (skipFile.path), false );
371
386
expect (updatedPaths.contains (doNothingFile.path), false );
387
+
388
+ expect (contentsBeforeUpdate, isNot (equals (contentsAfterUpdate)));
389
+ // There is an extremely rare failure case on the year boundary.
390
+ // TODO(mossmana): Handle running test on Dec 31 - Jan 1.
391
+ expect (contentsAfterUpdate, contains (DateTime .now ().year.toString ()));
372
392
});
373
393
374
394
test ('license headers bulk update can be dry run' , () async {
0 commit comments