Skip to content

Commit 05ff48f

Browse files
committed
test(tool): Add tests for CHANGELOG blank line validation
Adds unit tests to verify that the `version-check` command correctly fails when it detects blank lines between list items in a CHANGELOG, as this breaks list rendering on pub.dev. Tests are added for both simple lists and nested lists. Also includes a minor formatting fix for the error message. Signed-off-by: Lorenzo Croce <lorenzo.croce@arenastudios.it>
1 parent e77b90d commit 05ff48f

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

script/tool/lib/src/version_check_command.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
471471

472472
printError(
473473
'${indentation}Blank lines found between list items in CHANGELOG.\n'
474-
'${indentation}This creates multiple separate lists on pub.dev.\n'
475-
'${indentation}Remove blank lines to keep all items in a single list.\n'
476-
'${indentation}The problematic section found is:\n'
477-
'$offendingLines');
474+
'${indentation}This creates multiple separate lists on pub.dev.\n'
475+
'${indentation}Remove blank lines to keep all items in a single list.\n'
476+
'${indentation}The problematic section found is:\n'
477+
'$offendingLines');
478478
return false;
479479
}
480480

script/tool/test/version_check_command_test.dart

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,83 @@ void main() {
421421
);
422422
});
423423

424+
test('Fail if CHANGELOG list items have a blank line', () async {
425+
const String version = '1.0.1';
426+
final RepositoryPackage plugin =
427+
createFakePlugin('plugin', packagesDir, version: version);
428+
429+
// Blank line breaks the list items.
430+
const String changelog = '''
431+
## $version
432+
* First item.
433+
434+
* Second item.
435+
* Third item.
436+
''';
437+
plugin.changelogFile.writeAsStringSync(changelog);
438+
gitProcessRunner.mockProcessesForExecutable['git-show'] =
439+
<FakeProcessInfo>[
440+
FakeProcessInfo(MockProcess(stdout: 'version: 1.0.0')),
441+
];
442+
Error? commandError;
443+
final List<String> output = await runCapturingPrint(
444+
runner, <String>['version-check', '--base-sha=main'],
445+
errorHandler: (Error e) {
446+
commandError = e;
447+
});
448+
449+
expect(commandError, isA<ToolExit>());
450+
expect(
451+
output,
452+
containsAllInOrder(<Matcher>[
453+
contains('Running for plugin'),
454+
contains('1.0.0 -> 1.0.1'),
455+
contains('Blank lines found between list items in CHANGELOG.'),
456+
contains('CHANGELOG.md failed validation.'),
457+
]),
458+
);
459+
});
460+
461+
test('Fail if CHANGELOG list items have a blank line with nested items',
462+
() async {
463+
const String version = '1.0.1';
464+
final RepositoryPackage plugin =
465+
createFakePlugin('plugin', packagesDir, version: version);
466+
467+
// Blank line in nested list items.
468+
const String changelog = '''
469+
## $version
470+
* Top level item.
471+
* Nested item A.
472+
473+
* Nested item B.
474+
* Another top level item.
475+
''';
476+
plugin.changelogFile.writeAsStringSync(changelog);
477+
gitProcessRunner.mockProcessesForExecutable['git-show'] =
478+
<FakeProcessInfo>[
479+
FakeProcessInfo(MockProcess(stdout: 'version: 1.0.0')),
480+
];
481+
Error? commandError;
482+
final List<String> output = await runCapturingPrint(
483+
runner, <String>['version-check', '--base-sha=main'],
484+
errorHandler: (Error e) {
485+
commandError = e;
486+
});
487+
488+
expect(commandError, isA<ToolExit>());
489+
expect(
490+
output,
491+
containsAllInOrder(<Matcher>[
492+
contains('Running for plugin'),
493+
contains('1.0.0 -> 1.0.1'),
494+
contains('Blank lines found between list items in CHANGELOG.'),
495+
contains('CHANGELOG.md failed validation.'),
496+
]),
497+
);
498+
});
499+
// END OF NEW TESTS
500+
424501
test(
425502
'Fail if pubspec version only matches an older version listed in CHANGELOG',
426503
() async {

0 commit comments

Comments
 (0)