mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
[tool] Consider comment-only changes to be dev-only (#4279)
Updates the state checker to inspect changed Dart files to see if the only changes are implementation (not documentation) comment lines. In particular, this will fix the problem of CI flagging changes that do nothing but add `// ignore:` comments (for federated package changes involving deprecation, framework changes that require temporary ignores in packages to support stable, etc.) as needing version and changelog changes
This commit is contained in:
@ -289,6 +289,90 @@ void main() {
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'does not requires changelog or version change for '
|
||||
'non-doc-comment-only changes', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/lib/a_plugin.dart',
|
||||
];
|
||||
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/lib/a_plugin.dart': <String>[
|
||||
'- // Old comment.',
|
||||
'+ // New comment.',
|
||||
'+ ', // Allow whitespace line changes as part of comment changes.
|
||||
]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, false);
|
||||
expect(state.needsChangelogChange, false);
|
||||
});
|
||||
|
||||
test('requires changelog or version change for doc comment changes',
|
||||
() async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/lib/a_plugin.dart',
|
||||
];
|
||||
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/lib/a_plugin.dart': <String>[
|
||||
'- /// Old doc comment.',
|
||||
'+ /// New doc comment.',
|
||||
]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(
|
||||
package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git,
|
||||
);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('requires changelog or version change for Dart code change', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/lib/a_plugin.dart',
|
||||
];
|
||||
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/lib/a_plugin.dart': <String>[
|
||||
// Include inline comments to ensure the comment check doesn't have
|
||||
// false positives for lines that include comment changes but aren't
|
||||
// only comment changes.
|
||||
'- callOldMethod(); // inline comment',
|
||||
'+ callNewMethod(); // inline comment',
|
||||
]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'requires changelog or version change if build.gradle diffs cannot '
|
||||
'be checked', () async {
|
||||
|
@ -1114,7 +1114,8 @@ packages/plugin/android/build.gradle
|
||||
);
|
||||
});
|
||||
|
||||
test('allows missing CHANGELOG and version change for dev-only changes',
|
||||
test(
|
||||
'allows missing CHANGELOG and version change for dev-only-file changes',
|
||||
() async {
|
||||
final RepositoryPackage plugin =
|
||||
createFakePlugin('plugin', packagesDir, version: '1.0.0');
|
||||
@ -1147,6 +1148,86 @@ packages/plugin/run_tests.sh
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'allows missing CHANGELOG and version change for dev-only line-level '
|
||||
'changes in production files', () async {
|
||||
final RepositoryPackage plugin =
|
||||
createFakePlugin('plugin', packagesDir, version: '1.0.0');
|
||||
|
||||
const String changelog = '''
|
||||
## 1.0.0
|
||||
* Some changes.
|
||||
''';
|
||||
plugin.changelogFile.writeAsStringSync(changelog);
|
||||
processRunner.mockProcessesForExecutable['git-show'] =
|
||||
<FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(stdout: 'version: 1.0.0')),
|
||||
];
|
||||
processRunner.mockProcessesForExecutable['git-diff'] =
|
||||
<FakeProcessInfo>[
|
||||
// File list.
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
packages/plugin/lib/plugin.dart
|
||||
''')),
|
||||
// Dart file diff.
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
+ // TODO(someone): Fix this.
|
||||
+ // ignore: some_lint
|
||||
'''), <String>['main', 'HEAD', '--', 'packages/plugin/lib/plugin.dart']),
|
||||
];
|
||||
|
||||
final List<String> output =
|
||||
await runWithMissingChangeDetection(<String>[]);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for plugin'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('documentation comments are not exempt', () async {
|
||||
final RepositoryPackage plugin =
|
||||
createFakePlugin('plugin', packagesDir, version: '1.0.0');
|
||||
|
||||
const String changelog = '''
|
||||
## 1.0.0
|
||||
* Some changes.
|
||||
''';
|
||||
plugin.changelogFile.writeAsStringSync(changelog);
|
||||
processRunner.mockProcessesForExecutable['git-show'] =
|
||||
<FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(stdout: 'version: 1.0.0')),
|
||||
];
|
||||
processRunner.mockProcessesForExecutable['git-diff'] =
|
||||
<FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
packages/plugin/lib/plugin.dart
|
||||
''')),
|
||||
// Dart file diff.
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
+ /// Important new information for API clients!
|
||||
'''), <String>['main', 'HEAD', '--', 'packages/plugin/lib/plugin.dart']),
|
||||
];
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runWithMissingChangeDetection(
|
||||
<String>[], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('No version change found'),
|
||||
contains('plugin:\n'
|
||||
' Missing version change'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('allows valid against pub', () async {
|
||||
|
Reference in New Issue
Block a user