mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 17:28:42 +08:00
[flutter_plugin_tools] Move publish tests to RecordingProcessRunner (#4269)
Replaces almost all of the `TestProcessRunner`, which was specific to the `publish` tests, with the repo-standard `RecordingProcessRunner` (which now has most of the capabilities these tests need). This finishes aligning these tests with the rest of the repository tests, so they will be easier to maintain as part of the overall repository. To support this, `RecordingProcessRunner` was modified slightly to return a succeeding, no-output process by default for `start`. That makes it consistent with its existing `run` behavior, so is a good change in general.
This commit is contained in:
@ -49,11 +49,6 @@ void main() {
|
|||||||
final Directory plugin2Dir =
|
final Directory plugin2Dir =
|
||||||
createFakePlugin('plugin_tools_test_package_b', packagesDir);
|
createFakePlugin('plugin_tools_test_package_b', packagesDir);
|
||||||
|
|
||||||
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
|
|
||||||
MockProcess(),
|
|
||||||
MockProcess(),
|
|
||||||
];
|
|
||||||
|
|
||||||
await runCapturingPrint(runner, <String>['publish-check']);
|
await runCapturingPrint(runner, <String>['publish-check']);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -87,10 +82,6 @@ void main() {
|
|||||||
final Directory dir = createFakePlugin('c', packagesDir);
|
final Directory dir = createFakePlugin('c', packagesDir);
|
||||||
await dir.childFile('pubspec.yaml').writeAsString('bad-yaml');
|
await dir.childFile('pubspec.yaml').writeAsString('bad-yaml');
|
||||||
|
|
||||||
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
|
|
||||||
MockProcess(),
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(() => runCapturingPrint(runner, <String>['publish-check']),
|
expect(() => runCapturingPrint(runner, <String>['publish-check']),
|
||||||
throwsA(isA<ToolExit>()));
|
throwsA(isA<ToolExit>()));
|
||||||
});
|
});
|
||||||
@ -245,10 +236,6 @@ void main() {
|
|||||||
createFakePlugin('no_publish_a', packagesDir, version: '0.1.0');
|
createFakePlugin('no_publish_a', packagesDir, version: '0.1.0');
|
||||||
createFakePlugin('no_publish_b', packagesDir, version: '0.2.0');
|
createFakePlugin('no_publish_b', packagesDir, version: '0.2.0');
|
||||||
|
|
||||||
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
|
|
||||||
MockProcess(),
|
|
||||||
];
|
|
||||||
|
|
||||||
final List<String> output = await runCapturingPrint(
|
final List<String> output = await runCapturingPrint(
|
||||||
runner, <String>['publish-check', '--machine']);
|
runner, <String>['publish-check', '--machine']);
|
||||||
|
|
||||||
@ -318,10 +305,6 @@ void main() {
|
|||||||
|
|
||||||
await plugin1Dir.childFile('pubspec.yaml').writeAsString('bad-yaml');
|
await plugin1Dir.childFile('pubspec.yaml').writeAsString('bad-yaml');
|
||||||
|
|
||||||
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
|
|
||||||
MockProcess(),
|
|
||||||
];
|
|
||||||
|
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
final List<String> output = await runCapturingPrint(
|
final List<String> output = await runCapturingPrint(
|
||||||
runner, <String>['publish-check', '--machine'],
|
runner, <String>['publish-check', '--machine'],
|
||||||
|
@ -10,7 +10,6 @@ import 'package:args/command_runner.dart';
|
|||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
import 'package:file/memory.dart';
|
import 'package:file/memory.dart';
|
||||||
import 'package:flutter_plugin_tools/src/common/core.dart';
|
import 'package:flutter_plugin_tools/src/common/core.dart';
|
||||||
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
|
|
||||||
import 'package:flutter_plugin_tools/src/publish_plugin_command.dart';
|
import 'package:flutter_plugin_tools/src/publish_plugin_command.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:http/testing.dart';
|
import 'package:http/testing.dart';
|
||||||
@ -23,13 +22,11 @@ import 'mocks.dart';
|
|||||||
import 'util.dart';
|
import 'util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const String testPluginName = 'foo';
|
final String flutterCommand = getFlutterCommand(const LocalPlatform());
|
||||||
|
|
||||||
late Directory packagesDir;
|
late Directory packagesDir;
|
||||||
late Directory pluginDir;
|
|
||||||
late MockGitDir gitDir;
|
late MockGitDir gitDir;
|
||||||
late TestProcessRunner processRunner;
|
late TestProcessRunner processRunner;
|
||||||
late RecordingProcessRunner gitProcessRunner;
|
|
||||||
late CommandRunner<void> commandRunner;
|
late CommandRunner<void> commandRunner;
|
||||||
late MockStdin mockStdin;
|
late MockStdin mockStdin;
|
||||||
late FileSystem fileSystem;
|
late FileSystem fileSystem;
|
||||||
@ -44,25 +41,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
fileSystem = MemoryFileSystem();
|
fileSystem = MemoryFileSystem();
|
||||||
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
||||||
// TODO(stuartmorgan): Move this from setup to individual tests.
|
|
||||||
pluginDir =
|
|
||||||
createFakePlugin(testPluginName, packagesDir, examples: <String>[]);
|
|
||||||
assert(pluginDir != null && pluginDir.existsSync());
|
|
||||||
|
|
||||||
gitProcessRunner = RecordingProcessRunner();
|
processRunner = TestProcessRunner();
|
||||||
gitDir = MockGitDir();
|
gitDir = MockGitDir();
|
||||||
when(gitDir.path).thenReturn(packagesDir.parent.path);
|
when(gitDir.path).thenReturn(packagesDir.parent.path);
|
||||||
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
||||||
.thenAnswer((Invocation invocation) {
|
.thenAnswer((Invocation invocation) {
|
||||||
final List<String> arguments =
|
final List<String> arguments =
|
||||||
invocation.positionalArguments[0]! as List<String>;
|
invocation.positionalArguments[0]! as List<String>;
|
||||||
// Attach the first argument to the command to make targeting the mock
|
// Route git calls through the process runner, to make mock output
|
||||||
// results easier.
|
// consistent with outer processes. Attach the first argument to the
|
||||||
|
// command to make targeting the mock results easier.
|
||||||
final String gitCommand = arguments.removeAt(0);
|
final String gitCommand = arguments.removeAt(0);
|
||||||
return gitProcessRunner.run('git-$gitCommand', arguments);
|
return processRunner.run('git-$gitCommand', arguments);
|
||||||
});
|
});
|
||||||
|
|
||||||
processRunner = TestProcessRunner();
|
|
||||||
mockStdin = MockStdin();
|
mockStdin = MockStdin();
|
||||||
commandRunner = CommandRunner<void>('tester', '')
|
commandRunner = CommandRunner<void>('tester', '')
|
||||||
..addCommand(PublishPluginCommand(packagesDir,
|
..addCommand(PublishPluginCommand(packagesDir,
|
||||||
@ -99,18 +92,17 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('refuses to proceed with dirty files', () async {
|
test('refuses to proceed with dirty files', () async {
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-status'] = <io.Process>[
|
final Directory pluginDir =
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
|
processRunner.mockProcessesForExecutable['git-status'] = <io.Process>[
|
||||||
MockProcess(stdout: '?? ${pluginDir.childFile('tmp').path}\n')
|
MockProcess(stdout: '?? ${pluginDir.childFile('tmp').path}\n')
|
||||||
];
|
];
|
||||||
|
|
||||||
Error? commandError;
|
Error? commandError;
|
||||||
final List<String> output = await runCapturingPrint(
|
final List<String> output = await runCapturingPrint(commandRunner,
|
||||||
commandRunner, <String>[
|
<String>['publish-plugin', '--package', 'foo', '--no-push-tags'],
|
||||||
'publish-plugin',
|
errorHandler: (Error e) {
|
||||||
'--package',
|
|
||||||
testPluginName,
|
|
||||||
'--no-push-tags'
|
|
||||||
], errorHandler: (Error e) {
|
|
||||||
commandError = e;
|
commandError = e;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -128,13 +120,15 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('fails immediately if the remote doesn\'t exist', () async {
|
test('fails immediately if the remote doesn\'t exist', () async {
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-remote'] = <io.Process>[
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
|
processRunner.mockProcessesForExecutable['git-remote'] = <io.Process>[
|
||||||
MockProcess(exitCode: 1),
|
MockProcess(exitCode: 1),
|
||||||
];
|
];
|
||||||
|
|
||||||
Error? commandError;
|
Error? commandError;
|
||||||
final List<String> output = await runCapturingPrint(commandRunner,
|
final List<String> output = await runCapturingPrint(
|
||||||
<String>['publish-plugin', '--package', testPluginName],
|
commandRunner, <String>['publish-plugin', '--package', 'foo'],
|
||||||
errorHandler: (Error e) {
|
errorHandler: (Error e) {
|
||||||
commandError = e;
|
commandError = e;
|
||||||
});
|
});
|
||||||
@ -149,19 +143,18 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("doesn't validate the remote if it's not pushing tags", () async {
|
test("doesn't validate the remote if it's not pushing tags", () async {
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
// Checking the remote should fail.
|
// Checking the remote should fail.
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-remote'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-remote'] = <io.Process>[
|
||||||
MockProcess(exitCode: 1),
|
MockProcess(exitCode: 1),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Immediately return 0 when running `pub publish`.
|
final List<String> output = await runCapturingPrint(
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
commandRunner, <String>[
|
||||||
|
|
||||||
final List<String> output =
|
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release'
|
'--no-tag-release'
|
||||||
]);
|
]);
|
||||||
@ -169,17 +162,15 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
output,
|
output,
|
||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains('Running `pub publish ` in /packages/$testPluginName...'),
|
contains('Running `pub publish ` in /packages/foo...'),
|
||||||
contains('Package published!'),
|
contains('Package published!'),
|
||||||
contains('Released [$testPluginName] successfully.'),
|
contains('Released [foo] successfully.'),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can publish non-flutter package', () async {
|
test('can publish non-flutter package', () async {
|
||||||
const String packageName = 'a_package';
|
const String packageName = 'a_package';
|
||||||
createFakePackage(packageName, packagesDir);
|
createFakePackage(packageName, packagesDir);
|
||||||
// Immediately return 0 when running `pub publish`.
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
|
|
||||||
final List<String> output = await runCapturingPrint(
|
final List<String> output = await runCapturingPrint(
|
||||||
commandRunner, <String>[
|
commandRunner, <String>[
|
||||||
@ -204,15 +195,21 @@ void main() {
|
|||||||
|
|
||||||
group('Publishes package', () {
|
group('Publishes package', () {
|
||||||
test('while showing all output from pub publish to the user', () async {
|
test('while showing all output from pub publish to the user', () async {
|
||||||
processRunner.mockPublishStdout = 'Foo';
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
processRunner.mockPublishStderr = 'Bar';
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
|
|
||||||
final List<String> output =
|
processRunner.mockProcessesForExecutable[flutterCommand] = <io.Process>[
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
MockProcess(
|
||||||
|
stdout: 'Foo',
|
||||||
|
stderr: 'Bar',
|
||||||
|
stdoutEncoding: utf8,
|
||||||
|
stderrEncoding: utf8) // pub publish
|
||||||
|
];
|
||||||
|
|
||||||
|
final List<String> output = await runCapturingPrint(
|
||||||
|
commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release'
|
'--no-tag-release'
|
||||||
]);
|
]);
|
||||||
@ -226,13 +223,14 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('forwards input from the user to `pub publish`', () async {
|
test('forwards input from the user to `pub publish`', () async {
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
mockStdin.mockUserInputs.add(utf8.encode('user input'));
|
mockStdin.mockUserInputs.add(utf8.encode('user input'));
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
|
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release'
|
'--no-tag-release'
|
||||||
]);
|
]);
|
||||||
@ -242,35 +240,38 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('forwards --pub-publish-flags to pub publish', () async {
|
test('forwards --pub-publish-flags to pub publish', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
final Directory pluginDir =
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release',
|
'--no-tag-release',
|
||||||
'--pub-publish-flags',
|
'--pub-publish-flags',
|
||||||
'--dry-run,--server=foo'
|
'--dry-run,--server=foo'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(processRunner.mockPublishArgs.length, 4);
|
expect(
|
||||||
expect(processRunner.mockPublishArgs[0], 'pub');
|
processRunner.recordedCalls,
|
||||||
expect(processRunner.mockPublishArgs[1], 'publish');
|
contains(ProcessCall(
|
||||||
expect(processRunner.mockPublishArgs[2], '--dry-run');
|
flutterCommand,
|
||||||
expect(processRunner.mockPublishArgs[3], '--server=foo');
|
const <String>['pub', 'publish', '--dry-run', '--server=foo'],
|
||||||
|
pluginDir.path)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'--skip-confirmation flag automatically adds --force to --pub-publish-flags',
|
'--skip-confirmation flag automatically adds --force to --pub-publish-flags',
|
||||||
() async {
|
() async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
_createMockCredentialFile();
|
_createMockCredentialFile();
|
||||||
|
final Directory pluginDir =
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release',
|
'--no-tag-release',
|
||||||
'--skip-confirmation',
|
'--skip-confirmation',
|
||||||
@ -278,22 +279,27 @@ void main() {
|
|||||||
'--server=foo'
|
'--server=foo'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(processRunner.mockPublishArgs.length, 4);
|
expect(
|
||||||
expect(processRunner.mockPublishArgs[0], 'pub');
|
processRunner.recordedCalls,
|
||||||
expect(processRunner.mockPublishArgs[1], 'publish');
|
contains(ProcessCall(
|
||||||
expect(processRunner.mockPublishArgs[2], '--server=foo');
|
flutterCommand,
|
||||||
expect(processRunner.mockPublishArgs[3], '--force');
|
const <String>['pub', 'publish', '--server=foo', '--force'],
|
||||||
|
pluginDir.path)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws if pub publish fails', () async {
|
test('throws if pub publish fails', () async {
|
||||||
processRunner.mockPublishCompleteCode = 128;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
|
processRunner.mockProcessesForExecutable[flutterCommand] = <io.Process>[
|
||||||
|
MockProcess(exitCode: 128) // pub publish
|
||||||
|
];
|
||||||
|
|
||||||
Error? commandError;
|
Error? commandError;
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release',
|
'--no-tag-release',
|
||||||
], errorHandler: (Error e) {
|
], errorHandler: (Error e) {
|
||||||
@ -309,18 +315,21 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('publish, dry run', () async {
|
test('publish, dry run', () async {
|
||||||
|
final Directory pluginDir =
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--dry-run',
|
'--dry-run',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
'--no-tag-release',
|
'--no-tag-release',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
expect(
|
expect(
|
||||||
@ -335,30 +344,31 @@ void main() {
|
|||||||
|
|
||||||
group('Tags release', () {
|
group('Tags release', () {
|
||||||
test('with the version and name from the pubspec.yaml', () async {
|
test('with the version and name from the pubspec.yaml', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(processRunner.recordedCalls,
|
||||||
gitProcessRunner.recordedCalls,
|
contains(const ProcessCall('git-tag', <String>['foo-v0.0.1'], null)));
|
||||||
contains(const ProcessCall(
|
|
||||||
'git-tag', <String>['$testPluginName-v0.0.1'], null)));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('only if publishing succeeded', () async {
|
test('only if publishing succeeded', () async {
|
||||||
processRunner.mockPublishCompleteCode = 128;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
|
processRunner.mockProcessesForExecutable[flutterCommand] = <io.Process>[
|
||||||
|
MockProcess(exitCode: 128) // pub publish
|
||||||
|
];
|
||||||
|
|
||||||
Error? commandError;
|
Error? commandError;
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-push-tags',
|
'--no-push-tags',
|
||||||
], errorHandler: (Error e) {
|
], errorHandler: (Error e) {
|
||||||
commandError = e;
|
commandError = e;
|
||||||
@ -371,7 +381,7 @@ void main() {
|
|||||||
contains('Publish foo failed.'),
|
contains('Publish foo failed.'),
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
isNot(contains(
|
isNot(contains(
|
||||||
const ProcessCall('git-tag', <String>['foo-v0.0.1'], null))));
|
const ProcessCall('git-tag', <String>['foo-v0.0.1'], null))));
|
||||||
});
|
});
|
||||||
@ -379,7 +389,8 @@ void main() {
|
|||||||
|
|
||||||
group('Pushes tags', () {
|
group('Pushes tags', () {
|
||||||
test('requires user confirmation', () async {
|
test('requires user confirmation', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
mockStdin.readLineOutput = 'help';
|
mockStdin.readLineOutput = 'help';
|
||||||
|
|
||||||
Error? commandError;
|
Error? commandError;
|
||||||
@ -387,7 +398,7 @@ void main() {
|
|||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
], errorHandler: (Error e) {
|
], errorHandler: (Error e) {
|
||||||
commandError = e;
|
commandError = e;
|
||||||
});
|
});
|
||||||
@ -397,61 +408,63 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('to upstream by default', () async {
|
test('to upstream by default', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall('git-push',
|
contains(const ProcessCall(
|
||||||
<String>['upstream', '$testPluginName-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'foo-v0.0.1'], null)));
|
||||||
expect(
|
expect(
|
||||||
output,
|
output,
|
||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains('Released [$testPluginName] successfully.'),
|
contains('Released [foo] successfully.'),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('does not ask for user input if the --skip-confirmation flag is on',
|
test('does not ask for user input if the --skip-confirmation flag is on',
|
||||||
() async {
|
() async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
_createMockCredentialFile();
|
_createMockCredentialFile();
|
||||||
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--skip-confirmation',
|
'--skip-confirmation',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall('git-push',
|
contains(const ProcessCall(
|
||||||
<String>['upstream', '$testPluginName-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'foo-v0.0.1'], null)));
|
||||||
expect(
|
expect(
|
||||||
output,
|
output,
|
||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains('Released [$testPluginName] successfully.'),
|
contains('Released [foo] successfully.'),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('to upstream by default, dry run', () async {
|
test('to upstream by default, dry run', () async {
|
||||||
// Immediately return 1 when running `pub publish`. If dry-run does not work, test should throw.
|
final Directory pluginDir =
|
||||||
processRunner.mockPublishCompleteCode = 1;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output = await runCapturingPrint(commandRunner,
|
final List<String> output = await runCapturingPrint(commandRunner,
|
||||||
<String>['publish-plugin', '--package', testPluginName, '--dry-run']);
|
<String>['publish-plugin', '--package', 'foo', '--dry-run']);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
expect(
|
expect(
|
||||||
@ -459,57 +472,58 @@ void main() {
|
|||||||
containsAllInOrder(<String>[
|
containsAllInOrder(<String>[
|
||||||
'=============== DRY RUN ===============',
|
'=============== DRY RUN ===============',
|
||||||
'Running `pub publish ` in ${pluginDir.path}...\n',
|
'Running `pub publish ` in ${pluginDir.path}...\n',
|
||||||
'Tagging release $testPluginName-v0.0.1...',
|
'Tagging release foo-v0.0.1...',
|
||||||
'Pushing tag to upstream...',
|
'Pushing tag to upstream...',
|
||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('to different remotes based on a flag', () async {
|
test('to different remotes based on a flag', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--remote',
|
'--remote',
|
||||||
'origin',
|
'origin',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['origin', '$testPluginName-v0.0.1'], null)));
|
'git-push', <String>['origin', 'foo-v0.0.1'], null)));
|
||||||
expect(
|
expect(
|
||||||
output,
|
output,
|
||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains('Released [$testPluginName] successfully.'),
|
contains('Released [foo] successfully.'),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('only if tagging and pushing to remotes are both enabled', () async {
|
test('only if tagging and pushing to remotes are both enabled', () async {
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
createFakePlugin('foo', packagesDir, examples: <String>[]);
|
||||||
|
|
||||||
final List<String> output =
|
final List<String> output =
|
||||||
await runCapturingPrint(commandRunner, <String>[
|
await runCapturingPrint(commandRunner, <String>[
|
||||||
'publish-plugin',
|
'publish-plugin',
|
||||||
'--package',
|
'--package',
|
||||||
testPluginName,
|
'foo',
|
||||||
'--no-tag-release',
|
'--no-tag-release',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
expect(
|
expect(
|
||||||
output,
|
output,
|
||||||
containsAllInOrder(<Matcher>[
|
containsAllInOrder(<Matcher>[
|
||||||
contains('Running `pub publish ` in /packages/$testPluginName...'),
|
contains('Running `pub publish ` in /packages/foo...'),
|
||||||
contains('Package published!'),
|
contains('Package published!'),
|
||||||
contains('Released [$testPluginName] successfully.'),
|
contains('Released [foo] successfully.'),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -553,13 +567,11 @@ void main() {
|
|||||||
'plugin2',
|
'plugin2',
|
||||||
packagesDir.childDirectory('plugin2'),
|
packagesDir.childDirectory('plugin2'),
|
||||||
);
|
);
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
];
|
];
|
||||||
// Immediately return 0 when running `pub publish`.
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output = await runCapturingPrint(commandRunner,
|
final List<String> output = await runCapturingPrint(commandRunner,
|
||||||
@ -576,11 +588,11 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin1-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'plugin1-v0.0.1'], null)));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin2-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'plugin2-v0.0.1'], null)));
|
||||||
});
|
});
|
||||||
@ -634,17 +646,15 @@ void main() {
|
|||||||
|
|
||||||
// Git results for plugin0 having been released already, and plugin1 and
|
// Git results for plugin0 having been released already, and plugin1 and
|
||||||
// plugin2 being new.
|
// plugin2 being new.
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-tag'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-tag'] = <io.Process>[
|
||||||
MockProcess(stdout: 'plugin0-v0.0.1\n')
|
MockProcess(stdout: 'plugin0-v0.0.1\n')
|
||||||
];
|
];
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
];
|
];
|
||||||
|
|
||||||
// Immediately return 0 when running `pub publish`.
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output = await runCapturingPrint(commandRunner,
|
final List<String> output = await runCapturingPrint(commandRunner,
|
||||||
@ -661,11 +671,11 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin1-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'plugin1-v0.0.1'], null)));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin2-v0.0.1'], null)));
|
'git-push', <String>['upstream', 'plugin2-v0.0.1'], null)));
|
||||||
});
|
});
|
||||||
@ -706,7 +716,7 @@ void main() {
|
|||||||
final Directory pluginDir2 =
|
final Directory pluginDir2 =
|
||||||
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
@ -737,7 +747,7 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
});
|
});
|
||||||
@ -781,14 +791,12 @@ void main() {
|
|||||||
'plugin2', packagesDir.childDirectory('plugin2'),
|
'plugin2', packagesDir.childDirectory('plugin2'),
|
||||||
version: '0.0.2');
|
version: '0.0.2');
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
];
|
];
|
||||||
|
|
||||||
// Immediately return 0 when running `pub publish`.
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output2 = await runCapturingPrint(commandRunner,
|
final List<String> output2 = await runCapturingPrint(commandRunner,
|
||||||
@ -804,11 +812,11 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin1-v0.0.2'], null)));
|
'git-push', <String>['upstream', 'plugin1-v0.0.2'], null)));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin2-v0.0.2'], null)));
|
'git-push', <String>['upstream', 'plugin2-v0.0.2'], null)));
|
||||||
});
|
});
|
||||||
@ -854,14 +862,12 @@ void main() {
|
|||||||
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
||||||
pluginDir2.deleteSync(recursive: true);
|
pluginDir2.deleteSync(recursive: true);
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
];
|
];
|
||||||
|
|
||||||
// Immediately return 0 when running `pub publish`.
|
|
||||||
processRunner.mockPublishCompleteCode = 0;
|
|
||||||
mockStdin.readLineOutput = 'y';
|
mockStdin.readLineOutput = 'y';
|
||||||
|
|
||||||
final List<String> output2 = await runCapturingPrint(commandRunner,
|
final List<String> output2 = await runCapturingPrint(commandRunner,
|
||||||
@ -877,7 +883,7 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls,
|
processRunner.recordedCalls,
|
||||||
contains(const ProcessCall(
|
contains(const ProcessCall(
|
||||||
'git-push', <String>['upstream', 'plugin1-v0.0.2'], null)));
|
'git-push', <String>['upstream', 'plugin1-v0.0.2'], null)));
|
||||||
});
|
});
|
||||||
@ -922,12 +928,12 @@ void main() {
|
|||||||
'plugin2', packagesDir.childDirectory('plugin2'),
|
'plugin2', packagesDir.childDirectory('plugin2'),
|
||||||
version: '0.0.2');
|
version: '0.0.2');
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
];
|
];
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-tag'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-tag'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: 'plugin1-v0.0.2\n'
|
stdout: 'plugin1-v0.0.2\n'
|
||||||
'plugin2-v0.0.2\n')
|
'plugin2-v0.0.2\n')
|
||||||
@ -949,7 +955,7 @@ void main() {
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
});
|
});
|
||||||
@ -995,7 +1001,7 @@ void main() {
|
|||||||
'plugin2', packagesDir.childDirectory('plugin2'),
|
'plugin2', packagesDir.childDirectory('plugin2'),
|
||||||
version: '0.0.2');
|
version: '0.0.2');
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
stdout: '${pluginDir1.childFile('pubspec.yaml').path}\n'
|
||||||
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
'${pluginDir2.childFile('pubspec.yaml').path}\n')
|
||||||
@ -1020,7 +1026,7 @@ void main() {
|
|||||||
'However, the git release tag for this version (plugin2-v0.0.2) is not found.'),
|
'However, the git release tag for this version (plugin2-v0.0.2) is not found.'),
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
});
|
});
|
||||||
@ -1032,7 +1038,7 @@ void main() {
|
|||||||
final Directory pluginDir2 =
|
final Directory pluginDir2 =
|
||||||
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
createFakePlugin('plugin2', packagesDir.childDirectory('plugin2'));
|
||||||
|
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(
|
MockProcess(
|
||||||
stdout: '${pluginDir1.childFile('plugin1.dart').path}\n'
|
stdout: '${pluginDir1.childFile('plugin1.dart').path}\n'
|
||||||
'${pluginDir2.childFile('plugin2.dart').path}\n')
|
'${pluginDir2.childFile('plugin2.dart').path}\n')
|
||||||
@ -1050,7 +1056,7 @@ void main() {
|
|||||||
'Done!'
|
'Done!'
|
||||||
]));
|
]));
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
});
|
});
|
||||||
@ -1081,7 +1087,7 @@ void main() {
|
|||||||
|
|
||||||
final Directory flutterPluginTools =
|
final Directory flutterPluginTools =
|
||||||
createFakePlugin('flutter_plugin_tools', packagesDir);
|
createFakePlugin('flutter_plugin_tools', packagesDir);
|
||||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||||
MockProcess(stdout: flutterPluginTools.childFile('pubspec.yaml').path)
|
MockProcess(stdout: flutterPluginTools.childFile('pubspec.yaml').path)
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -1101,75 +1107,41 @@ void main() {
|
|||||||
),
|
),
|
||||||
isFalse);
|
isFalse);
|
||||||
expect(
|
expect(
|
||||||
gitProcessRunner.recordedCalls
|
processRunner.recordedCalls
|
||||||
.map((ProcessCall call) => call.executable),
|
.map((ProcessCall call) => call.executable),
|
||||||
isNot(contains('git-push')));
|
isNot(contains('git-push')));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestProcessRunner extends ProcessRunner {
|
/// An extension of [RecordingProcessRunner] that stores 'flutter pub publish'
|
||||||
|
/// calls so that their input streams can be checked in tests.
|
||||||
|
class TestProcessRunner extends RecordingProcessRunner {
|
||||||
// Most recent returned publish process.
|
// Most recent returned publish process.
|
||||||
late MockProcess mockPublishProcess;
|
late MockProcess mockPublishProcess;
|
||||||
final List<String> mockPublishArgs = <String>[];
|
|
||||||
|
|
||||||
String? mockPublishStdout;
|
|
||||||
String? mockPublishStderr;
|
|
||||||
int mockPublishCompleteCode = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<io.ProcessResult> run(
|
|
||||||
String executable,
|
|
||||||
List<String> args, {
|
|
||||||
Directory? workingDir,
|
|
||||||
bool exitOnError = false,
|
|
||||||
bool logOnError = false,
|
|
||||||
Encoding stdoutEncoding = io.systemEncoding,
|
|
||||||
Encoding stderrEncoding = io.systemEncoding,
|
|
||||||
}) async {
|
|
||||||
final io.ProcessResult result = io.Process.runSync(executable, args,
|
|
||||||
workingDirectory: workingDir?.path);
|
|
||||||
if (result.exitCode != 0) {
|
|
||||||
throw ToolExit(result.exitCode);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<io.Process> start(String executable, List<String> args,
|
Future<io.Process> start(String executable, List<String> args,
|
||||||
{Directory? workingDirectory}) async {
|
{Directory? workingDirectory}) async {
|
||||||
/// Never actually publish anything. Start is always and only used for this
|
final io.Process process =
|
||||||
/// since it returns something we can route stdin through.
|
await super.start(executable, args, workingDirectory: workingDirectory);
|
||||||
assert(executable == getFlutterCommand(const LocalPlatform()) &&
|
if (executable == getFlutterCommand(const LocalPlatform()) &&
|
||||||
args.isNotEmpty &&
|
args.isNotEmpty &&
|
||||||
args[0] == 'pub' &&
|
args[0] == 'pub' &&
|
||||||
args[1] == 'publish');
|
args[1] == 'publish') {
|
||||||
mockPublishArgs.addAll(args);
|
mockPublishProcess = process as MockProcess;
|
||||||
|
}
|
||||||
mockPublishProcess = MockProcess(
|
return process;
|
||||||
exitCode: mockPublishCompleteCode,
|
|
||||||
stdout: mockPublishStdout,
|
|
||||||
stderr: mockPublishStderr,
|
|
||||||
stdoutEncoding: utf8,
|
|
||||||
stderrEncoding: utf8,
|
|
||||||
);
|
|
||||||
return mockPublishProcess;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockStdin extends Mock implements io.Stdin {
|
class MockStdin extends Mock implements io.Stdin {
|
||||||
List<List<int>> mockUserInputs = <List<int>>[];
|
List<List<int>> mockUserInputs = <List<int>>[];
|
||||||
late StreamController<List<int>> _controller;
|
final StreamController<List<int>> _controller = StreamController<List<int>>();
|
||||||
String? readLineOutput;
|
String? readLineOutput;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<S> transform<S>(StreamTransformer<List<int>, S> streamTransformer) {
|
Stream<S> transform<S>(StreamTransformer<List<int>, S> streamTransformer) {
|
||||||
// In the test context, only one `PublishPluginCommand` object is created for a single test case.
|
|
||||||
// However, sometimes, we need to run multiple commands in a single test case.
|
|
||||||
// In such situation, this `MockStdin`'s StreamController might be listened to more than once, which is not allowed.
|
|
||||||
//
|
|
||||||
// Create a new controller every time so this Stdin could be listened to multiple times.
|
|
||||||
_controller = StreamController<List<int>>();
|
|
||||||
mockUserInputs.forEach(_addUserInputsToSteam);
|
mockUserInputs.forEach(_addUserInputsToSteam);
|
||||||
return _controller.stream.transform(streamTransformer);
|
return _controller.stream.transform(streamTransformer);
|
||||||
}
|
}
|
||||||
@ -1189,12 +1161,3 @@ class MockStdin extends Mock implements io.Stdin {
|
|||||||
|
|
||||||
void _addUserInputsToSteam(List<int> input) => _controller.add(input);
|
void _addUserInputsToSteam(List<int> input) => _controller.add(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockProcessResult extends Mock implements io.ProcessResult {
|
|
||||||
MockProcessResult({int exitCode = 0}) : _exitCode = exitCode;
|
|
||||||
|
|
||||||
final int _exitCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get exitCode => _exitCode;
|
|
||||||
}
|
|
||||||
|
@ -17,6 +17,8 @@ import 'package:path/path.dart' as p;
|
|||||||
import 'package:platform/platform.dart';
|
import 'package:platform/platform.dart';
|
||||||
import 'package:quiver/collection.dart';
|
import 'package:quiver/collection.dart';
|
||||||
|
|
||||||
|
import 'mocks.dart';
|
||||||
|
|
||||||
/// Returns the exe name that command will use when running Flutter on
|
/// Returns the exe name that command will use when running Flutter on
|
||||||
/// [platform].
|
/// [platform].
|
||||||
String getFlutterCommand(Platform platform) =>
|
String getFlutterCommand(Platform platform) =>
|
||||||
@ -320,7 +322,8 @@ class RecordingProcessRunner extends ProcessRunner {
|
|||||||
Future<io.Process> start(String executable, List<String> args,
|
Future<io.Process> start(String executable, List<String> args,
|
||||||
{Directory? workingDirectory}) async {
|
{Directory? workingDirectory}) async {
|
||||||
recordedCalls.add(ProcessCall(executable, args, workingDirectory?.path));
|
recordedCalls.add(ProcessCall(executable, args, workingDirectory?.path));
|
||||||
return Future<io.Process>.value(_getProcessToReturn(executable));
|
return Future<io.Process>.value(
|
||||||
|
_getProcessToReturn(executable) ?? MockProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
io.Process? _getProcessToReturn(String executable) {
|
io.Process? _getProcessToReturn(String executable) {
|
||||||
|
Reference in New Issue
Block a user