Skip to content

Commit

Permalink
[tool] Improve changed-package run mode logging (#6521)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan authored Sep 30, 2022
1 parent dc5f185 commit b7bb9db
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
9 changes: 6 additions & 3 deletions script/tool/lib/src/common/package_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,14 @@ abstract class PackageCommand extends Command<void> {

if (changedFileFinder != null) {
final String baseSha = await changedFileFinder.getBaseSha();
print(
'Running for all packages that have diffs relative to "$baseSha"\n');
final List<String> changedFiles =
await changedFileFinder.getChangedFiles();
if (!_changesRequireFullTest(changedFiles)) {
if (_changesRequireFullTest(changedFiles)) {
print('Running for all packages, since a file has changed that could '
'affect the entire repository.');
} else {
print(
'Running for all packages that have diffs relative to "$baseSha"\n');
packages = _getChangedPackageNames(changedFiles);
}
} else if (getBoolArg(_runOnDirtyPackagesArg)) {
Expand Down
51 changes: 44 additions & 7 deletions script/tool/test/common/package_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,18 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,

final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('all plugins should be tested if .ci.yaml changes', () async {
Expand All @@ -426,11 +433,17 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('all plugins should be tested if anything in .ci/ changes',
Expand All @@ -445,14 +458,20 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('all plugins should be tested if anything in script changes.',
test('all plugins should be tested if anything in script/ changes.',
() async {
processRunner.mockProcessesForExecutable['git-diff'] = <Process>[
MockProcess(stdout: '''
Expand All @@ -464,11 +483,17 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('all plugins should be tested if the root analysis options change.',
Expand All @@ -483,11 +508,17 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('all plugins should be tested if formatting options change.',
Expand All @@ -502,11 +533,17 @@ packages/plugin1/CHANGELOG
createFakePlugin('plugin1', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner,
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for all packages, since a file has changed '
'that could affect the entire repository.')
]));
});

test('Only changed plugin should be tested.', () async {
Expand Down

0 comments on commit b7bb9db

Please sign in to comment.