Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 88f8410

Browse files
[flutter_plugin_tools] Convert publish tests to mock git (#4263)
Replaces the use of an actual git repository on the filesystem with mock git output and an in-memory filesystem. This: - makes the tests more hermetic. - simplifies the setup of some tests considerably, avoiding the need to run the command once to set up the expected state before running a second time for the intended test. - eliminates some of the special handling in the test's custom process runner (making it easier to eliminate in a PR that will follow after). Also adds some output checking in a couple of tests that didn't have enough to ensure that they were necessarily testing the right thing (e.g., testing that a specific thing didn't happen, but not checking that the publish step that could have caused that thing to happen even ran at all).
1 parent 5b5f801 commit 88f8410

File tree

2 files changed

+285
-302
lines changed

2 files changed

+285
-302
lines changed

script/tool/lib/src/publish_plugin_command.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,9 @@ Safe to ignore if the package is deleted in this commit.
355355
final String tag = _getTag(packageDir);
356356
print('Tagging release $tag...');
357357
if (!getBoolArg(_dryRunFlag)) {
358-
final io.ProcessResult result = await processRunner.run(
359-
'git',
358+
final io.ProcessResult result = await (await gitDir).runCommand(
360359
<String>['tag', tag],
361-
workingDir: packageDir,
362-
logOnError: true,
360+
throwOnError: false,
363361
);
364362
if (result.exitCode != 0) {
365363
return false;
@@ -400,11 +398,9 @@ Safe to ignore if the package is deleted in this commit.
400398
}
401399

402400
Future<bool> _checkGitStatus(Directory packageDir) async {
403-
final io.ProcessResult statusResult = await processRunner.run(
404-
'git',
401+
final io.ProcessResult statusResult = await (await gitDir).runCommand(
405402
<String>['status', '--porcelain', '--ignored', packageDir.absolute.path],
406-
workingDir: packageDir,
407-
logOnError: true,
403+
throwOnError: false,
408404
);
409405
if (statusResult.exitCode != 0) {
410406
return false;
@@ -421,11 +417,9 @@ Safe to ignore if the package is deleted in this commit.
421417
}
422418

423419
Future<String?> _verifyRemote(String remote) async {
424-
final io.ProcessResult getRemoteUrlResult = await processRunner.run(
425-
'git',
420+
final io.ProcessResult getRemoteUrlResult = await (await gitDir).runCommand(
426421
<String>['remote', 'get-url', remote],
427-
workingDir: packagesDir,
428-
logOnError: true,
422+
throwOnError: false,
429423
);
430424
if (getRemoteUrlResult.exitCode != 0) {
431425
return null;
@@ -494,11 +488,9 @@ Safe to ignore if the package is deleted in this commit.
494488
}
495489
}
496490
if (!getBoolArg(_dryRunFlag)) {
497-
final io.ProcessResult result = await processRunner.run(
498-
'git',
491+
final io.ProcessResult result = await (await gitDir).runCommand(
499492
<String>['push', remote.name, tag],
500-
workingDir: packagesDir,
501-
logOnError: true,
493+
throwOnError: false,
502494
);
503495
if (result.exitCode != 0) {
504496
return false;

0 commit comments

Comments
 (0)