Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -11,143 +11,137 @@ import 'package:platform/platform.dart';
import './common.dart';
void main() {
group('candidates command', () {
const String flutterRoot = '/flutter';
const String flutterBinPath = '$flutterRoot/bin/flutter';
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
const String remoteName = 'origin';
group(
'candidates command',
() {
const String flutterRoot = '/flutter';
const String flutterBinPath = '$flutterRoot/bin/flutter';
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
const String remoteName = 'origin';
late MemoryFileSystem fileSystem;
late FakePlatform platform;
late TestStdio stdio;
late FakeProcessManager processManager;
final String operatingSystem = const LocalPlatform().operatingSystem;
late MemoryFileSystem fileSystem;
late FakePlatform platform;
late TestStdio stdio;
late FakeProcessManager processManager;
final String operatingSystem = const LocalPlatform().operatingSystem;
setUp(() {
stdio = TestStdio();
fileSystem = MemoryFileSystem.test();
});
setUp(() {
stdio = TestStdio();
fileSystem = MemoryFileSystem.test();
});
CommandRunner<void> createRunner({
required Checkouts checkouts,
}) {
final CandidatesCommand command = CandidatesCommand(
checkouts: checkouts,
flutterRoot: fileSystem.directory(flutterRoot),
);
return CommandRunner<void>('clean-test', '')..addCommand(command);
}
CommandRunner<void> createRunner({required Checkouts checkouts}) {
final CandidatesCommand command = CandidatesCommand(
checkouts: checkouts,
flutterRoot: fileSystem.directory(flutterRoot),
);
return CommandRunner<void>('clean-test', '')..addCommand(command);
}
test('prints only branches from targeted remote', () async {
const String currentVersion = '1.2.3';
const String branch = 'flutter-1.3-candidate.0';
test('prints only branches from targeted remote', () async {
const String currentVersion = '1.2.3';
const String branch = 'flutter-1.3-candidate.0';
processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['git', 'fetch', remoteName],
),
const FakeCommand(
command: <String>[flutterBinPath, 'help'],
),
const FakeCommand(
command: <String>[flutterBinPath, '--version', '--machine'],
stdout: '{"frameworkVersion": "$currentVersion"}',
),
FakeCommand(
command: const <String>[
'git',
'branch',
'--no-color',
'--remotes',
'--list',
'$remoteName/*',
],
stdout: <String>[
'other-remote/flutter-5.0-candidate.0',
'$remoteName/$branch',
].join('\n'),
),
]);
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['git', 'fetch', remoteName]),
const FakeCommand(command: <String>[flutterBinPath, 'help']),
const FakeCommand(
command: <String>[flutterBinPath, '--version', '--machine'],
stdout: '{"frameworkVersion": "$currentVersion"}',
),
FakeCommand(
command: const <String>[
'git',
'branch',
'--no-color',
'--remotes',
'--list',
'$remoteName/*',
],
stdout: <String>[
'other-remote/flutter-5.0-candidate.0',
'$remoteName/$branch',
].join('\n'),
),
]);
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
platform = FakePlatform(
environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(pathSeparator),
},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
platform = FakePlatform(
environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(pathSeparator),
},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final CommandRunner<void> runner = createRunner(checkouts: checkouts);
await runner.run(<String>['candidates', '--$kRemote', remoteName]);
expect(stdio.stdout.contains('currentVersion = $currentVersion'), true);
expect(stdio.stdout.contains(branch), true);
expect(stdio.stdout.contains('flutter-5.0-candidate.0'), false);
});
final CommandRunner<void> runner = createRunner(checkouts: checkouts);
await runner.run(<String>['candidates', '--$kRemote', remoteName]);
expect(stdio.stdout.contains('currentVersion = $currentVersion'), true);
expect(stdio.stdout.contains(branch), true);
expect(stdio.stdout.contains('flutter-5.0-candidate.0'), false);
});
test('does not print branches older or equal to current version', () async {
const String currentVersion = '2.3.0-13.0.pre.48';
const String newBranch = 'flutter-2.4-candidate.0';
const String oldBranch = 'flutter-1.0-candidate.0';
const String currentBranch = 'flutter-2.3-candidate.13';
test('does not print branches older or equal to current version', () async {
const String currentVersion = '2.3.0-13.0.pre.48';
const String newBranch = 'flutter-2.4-candidate.0';
const String oldBranch = 'flutter-1.0-candidate.0';
const String currentBranch = 'flutter-2.3-candidate.13';
processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['git', 'fetch', remoteName],
),
const FakeCommand(
command: <String>[flutterBinPath, 'help'],
),
const FakeCommand(
command: <String>[flutterBinPath, '--version', '--machine'],
stdout: '{"frameworkVersion": "$currentVersion"}',
),
FakeCommand(
command: const <String>[
'git',
'branch',
'--no-color',
'--remotes',
'--list',
'$remoteName/*',
],
stdout: <String>[
'$remoteName/$oldBranch',
'$remoteName/$currentBranch',
'$remoteName/$newBranch',
].join('\n'),
),
]);
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['git', 'fetch', remoteName]),
const FakeCommand(command: <String>[flutterBinPath, 'help']),
const FakeCommand(
command: <String>[flutterBinPath, '--version', '--machine'],
stdout: '{"frameworkVersion": "$currentVersion"}',
),
FakeCommand(
command: const <String>[
'git',
'branch',
'--no-color',
'--remotes',
'--list',
'$remoteName/*',
],
stdout: <String>[
'$remoteName/$oldBranch',
'$remoteName/$currentBranch',
'$remoteName/$newBranch',
].join('\n'),
),
]);
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
platform = FakePlatform(
environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(pathSeparator),
},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
platform = FakePlatform(
environment: <String, String>{
'HOME': <String>['path', 'to', 'home'].join(pathSeparator),
},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final CommandRunner<void> runner = createRunner(checkouts: checkouts);
await runner.run(<String>['candidates', '--$kRemote', remoteName]);
expect(stdio.stdout.contains('currentVersion = $currentVersion'), true);
expect(stdio.stdout.contains(newBranch), true);
expect(stdio.stdout.contains(oldBranch), false);
expect(stdio.stdout.contains(currentBranch), false);
});
}, onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
});
final CommandRunner<void> runner = createRunner(checkouts: checkouts);
await runner.run(<String>['candidates', '--$kRemote', remoteName]);
expect(stdio.stdout.contains('currentVersion = $currentVersion'), true);
expect(stdio.stdout.contains(newBranch), true);
expect(stdio.stdout.contains(oldBranch), false);
expect(stdio.stdout.contains(currentBranch), false);
});
},
onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
},
);
}

View File

@@ -12,83 +12,69 @@ import 'package:platform/platform.dart';
import './common.dart';
void main() {
group('clean command', () {
const String flutterRoot = '/flutter';
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
const String stateFilePath = '/state-file.json';
group(
'clean command',
() {
const String flutterRoot = '/flutter';
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
const String stateFilePath = '/state-file.json';
late MemoryFileSystem fileSystem;
late FakePlatform platform;
late TestStdio stdio;
late FakeProcessManager processManager;
late CommandRunner<void> runner;
late MemoryFileSystem fileSystem;
late FakePlatform platform;
late TestStdio stdio;
late FakeProcessManager processManager;
late CommandRunner<void> runner;
setUp(() {
stdio = TestStdio();
fileSystem = MemoryFileSystem.test();
final String operatingSystem = const LocalPlatform().operatingSystem;
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
setUp(() {
stdio = TestStdio();
fileSystem = MemoryFileSystem.test();
final String operatingSystem = const LocalPlatform().operatingSystem;
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
processManager = FakeProcessManager.empty();
platform = FakePlatform(
environment: <String, String>{'HOME': '/path/to/user/home'},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final CleanCommand command = CleanCommand(
checkouts: checkouts,
);
runner = CommandRunner<void>('clean-test', '')..addCommand(command);
});
processManager = FakeProcessManager.empty();
platform = FakePlatform(
environment: <String, String>{'HOME': '/path/to/user/home'},
pathSeparator: pathSeparator,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final CleanCommand command = CleanCommand(checkouts: checkouts);
runner = CommandRunner<void>('clean-test', '')..addCommand(command);
});
test('throws if no state file found', () async {
await expectLater(
() async => runner.run(<String>[
'clean',
'--$kStateOption',
stateFilePath,
'--$kYesFlag',
]),
throwsExceptionWith(
'No persistent state file found at $stateFilePath',
),
);
});
test('throws if no state file found', () async {
await expectLater(
() async =>
runner.run(<String>['clean', '--$kStateOption', stateFilePath, '--$kYesFlag']),
throwsExceptionWith('No persistent state file found at $stateFilePath'),
);
});
test('deletes an empty state file', () async {
final File stateFile = fileSystem.file(stateFilePath);
stateFile.writeAsStringSync('');
test('deletes an empty state file', () async {
final File stateFile = fileSystem.file(stateFilePath);
stateFile.writeAsStringSync('');
await runner.run(<String>[
'clean',
'--$kStateOption',
stateFile.path,
'--$kYesFlag',
]);
await runner.run(<String>['clean', '--$kStateOption', stateFile.path, '--$kYesFlag']);
expect(stateFile.existsSync(), false);
});
expect(stateFile.existsSync(), false);
});
test('deletes a state file with content', () async {
final File stateFile = fileSystem.file(stateFilePath);
stateFile.writeAsStringSync('{status: pending}');
test('deletes a state file with content', () async {
final File stateFile = fileSystem.file(stateFilePath);
stateFile.writeAsStringSync('{status: pending}');
await runner.run(<String>[
'clean',
'--$kStateOption',
stateFile.path,
'--$kYesFlag',
]);
await runner.run(<String>['clean', '--$kStateOption', stateFile.path, '--$kYesFlag']);
expect(stateFile.existsSync(), false);
});
}, onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
});
expect(stateFile.existsSync(), false);
});
},
onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
},
);
}

View File

@@ -13,35 +13,36 @@ export '../../../../packages/flutter_tools/test/src/fake_process_manager.dart';
Matcher throwsAssertionWith(String messageSubString) {
return throwsA(
isA<AssertionError>().having(
(AssertionError e) => e.toString(),
'description',
contains(messageSubString),
),
isA<AssertionError>().having(
(AssertionError e) => e.toString(),
'description',
contains(messageSubString),
),
);
}
Matcher throwsExceptionWith(String messageSubString) {
return throwsA(
isA<Exception>().having(
(Exception e) => e.toString(),
'description',
contains(messageSubString),
),
isA<Exception>().having(
(Exception e) => e.toString(),
'description',
contains(messageSubString),
),
);
}
class TestStdio extends Stdio {
TestStdio({
this.verbose = false,
List<String>? stdin,
}) : stdin = stdin ?? <String>[];
TestStdio({this.verbose = false, List<String>? stdin}) : stdin = stdin ?? <String>[];
String get error => logs.where((String log) => log.startsWith(r'[error] ')).join('\n');
String get stdout => logs.where((String log) {
return log.startsWith(r'[status] ') || log.startsWith(r'[trace] ') || log.startsWith(r'[write] ');
}).join('\n');
String get stdout => logs
.where((String log) {
return log.startsWith(r'[status] ') ||
log.startsWith(r'[trace] ') ||
log.startsWith(r'[write] ');
})
.join('\n');
final bool verbose;
final List<String> stdin;
@@ -66,15 +67,15 @@ class FakeArgResults extends Fake implements ArgResults {
bool force = false,
bool skipTagging = false,
}) : _parsedArgs = <String, dynamic>{
'increment': level,
'candidate-branch': candidateBranch,
'remote': remote,
'just-print': justPrint,
'yes': autoApprove,
'help': help,
'force': force,
'skip-tagging': skipTagging,
};
'increment': level,
'candidate-branch': candidateBranch,
'remote': remote,
'just-print': justPrint,
'yes': autoApprove,
'help': help,
'force': force,
'skip-tagging': skipTagging,
};
@override
String? name;

View File

@@ -22,8 +22,7 @@ void main() {
const String dartRevision = 'fe9708ab688dcda9923f584ba370a66fcbc3811f';
const String engineCherrypick1 = 'a5a25cd702b062c24b2c67b8d30b5cb33e0ef6f0';
const String engineCherrypick2 = '94d06a2e1d01a3b0c693b94d70c5e1df9d78d249';
const String frameworkCherrypick =
'a5a25cd702b062c24b2c67b8d30b5cb33e0ef6f0';
const String frameworkCherrypick = 'a5a25cd702b062c24b2c67b8d30b5cb33e0ef6f0';
final RegExp titlePattern = RegExp(r'&title=(.*)&');
final RegExp bodyPattern = RegExp(r'&body=(.*)$');
@@ -31,61 +30,41 @@ void main() {
late pb.ConductorState state;
setUp(() {
state = (pb.ConductorState.create()
..engine = (pb.Repository.create()
..candidateBranch = candidateBranch
..cherrypicks.addAll(<pb.Cherrypick>[
pb.Cherrypick.create()
..trunkRevision = engineCherrypick1,
pb.Cherrypick.create()
..trunkRevision = engineCherrypick2,
])
..dartRevision = dartRevision
..workingBranch = workingBranch
)
..framework = (pb.Repository.create()
..candidateBranch = candidateBranch
..cherrypicks.add(pb.Cherrypick.create()
..trunkRevision = frameworkCherrypick
)
..workingBranch = workingBranch
)
..releaseChannel = releaseChannel
..releaseVersion = releaseVersion
);
state =
(pb.ConductorState.create()
..engine =
(pb.Repository.create()
..candidateBranch = candidateBranch
..cherrypicks.addAll(<pb.Cherrypick>[
pb.Cherrypick.create()..trunkRevision = engineCherrypick1,
pb.Cherrypick.create()..trunkRevision = engineCherrypick2,
])
..dartRevision = dartRevision
..workingBranch = workingBranch)
..framework =
(pb.Repository.create()
..candidateBranch = candidateBranch
..cherrypicks.add(pb.Cherrypick.create()..trunkRevision = frameworkCherrypick)
..workingBranch = workingBranch)
..releaseChannel = releaseChannel
..releaseVersion = releaseVersion);
});
test('throws on an invalid repoName', () {
expect(
() => getNewPrLink(
repoName: 'flooter',
userName: userName,
state: state,
),
throwsExceptionWith(
'Expected repoName to be one of flutter or engine but got flooter.',
),
() => getNewPrLink(repoName: 'flooter', userName: userName, state: state),
throwsExceptionWith('Expected repoName to be one of flutter or engine but got flooter.'),
);
});
test('returns a valid URL for engine', () {
final String link = getNewPrLink(
repoName: 'engine',
userName: userName,
state: state,
);
final String link = getNewPrLink(repoName: 'engine', userName: userName, state: state);
expect(link, contains('https://github.com/flutter/engine/compare/'));
expect(link, contains('$candidateBranch...$userName:$workingBranch?expand=1'));
expect(
link,
contains('https://github.com/flutter/engine/compare/'),
Uri.decodeQueryComponent(titlePattern.firstMatch(link)?.group(1) ?? ''),
'[flutter_releases] Flutter $releaseChannel $releaseVersion Engine Cherrypicks',
);
expect(
link,
contains('$candidateBranch...$userName:$workingBranch?expand=1'),
);
expect(
Uri.decodeQueryComponent(
titlePattern.firstMatch(link)?.group(1) ?? ''),
'[flutter_releases] Flutter $releaseChannel $releaseVersion Engine Cherrypicks');
final String expectedBody = '''
# Flutter $releaseChannel $releaseVersion Engine
@@ -95,30 +74,17 @@ void main() {
- commit: flutter/engine@${engineCherrypick1.substring(0, 9)}
- commit: flutter/engine@${engineCherrypick2.substring(0, 9)}
''';
expect(
Uri.decodeQueryComponent(bodyPattern.firstMatch(link)?.group(1) ?? ''),
expectedBody,
);
expect(Uri.decodeQueryComponent(bodyPattern.firstMatch(link)?.group(1) ?? ''), expectedBody);
});
test('returns a valid URL for framework', () {
final String link = getNewPrLink(
repoName: 'flutter',
userName: userName,
state: state,
);
final String link = getNewPrLink(repoName: 'flutter', userName: userName, state: state);
expect(link, contains('https://github.com/flutter/flutter/compare/'));
expect(link, contains('$candidateBranch...$userName:$workingBranch?expand=1'));
expect(
link,
contains('https://github.com/flutter/flutter/compare/'),
Uri.decodeQueryComponent(titlePattern.firstMatch(link)?.group(1) ?? ''),
'[flutter_releases] Flutter $releaseChannel $releaseVersion Framework Cherrypicks',
);
expect(
link,
contains('$candidateBranch...$userName:$workingBranch?expand=1'),
);
expect(
Uri.decodeQueryComponent(
titlePattern.firstMatch(link)?.group(1) ?? ''),
'[flutter_releases] Flutter $releaseChannel $releaseVersion Framework Cherrypicks');
final String expectedBody = '''
# Flutter $releaseChannel $releaseVersion Framework
@@ -126,10 +92,7 @@ void main() {
- commit: ${frameworkCherrypick.substring(0, 9)}
''';
expect(
Uri.decodeQueryComponent(bodyPattern.firstMatch(link)?.group(1) ?? ''),
expectedBody,
);
expect(Uri.decodeQueryComponent(bodyPattern.firstMatch(link)?.group(1) ?? ''), expectedBody);
});
});
@@ -137,28 +100,16 @@ void main() {
const String flagName = 'a-cli-flag';
test('prefers env over argResults', () {
final ArgResults argResults = FakeArgs(results: <String, Object>{
flagName: false,
});
final ArgResults argResults = FakeArgs(results: <String, Object>{flagName: false});
final Map<String, String> env = <String, String>{'A_CLI_FLAG': 'TRUE'};
final bool result = getBoolFromEnvOrArgs(
flagName,
argResults,
env,
);
final bool result = getBoolFromEnvOrArgs(flagName, argResults, env);
expect(result, true);
});
test('falls back to argResults if env is empty', () {
final ArgResults argResults = FakeArgs(results: <String, Object>{
flagName: false,
});
final ArgResults argResults = FakeArgs(results: <String, Object>{flagName: false});
final Map<String, String> env = <String, String>{};
final bool result = getBoolFromEnvOrArgs(
flagName,
argResults,
env,
);
final bool result = getBoolFromEnvOrArgs(flagName, argResults, env);
expect(result, false);
});
});
@@ -185,7 +136,7 @@ class FakeArgs extends Fake implements ArgResults {
}
@override
Object? operator[](String name) {
Object? operator [](String name) {
return results[name];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -44,16 +44,12 @@ void main() {
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(checkoutsParentDirectory)
..createSync(recursive: true),
parentDirectory: fileSystem.directory(checkoutsParentDirectory)..createSync(recursive: true),
platform: platform,
processManager: processManager,
stdio: stdio,
);
framework = FrameworkRepository(
checkouts,
mirrorRemote: const Remote.mirror(mirrorUrl),
);
framework = FrameworkRepository(checkouts, mirrorRemote: const Remote.mirror(mirrorUrl));
autoroller = PackageAutoroller(
githubClient: githubClient,
@@ -67,104 +63,81 @@ void main() {
});
test('GitHub token is redacted from exceptions while pushing', () async {
final StreamController<List<int>> controller =
StreamController<List<int>>();
final StreamController<List<int>> controller = StreamController<List<int>>();
processManager.addCommands(<FakeCommand>[
FakeCommand(command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
], stdin: io.IOSink(controller.sink)),
const FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
]),
const FakeCommand(command: <String>[
'git',
'remote',
'add',
'mirror',
mirrorUrl,
]),
const FakeCommand(command: <String>[
'git',
'fetch',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
FrameworkRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: 'deadbeef'),
const FakeCommand(command: <String>[
'git',
'ls-remote',
'--heads',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
'-b',
'packages-autoroller-branch-1',
]),
const FakeCommand(command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'help',
]),
const FakeCommand(command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
]),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
], stdout: '''
FakeCommand(
command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
],
stdin: io.IOSink(controller.sink),
),
const FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
],
),
const FakeCommand(command: <String>['git', 'remote', 'add', 'mirror', mirrorUrl]),
const FakeCommand(command: <String>['git', 'fetch', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', FrameworkRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: 'deadbeef'),
const FakeCommand(command: <String>['git', 'ls-remote', '--heads', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', '-b', 'packages-autoroller-branch-1']),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'help',
],
),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
],
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: '''
M packages/foo/pubspec.yaml
M packages/bar/pubspec.yaml
M dev/integration_tests/test_foo/pubspec.yaml
'''),
const FakeCommand(command: <String>[
'git',
'add',
'--all',
]),
const FakeCommand(command: <String>[
'git',
'commit',
'--message',
'roll packages',
'--author="fluttergithubbot <fluttergithubbot@google.com>"',
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: '000deadbeef'),
const FakeCommand(command: <String>[
'git',
'push',
'https://$token@github.com/$orgName/flutter.git',
'packages-autoroller-branch-1:packages-autoroller-branch-1',
], exitCode: 1, stderr: 'Authentication error!'),
''',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(
command: <String>[
'git',
'commit',
'--message',
'roll packages',
'--author="fluttergithubbot <fluttergithubbot@google.com>"',
],
),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: '000deadbeef'),
const FakeCommand(
command: <String>[
'git',
'push',
'https://$token@github.com/$orgName/flutter.git',
'packages-autoroller-branch-1:packages-autoroller-branch-1',
],
exitCode: 1,
stderr: 'Authentication error!',
),
]);
await expectLater(
() async {
@@ -172,45 +145,52 @@ void main() {
await controller.stream.drain<Object?>();
await rollFuture;
},
throwsA(isA<Exception>().having(
(Exception exc) => exc.toString(),
'message',
isNot(contains(token)),
)),
throwsA(
isA<Exception>().having(
(Exception exc) => exc.toString(),
'message',
isNot(contains(token)),
),
),
);
});
test('Does not attempt to roll if bot already has an open PR', () async {
final StreamController<List<int>> controller =
StreamController<List<int>>();
final StreamController<List<int>> controller = StreamController<List<int>>();
processManager.addCommands(<FakeCommand>[
FakeCommand(command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
], stdin: io.IOSink(controller.sink)),
const FakeCommand(command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Non empty array means there are open PRs by the bot with the tool label
// We expect no further commands to be run
], stdout: '[{"number": 123}]'),
FakeCommand(
command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
],
stdin: io.IOSink(controller.sink),
),
const FakeCommand(
command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Non empty array means there are open PRs by the bot with the tool label
// We expect no further commands to be run
],
stdout: '[{"number": 123}]',
),
]);
final Future<void> rollFuture = autoroller.roll();
await controller.stream.drain<Object?>();
@@ -221,111 +201,90 @@ void main() {
});
test('Does not commit or create a PR if no changes were made', () async {
final StreamController<List<int>> controller =
StreamController<List<int>>();
final StreamController<List<int>> controller = StreamController<List<int>>();
processManager.addCommands(<FakeCommand>[
FakeCommand(command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
], stdin: io.IOSink(controller.sink)),
const FakeCommand(command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Returns empty array, as there are no other open roll PRs from the bot
], stdout: '[]'),
const FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
]),
const FakeCommand(command: <String>[
'git',
'remote',
'add',
'mirror',
mirrorUrl,
]),
const FakeCommand(command: <String>[
'git',
'fetch',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
FrameworkRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: 'deadbeef'),
FakeCommand(
command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
],
stdin: io.IOSink(controller.sink),
),
const FakeCommand(
command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Returns empty array, as there are no other open roll PRs from the bot
],
stdout: '[]',
),
const FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
],
),
const FakeCommand(command: <String>['git', 'remote', 'add', 'mirror', mirrorUrl]),
const FakeCommand(command: <String>['git', 'fetch', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', FrameworkRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: 'deadbeef'),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'pub',
'get',
],
workingDirectory: '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
workingDirectory:
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
),
FakeCommand(
command: const <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'compile',
'exe',
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
'-o',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
],
onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync(),
),
const FakeCommand(
command: <String>['chmod', '+x', '/.tmp_rand0/rand0/generate_gradle_lockfiles'],
),
const FakeCommand(command: <String>['git', 'ls-remote', '--heads', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', '-b', 'packages-autoroller-branch-1']),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
],
),
FakeCommand(command: const <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'compile',
'exe',
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
'-o',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
], onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync()),
const FakeCommand(command: <String>[
'chmod',
'+x',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
]),
const FakeCommand(command: <String>[
'git',
'ls-remote',
'--heads',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
'-b',
'packages-autoroller-branch-1',
]),
const FakeCommand(command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
]),
// Because there is no stdout to git status, the script should exit cleanly here
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
]),
const FakeCommand(command: <String>['git', 'status', '--porcelain']),
]);
final Future<void> rollFuture = autoroller.roll();
await controller.stream.drain<Object?>();
@@ -334,212 +293,178 @@ void main() {
});
test('can roll with correct inputs', () async {
final StreamController<List<int>> controller =
StreamController<List<int>>();
final StreamController<List<int>> controller = StreamController<List<int>>();
processManager.addCommands(<FakeCommand>[
FakeCommand(command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
], stdin: io.IOSink(controller.sink)),
const FakeCommand(command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Returns empty array, as there are no other open roll PRs from the bot
], stdout: '[]'),
const FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
]),
const FakeCommand(command: <String>[
'git',
'remote',
'add',
'mirror',
mirrorUrl,
]),
const FakeCommand(command: <String>[
'git',
'fetch',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
FrameworkRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: 'deadbeef'),
FakeCommand(
command: const <String>[
'gh',
'auth',
'login',
'--hostname',
'github.com',
'--git-protocol',
'https',
'--with-token',
],
stdin: io.IOSink(controller.sink),
),
const FakeCommand(
command: <String>[
'gh',
'pr',
'list',
'--author',
'flutter-pub-roller-bot',
'--repo',
'flutter/flutter',
'--state',
'open',
'--search',
'Roll pub packages',
'--json',
'number',
// Returns empty array, as there are no other open roll PRs from the bot
],
stdout: '[]',
),
const FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework',
],
),
const FakeCommand(command: <String>['git', 'remote', 'add', 'mirror', mirrorUrl]),
const FakeCommand(command: <String>['git', 'fetch', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', FrameworkRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: 'deadbeef'),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'pub',
'get',
],
workingDirectory: '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
workingDirectory:
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
),
FakeCommand(command: const <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'compile',
'exe',
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
'-o',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
], onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync()),
const FakeCommand(command: <String>[
'chmod',
'+x',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
]),
const FakeCommand(command: <String>[
'git',
'ls-remote',
'--heads',
'mirror',
]),
const FakeCommand(command: <String>[
'git',
'checkout',
'-b',
'packages-autoroller-branch-1',
]),
const FakeCommand(command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
]),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
], stdout: '''
FakeCommand(
command: const <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
'compile',
'exe',
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
'-o',
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
],
onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync(),
),
const FakeCommand(
command: <String>['chmod', '+x', '/.tmp_rand0/rand0/generate_gradle_lockfiles'],
),
const FakeCommand(command: <String>['git', 'ls-remote', '--heads', 'mirror']),
const FakeCommand(command: <String>['git', 'checkout', '-b', 'packages-autoroller-branch-1']),
const FakeCommand(
command: <String>[
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
'--verbose',
'update-packages',
'--force-upgrade',
],
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: '''
M packages/foo/pubspec.yaml
M packages/bar/pubspec.yaml
M dev/integration_tests/test_foo/pubspec.yaml
'''),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
], stdout: '''
''',
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: '''
M packages/foo/pubspec.yaml
M packages/bar/pubspec.yaml
M dev/integration_tests/test_foo/pubspec.yaml
'''),
const FakeCommand(command: <String>[
'git',
'add',
'--all',
]),
const FakeCommand(command: <String>[
'git',
'commit',
'--message',
'roll packages',
'--author="flutter-pub-roller-bot <flutter-pub-roller-bot@google.com>"',
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: '000deadbeef'),
const FakeCommand(command: <String>[
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
'--no-gradle-generation',
'--no-exclusion',
]),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
], stdout: '''
''',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(
command: <String>[
'git',
'commit',
'--message',
'roll packages',
'--author="flutter-pub-roller-bot <flutter-pub-roller-bot@google.com>"',
],
),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: '000deadbeef'),
const FakeCommand(
command: <String>[
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
'--no-gradle-generation',
'--no-exclusion',
],
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: '''
M dev/integration_tests/ui/android/project-app.lockfile
M examples/image_list/android/project-app.lockfile
'''),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
], stdout: '''
''',
),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: '''
M dev/integration_tests/ui/android/project-app.lockfile
M examples/image_list/android/project-app.lockfile
'''),
const FakeCommand(command: <String>[
'git',
'add',
'--all',
]),
const FakeCommand(command: <String>[
'git',
'commit',
'--message',
'Re-generate Gradle lockfiles',
'--author="flutter-pub-roller-bot <flutter-pub-roller-bot@google.com>"',
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: '234deadbeef'),
const FakeCommand(command: <String>[
'git',
'push',
'https://$token@github.com/$orgName/flutter.git',
'packages-autoroller-branch-1:packages-autoroller-branch-1',
]),
const FakeCommand(command: <String>[
'gh',
'pr',
'create',
'--title',
'Roll pub packages',
'--body',
'This PR was generated by `flutter update-packages --force-upgrade`.',
'--head',
'flutter-roller:packages-autoroller-branch-1',
'--base',
FrameworkRepository.defaultBranch,
'--label',
'tool',
'--label',
'autosubmit',
]),
const FakeCommand(command: <String>[
'gh',
'auth',
'logout',
'--hostname',
'github.com',
]),
''',
),
const FakeCommand(command: <String>['git', 'add', '--all']),
const FakeCommand(
command: <String>[
'git',
'commit',
'--message',
'Re-generate Gradle lockfiles',
'--author="flutter-pub-roller-bot <flutter-pub-roller-bot@google.com>"',
],
),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: '234deadbeef'),
const FakeCommand(
command: <String>[
'git',
'push',
'https://$token@github.com/$orgName/flutter.git',
'packages-autoroller-branch-1:packages-autoroller-branch-1',
],
),
const FakeCommand(
command: <String>[
'gh',
'pr',
'create',
'--title',
'Roll pub packages',
'--body',
'This PR was generated by `flutter update-packages --force-upgrade`.',
'--head',
'flutter-roller:packages-autoroller-branch-1',
'--base',
FrameworkRepository.defaultBranch,
'--label',
'tool',
'--label',
'autosubmit',
],
),
const FakeCommand(command: <String>['gh', 'auth', 'logout', '--hostname', 'github.com']),
]);
final Future<void> rollFuture = autoroller.roll();
final String givenToken =
await controller.stream.transform(const Utf8Decoder()).join();
final String givenToken = await controller.stream.transform(const Utf8Decoder()).join();
expect(givenToken.trim(), token);
await rollFuture;
expect(processManager, hasNoRemainingExpectations);
@@ -550,16 +475,14 @@ void main() {
test('validates that file exists at --token option', () async {
await expectLater(
() => run(
<String>['--token', tokenPath],
fs: fileSystem,
processManager: processManager,
() => run(<String>['--token', tokenPath], fs: fileSystem, processManager: processManager),
throwsA(
isA<ArgumentError>().having(
(ArgumentError err) => err.message,
'message',
contains('Provided token path $tokenPath but no file exists at'),
),
),
throwsA(isA<ArgumentError>().having(
(ArgumentError err) => err.message,
'message',
contains('Provided token path $tokenPath but no file exists at'),
)),
);
expect(processManager, hasNoRemainingExpectations);
});
@@ -569,16 +492,14 @@ void main() {
..createSync(recursive: true)
..writeAsStringSync('');
await expectLater(
() => run(
<String>['--token', tokenPath],
fs: fileSystem,
processManager: processManager,
() => run(<String>['--token', tokenPath], fs: fileSystem, processManager: processManager),
throwsA(
isA<ArgumentError>().having(
(ArgumentError err) => err.message,
'message',
contains('Tried to read a GitHub access token from file $tokenPath but it was empty'),
),
),
throwsA(isA<ArgumentError>().having(
(ArgumentError err) => err.message,
'message',
contains('Tried to read a GitHub access token from file $tokenPath but it was empty'),
)),
);
expect(processManager, hasNoRemainingExpectations);
});
@@ -613,10 +534,7 @@ void main() {
final Context ctx = Context(style: Style.posix);
test('empty input returns NoDiff', () {
expect(
CheckoutStatePostGradleRegeneration('', ctx),
const NoDiff(),
);
expect(CheckoutStatePostGradleRegeneration('', ctx), const NoDiff());
});
test('only *.lockfile changes returns OnlyLockfileChanges', () {
@@ -660,6 +578,7 @@ $malformedLine
}
class _NoOpStdin extends Fake implements io.Stdin {}
class _NoOpStdout extends Fake implements io.Stdout {
@override
void writeln([Object? object]) {}

View File

@@ -78,42 +78,22 @@ vars = {
const String commit2 = 'def456';
const String message = 'This is a commit message.';
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path
.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
]),
const FakeCommand(command: <String>[
'git',
'checkout',
EngineRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit1),
const FakeCommand(command: <String>[
'git',
'status',
'--porcelain',
]),
const FakeCommand(command: <String>[
'git',
'commit',
'--message',
message,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit2),
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
],
),
const FakeCommand(command: <String>['git', 'checkout', EngineRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit1),
const FakeCommand(command: <String>['git', 'status', '--porcelain']),
const FakeCommand(command: <String>['git', 'commit', '--message', message]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit2),
]);
final Checkouts checkouts = Checkouts(
@@ -136,41 +116,25 @@ vars = {
const String commit2 = 'def456';
const String message = 'This is a commit message.';
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path
.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
]),
const FakeCommand(command: <String>[
'git',
'checkout',
EngineRepository.defaultBranch,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit1),
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
],
),
const FakeCommand(command: <String>['git', 'checkout', EngineRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit1),
const FakeCommand(
command: <String>['git', 'status', '--porcelain'],
stdout: 'MM path/to/file.txt',
),
const FakeCommand(command: <String>[
'git',
'commit',
'--message',
message,
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit2),
const FakeCommand(command: <String>['git', 'commit', '--message', message]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit2),
]);
final Checkouts checkouts = Checkouts(
@@ -186,43 +150,47 @@ vars = {
expect(processManager.hasRemainingExpectations, false);
});
test('updateCandidateBranchVersion() returns false if branch is the same as version file', () async {
const String branch = 'flutter-2.15-candidate.3';
final File versionFile = fileSystem.file('/release-candidate-branch.version')..writeAsStringSync(branch);
test(
'updateCandidateBranchVersion() returns false if branch is the same as version file',
() async {
const String branch = 'flutter-2.15-candidate.3';
final File versionFile = fileSystem.file('/release-candidate-branch.version')
..writeAsStringSync(branch);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final FrameworkRepository repo = FrameworkRepository(checkouts);
final bool didUpdate = await repo.updateCandidateBranchVersion(branch, versionFile: versionFile);
expect(didUpdate, false);
});
final FrameworkRepository repo = FrameworkRepository(checkouts);
final bool didUpdate = await repo.updateCandidateBranchVersion(
branch,
versionFile: versionFile,
);
expect(didUpdate, false);
},
);
test('updateEngineRevision() returns false if newCommit is the same as version file', () async {
const String commit1 = 'abc123';
const String commit2 = 'def456';
final File engineVersionFile = fileSystem.file('/engine.version')..writeAsStringSync(commit2);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path
.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
]),
const FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: commit1),
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
],
),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit1),
]);
final Checkouts checkouts = Checkouts(
@@ -234,90 +202,88 @@ vars = {
);
final FrameworkRepository repo = FrameworkRepository(checkouts);
final bool didUpdate = await repo.updateEngineRevision(commit2, engineVersionFile: engineVersionFile);
final bool didUpdate = await repo.updateEngineRevision(
commit2,
engineVersionFile: engineVersionFile,
);
expect(didUpdate, false);
});
test('framework repo set as localUpstream ensures requiredLocalBranches exist locally', () async {
const String commit = 'deadbeef';
const String candidateBranch = 'flutter-1.2-candidate.3';
bool createdCandidateBranch = false;
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
]),
FakeCommand(
command: const <String>['git', 'checkout', candidateBranch, '--'],
onRun: (_) => createdCandidateBranch = true,
),
const FakeCommand(
command: <String>['git', 'checkout', 'stable', '--'],
),
const FakeCommand(
command: <String>['git', 'checkout', 'beta', '--'],
),
const FakeCommand(
command: <String>['git', 'checkout', FrameworkRepository.defaultBranch, '--'],
),
const FakeCommand(
command: <String>['git', 'checkout', FrameworkRepository.defaultBranch],
),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: commit,
),
]);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
test(
'framework repo set as localUpstream ensures requiredLocalBranches exist locally',
() async {
const String commit = 'deadbeef';
const String candidateBranch = 'flutter-1.2-candidate.3';
bool createdCandidateBranch = false;
processManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
FrameworkRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'framework'),
],
),
FakeCommand(
command: const <String>['git', 'checkout', candidateBranch, '--'],
onRun: (_) => createdCandidateBranch = true,
),
const FakeCommand(command: <String>['git', 'checkout', 'stable', '--']),
const FakeCommand(command: <String>['git', 'checkout', 'beta', '--']),
const FakeCommand(
command: <String>['git', 'checkout', FrameworkRepository.defaultBranch, '--'],
),
const FakeCommand(
command: <String>['git', 'checkout', FrameworkRepository.defaultBranch],
),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit),
]);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
parentDirectory: fileSystem.directory(rootDir),
platform: platform,
processManager: processManager,
stdio: stdio,
);
final Repository repo = FrameworkRepository(
checkouts,
additionalRequiredLocalBranches: <String>[candidateBranch],
localUpstream: true,
);
// call this so that repo.lazilyInitialize() is called.
await repo.checkoutDirectory;
final Repository repo = FrameworkRepository(
checkouts,
additionalRequiredLocalBranches: <String>[candidateBranch],
localUpstream: true,
);
// call this so that repo.lazilyInitialize() is called.
await repo.checkoutDirectory;
expect(processManager.hasRemainingExpectations, false);
expect(createdCandidateBranch, true);
});
expect(processManager.hasRemainingExpectations, false);
expect(createdCandidateBranch, true);
},
);
test('engine repo set as localUpstream ensures requiredLocalBranches exist locally', () async {
const String commit = 'deadbeef';
const String candidateBranch = 'flutter-1.2-candidate.3';
bool createdCandidateBranch = false;
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
]),
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
fileSystem.path.join(rootDir, 'flutter_conductor_checkouts', 'engine'),
],
),
FakeCommand(
command: const <String>['git', 'checkout', candidateBranch, '--'],
onRun: (_) => createdCandidateBranch = true,
),
const FakeCommand(
command: <String>['git', 'checkout', EngineRepository.defaultBranch],
),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: commit,
),
const FakeCommand(command: <String>['git', 'checkout', EngineRepository.defaultBranch]),
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commit),
]);
final Checkouts checkouts = Checkouts(
fileSystem: fileSystem,
@@ -353,25 +319,19 @@ bbbcae73699263764ad4421a4b2ca3952a6f96cb refs/heads/stable
Extraneous debug information that should be ignored.
''';
processManager.addCommands(const <FakeCommand>[
FakeCommand(command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
'${rootDir}flutter_conductor_checkouts/engine',
]),
FakeCommand(command: <String>[
'git',
'checkout',
'main',
]),
FakeCommand(command: <String>[
'git',
'rev-parse',
'HEAD',
], stdout: revision),
FakeCommand(
command: <String>[
'git',
'clone',
'--origin',
'upstream',
'--',
EngineRepository.defaultUpstream,
'${rootDir}flutter_conductor_checkouts/engine',
],
),
FakeCommand(command: <String>['git', 'checkout', 'main']),
FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: revision),
FakeCommand(
command: <String>['git', 'ls-remote', '--heads', remoteName],
stdout: lsRemoteOutput,
@@ -385,18 +345,12 @@ Extraneous debug information that should be ignored.
stdio: stdio,
);
final Repository repo = EngineRepository(
checkouts,
localUpstream: true,
);
final Repository repo = EngineRepository(checkouts, localUpstream: true);
final List<String> branchNames = await repo.listRemoteBranches(remoteName);
expect(branchNames, equals(<String>[
'experiment',
'feature-a',
'feature-b',
'fix_bug_1234',
'stable',
]));
expect(
branchNames,
equals(<String>['experiment', 'feature-a', 'feature-b', 'fix_bug_1234', 'stable']),
);
});
});
}

File diff suppressed because it is too large Load Diff

View File

@@ -12,31 +12,27 @@ import './common.dart';
void main() {
test('writeStateToFile() pretty-prints JSON with 2 spaces', () {
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final File stateFile = fileSystem.file('/path/to/statefile.json')
..createSync(recursive: true);
final File stateFile = fileSystem.file('/path/to/statefile.json')..createSync(recursive: true);
const String candidateBranch = 'flutter-2.3-candidate.0';
final pb.ConductorState state = pb.ConductorState.create()
..releaseChannel = 'stable'
..releaseVersion = '2.3.4'
..engine = (pb.Repository.create()
..candidateBranch = candidateBranch
..upstream = (pb.Remote.create()
..name = 'upstream'
..url = 'git@github.com:flutter/engine.git'
)
)
..framework = (pb.Repository.create()
..candidateBranch = candidateBranch
..upstream = (pb.Remote.create()
..name = 'upstream'
..url = 'git@github.com:flutter/flutter.git'
)
);
writeStateToFile(
stateFile,
state,
<String>['[status] hello world'],
);
final pb.ConductorState state =
pb.ConductorState.create()
..releaseChannel = 'stable'
..releaseVersion = '2.3.4'
..engine =
(pb.Repository.create()
..candidateBranch = candidateBranch
..upstream =
(pb.Remote.create()
..name = 'upstream'
..url = 'git@github.com:flutter/engine.git'))
..framework =
(pb.Repository.create()
..candidateBranch = candidateBranch
..upstream =
(pb.Remote.create()
..name = 'upstream'
..url = 'git@github.com:flutter/flutter.git'));
writeStateToFile(stateFile, state, <String>['[status] hello world']);
final String serializedState = stateFile.readAsStringSync();
const String expectedString = '''
{

View File

@@ -26,80 +26,83 @@ void main() {
expect(version.type, VersionType.gitDescribe);
});
});
group('Version.increment()', () {
test('throws exception on nonsensical `level`', () {
final List<String> levels = <String>['f', '0', 'xyz'];
for (final String level in levels) {
group(
'Version.increment()',
() {
test('throws exception on nonsensical `level`', () {
final List<String> levels = <String>['f', '0', 'xyz'];
for (final String level in levels) {
final Version version = Version.fromString('1.0.0-0.0.pre');
expect(
() => Version.increment(version, level).toString(),
throwsExceptionWith('Unknown increment level $level.'),
);
}
});
test('does not support incrementing x', () {
const String level = 'x';
final Version version = Version.fromString('1.0.0-0.0.pre');
expect(
() => Version.increment(version, level).toString(),
throwsExceptionWith('Unknown increment level $level.'),
throwsExceptionWith('Incrementing $level is not supported by this tool'),
);
}
});
});
test('does not support incrementing x', () {
const String level = 'x';
test('successfully increments y', () {
const String level = 'y';
final Version version = Version.fromString('1.0.0-0.0.pre');
expect(
() => Version.increment(version, level).toString(),
throwsExceptionWith(
'Incrementing $level is not supported by this tool'),
);
});
Version version = Version.fromString('1.0.0-0.0.pre');
expect(Version.increment(version, level).toString(), '1.1.0-0.0.pre');
test('successfully increments y', () {
const String level = 'y';
version = Version.fromString('10.20.0-40.50.pre');
expect(Version.increment(version, level).toString(), '10.21.0-0.0.pre');
Version version = Version.fromString('1.0.0-0.0.pre');
expect(Version.increment(version, level).toString(), '1.1.0-0.0.pre');
version = Version.fromString('1.18.0-3.0.pre');
expect(Version.increment(version, level).toString(), '1.19.0-0.0.pre');
});
version = Version.fromString('10.20.0-40.50.pre');
expect(Version.increment(version, level).toString(), '10.21.0-0.0.pre');
test('successfully increments z', () {
const String level = 'z';
version = Version.fromString('1.18.0-3.0.pre');
expect(Version.increment(version, level).toString(), '1.19.0-0.0.pre');
});
Version version = Version.fromString('1.0.0');
expect(Version.increment(version, level).toString(), '1.0.1');
test('successfully increments z', () {
const String level = 'z';
version = Version.fromString('10.20.0');
expect(Version.increment(version, level).toString(), '10.20.1');
Version version = Version.fromString('1.0.0');
expect(Version.increment(version, level).toString(), '1.0.1');
version = Version.fromString('1.18.3');
expect(Version.increment(version, level).toString(), '1.18.4');
});
version = Version.fromString('10.20.0');
expect(Version.increment(version, level).toString(), '10.20.1');
test('does not support incrementing m', () {
const String level = 'm';
version = Version.fromString('1.18.3');
expect(Version.increment(version, level).toString(), '1.18.4');
});
final Version version = Version.fromString('1.0.0-0.0.pre');
expect(
() => Version.increment(version, level).toString(),
throwsAssertionWith("Do not increment 'm' via Version.increment"),
);
});
test('does not support incrementing m', () {
const String level = 'm';
test('successfully increments n', () {
const String level = 'n';
final Version version = Version.fromString('1.0.0-0.0.pre');
expect(
() => Version.increment(version, level).toString(),
throwsAssertionWith("Do not increment 'm' via Version.increment"),
);
});
Version version = Version.fromString('1.0.0-0.0.pre');
expect(Version.increment(version, level).toString(), '1.0.0-0.1.pre');
test('successfully increments n', () {
const String level = 'n';
version = Version.fromString('10.20.0-40.50.pre');
expect(Version.increment(version, level).toString(), '10.20.0-40.51.pre');
Version version = Version.fromString('1.0.0-0.0.pre');
expect(Version.increment(version, level).toString(), '1.0.0-0.1.pre');
version = Version.fromString('10.20.0-40.50.pre');
expect(Version.increment(version, level).toString(), '10.20.0-40.51.pre');
version = Version.fromString('1.18.0-3.0.pre');
expect(Version.increment(version, level).toString(), '1.18.0-3.1.pre');
});
}, onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
});
version = Version.fromString('1.18.0-3.0.pre');
expect(Version.increment(version, level).toString(), '1.18.0-3.1.pre');
});
},
onPlatform: <String, dynamic>{
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
},
);
group('.ensureValid()', () {
test('throws when x does not match', () {
@@ -157,9 +160,7 @@ void main() {
final Version version = Version.fromString(versionString);
expect(
() => version.ensureValid(candidateBranch, ReleaseType.STABLE_HOTFIX),
throwsExceptionWith(
'Candidate branch $candidateBranch does not match the pattern',
),
throwsExceptionWith('Candidate branch $candidateBranch does not match the pattern'),
);
});
});