2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2017-02-27 23:38:47 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-09-11 15:30:29 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-01-06 19:04:20 +00:00
|
|
|
import 'package:platform/platform.dart';
|
2018-10-09 02:11:31 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2020-01-08 23:20:32 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2017-02-27 23:38:47 +00:00
|
|
|
import 'package:flutter_tools/src/base/process.dart';
|
2018-10-30 23:00:50 +00:00
|
|
|
import 'package:flutter_tools/src/base/terminal.dart';
|
2018-10-09 02:11:31 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import 'package:process/process.dart';
|
2017-02-27 23:38:47 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/common.dart';
|
|
|
|
import '../../src/context.dart';
|
2019-08-28 17:03:53 +00:00
|
|
|
import '../../src/mocks.dart' show MockProcess,
|
|
|
|
MockProcessManager,
|
2020-01-08 23:20:32 +00:00
|
|
|
MockStdio,
|
2019-08-28 17:03:53 +00:00
|
|
|
flakyProcessFactory;
|
2018-03-07 19:39:59 +00:00
|
|
|
|
2017-02-27 23:38:47 +00:00
|
|
|
void main() {
|
2018-10-09 02:11:31 +00:00
|
|
|
group('process exceptions', () {
|
|
|
|
ProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
2018-10-09 02:11:31 +00:00
|
|
|
|
|
|
|
setUp(() {
|
2018-10-30 23:00:50 +00:00
|
|
|
mockProcessManager = PlainMockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
2020-03-03 00:23:56 +00:00
|
|
|
logger: BufferLogger.test(),
|
2020-01-08 23:20:32 +00:00
|
|
|
);
|
2018-10-09 02:11:31 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext('runAsync throwOnError: exceptions should be ProcessException objects', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['false'])).thenAnswer(
|
|
|
|
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(0, 1, '', '')));
|
|
|
|
expect(() async => await processUtils.run(<String>['false'], throwOnError: true),
|
2020-01-27 22:36:02 +00:00
|
|
|
throwsA(isA<ProcessException>()));
|
2020-01-08 23:20:32 +00:00
|
|
|
});
|
2018-10-09 02:11:31 +00:00
|
|
|
});
|
2019-08-28 17:03:53 +00:00
|
|
|
|
2017-02-27 23:38:47 +00:00
|
|
|
group('shutdownHooks', () {
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext('runInExpectedOrder', () async {
|
2017-02-27 23:38:47 +00:00
|
|
|
int i = 1;
|
|
|
|
int serializeRecording1;
|
|
|
|
int serializeRecording2;
|
|
|
|
int postProcessRecording;
|
|
|
|
int cleanup;
|
|
|
|
|
2020-03-03 00:23:56 +00:00
|
|
|
final ShutdownHooks shutdownHooks = ShutdownHooks(logger: BufferLogger.test());
|
2020-01-08 23:20:32 +00:00
|
|
|
|
|
|
|
shutdownHooks.addShutdownHook(() async {
|
2017-02-27 23:38:47 +00:00
|
|
|
serializeRecording1 = i++;
|
|
|
|
}, ShutdownStage.SERIALIZE_RECORDING);
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
shutdownHooks.addShutdownHook(() async {
|
2017-02-27 23:38:47 +00:00
|
|
|
cleanup = i++;
|
|
|
|
}, ShutdownStage.CLEANUP);
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
shutdownHooks.addShutdownHook(() async {
|
2017-02-27 23:38:47 +00:00
|
|
|
postProcessRecording = i++;
|
|
|
|
}, ShutdownStage.POST_PROCESS_RECORDING);
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
shutdownHooks.addShutdownHook(() async {
|
2017-02-27 23:38:47 +00:00
|
|
|
serializeRecording2 = i++;
|
|
|
|
}, ShutdownStage.SERIALIZE_RECORDING);
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
await shutdownHooks.runShutdownHooks();
|
2017-02-27 23:38:47 +00:00
|
|
|
|
|
|
|
expect(serializeRecording1, lessThanOrEqualTo(2));
|
|
|
|
expect(serializeRecording2, lessThanOrEqualTo(2));
|
|
|
|
expect(postProcessRecording, 3);
|
|
|
|
expect(cleanup, 4);
|
|
|
|
});
|
|
|
|
});
|
2019-08-28 17:03:53 +00:00
|
|
|
|
2018-10-30 23:00:50 +00:00
|
|
|
group('output formatting', () {
|
|
|
|
MockProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
|
|
|
BufferLogger mockLogger;
|
2018-10-30 23:00:50 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockProcessManager = MockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
mockLogger = BufferLogger(
|
|
|
|
terminal: AnsiTerminal(
|
|
|
|
stdio: MockStdio(),
|
|
|
|
platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
|
|
|
|
),
|
|
|
|
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
|
|
|
|
);
|
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
|
|
|
logger: mockLogger,
|
|
|
|
);
|
2018-10-30 23:00:50 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
MockProcess Function(List<String>) processMetaFactory(List<String> stdout, {
|
|
|
|
List<String> stderr = const <String>[],
|
|
|
|
}) {
|
|
|
|
final Stream<List<int>> stdoutStream = Stream<List<int>>.fromIterable(
|
|
|
|
stdout.map<List<int>>((String s) => s.codeUnits,
|
|
|
|
));
|
|
|
|
final Stream<List<int>> stderrStream = Stream<List<int>>.fromIterable(
|
|
|
|
stderr.map<List<int>>((String s) => s.codeUnits,
|
|
|
|
));
|
2018-10-30 23:00:50 +00:00
|
|
|
return (List<String> command) => MockProcess(stdout: stdoutStream, stderr: stderrStream);
|
|
|
|
}
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext('Command output is not wrapped.', () async {
|
2018-10-30 23:00:50 +00:00
|
|
|
final List<String> testString = <String>['0123456789' * 10];
|
|
|
|
mockProcessManager.processFactory = processMetaFactory(testString, stderr: testString);
|
2019-09-12 01:20:42 +00:00
|
|
|
await processUtils.stream(<String>['command']);
|
2020-01-08 23:20:32 +00:00
|
|
|
expect(mockLogger.statusText, equals('${testString[0]}\n'));
|
|
|
|
expect(mockLogger.errorText, equals('${testString[0]}\n'));
|
2018-10-30 23:00:50 +00:00
|
|
|
});
|
|
|
|
});
|
2019-08-28 17:03:53 +00:00
|
|
|
|
2019-09-12 01:20:42 +00:00
|
|
|
group('run', () {
|
2019-08-28 17:03:53 +00:00
|
|
|
const Duration delay = Duration(seconds: 2);
|
|
|
|
MockProcessManager flakyProcessManager;
|
2019-09-12 01:20:42 +00:00
|
|
|
ProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
|
|
|
ProcessUtils flakyProcessUtils;
|
2019-08-28 17:03:53 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
// MockProcessManager has an implementation of start() that returns the
|
|
|
|
// result of processFactory.
|
|
|
|
flakyProcessManager = MockProcessManager();
|
2019-09-12 01:20:42 +00:00
|
|
|
mockProcessManager = MockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
2020-03-03 00:23:56 +00:00
|
|
|
logger: BufferLogger.test(),
|
2020-01-08 23:20:32 +00:00
|
|
|
);
|
|
|
|
flakyProcessUtils = ProcessUtils(
|
|
|
|
processManager: flakyProcessManager,
|
2020-03-03 00:23:56 +00:00
|
|
|
logger: BufferLogger.test(),
|
2020-01-08 23:20:32 +00:00
|
|
|
);
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' succeeds on success', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['whoohoo'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
|
|
|
|
});
|
|
|
|
expect((await processUtils.run(<String>['whoohoo'])).exitCode, 0);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' fails on failure', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['boohoo'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 1, '', ''));
|
|
|
|
});
|
|
|
|
expect((await processUtils.run(<String>['boohoo'])).exitCode, 1);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' throws on failure with throwOnError', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['kaboom'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 1, '', ''));
|
|
|
|
});
|
|
|
|
expect(() => processUtils.run(<String>['kaboom'], throwOnError: true),
|
|
|
|
throwsA(isA<ProcessException>()));
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' does not throw on failure with whitelist', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['kaboom'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 1, '', ''));
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
(await processUtils.run(
|
|
|
|
<String>['kaboom'],
|
|
|
|
throwOnError: true,
|
|
|
|
whiteListFailures: (int c) => c == 1,
|
|
|
|
)).exitCode,
|
2020-01-08 23:20:32 +00:00
|
|
|
1,
|
|
|
|
);
|
2019-09-11 15:30:29 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' throws on failure when not in whitelist', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['kaboom'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 2, '', ''));
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
() => processUtils.run(
|
|
|
|
<String>['kaboom'],
|
|
|
|
throwOnError: true,
|
|
|
|
whiteListFailures: (int c) => c == 1,
|
|
|
|
),
|
2020-01-08 23:20:32 +00:00
|
|
|
throwsA(isA<ProcessException>()),
|
|
|
|
);
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' flaky process fails without retry', () async {
|
2019-09-05 16:50:46 +00:00
|
|
|
flakyProcessManager.processFactory = flakyProcessFactory(
|
|
|
|
flakes: 1,
|
|
|
|
delay: delay,
|
|
|
|
);
|
2020-01-08 23:20:32 +00:00
|
|
|
final RunResult result = await flakyProcessUtils.run(
|
2019-08-28 17:03:53 +00:00
|
|
|
<String>['dummy'],
|
|
|
|
timeout: delay + const Duration(seconds: 1),
|
|
|
|
);
|
|
|
|
expect(result.exitCode, -9);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' flaky process succeeds with retry', () async {
|
2019-09-11 15:30:29 +00:00
|
|
|
flakyProcessManager.processFactory = flakyProcessFactory(
|
|
|
|
flakes: 1,
|
|
|
|
delay: delay,
|
|
|
|
);
|
2020-01-08 23:20:32 +00:00
|
|
|
final RunResult result = await flakyProcessUtils.run(
|
2019-08-28 17:03:53 +00:00
|
|
|
<String>['dummy'],
|
|
|
|
timeout: delay - const Duration(milliseconds: 500),
|
|
|
|
timeoutRetries: 1,
|
|
|
|
);
|
|
|
|
expect(result.exitCode, 0);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' flaky process generates ProcessException on timeout', () async {
|
2019-09-11 15:30:29 +00:00
|
|
|
final Completer<List<int>> flakyStderr = Completer<List<int>>();
|
|
|
|
final Completer<List<int>> flakyStdout = Completer<List<int>>();
|
|
|
|
flakyProcessManager.processFactory = flakyProcessFactory(
|
|
|
|
flakes: 1,
|
|
|
|
delay: delay,
|
|
|
|
stderr: () => Stream<List<int>>.fromFuture(flakyStderr.future),
|
|
|
|
stdout: () => Stream<List<int>>.fromFuture(flakyStdout.future),
|
|
|
|
);
|
|
|
|
when(flakyProcessManager.killPid(any)).thenAnswer((_) {
|
|
|
|
// Don't let the stderr stream stop until the process is killed. This
|
|
|
|
// ensures that runAsync() does not delay killing the process until
|
|
|
|
// stdout and stderr are drained (which won't happen).
|
|
|
|
flakyStderr.complete(<int>[]);
|
|
|
|
flakyStdout.complete(<int>[]);
|
|
|
|
return true;
|
|
|
|
});
|
2020-01-08 23:20:32 +00:00
|
|
|
expect(() => flakyProcessUtils.run(
|
2019-08-28 17:03:53 +00:00
|
|
|
<String>['dummy'],
|
|
|
|
timeout: delay - const Duration(milliseconds: 500),
|
|
|
|
timeoutRetries: 0,
|
2020-01-27 22:36:02 +00:00
|
|
|
), throwsA(isA<ProcessException>()));
|
2019-08-28 17:03:53 +00:00
|
|
|
});
|
|
|
|
});
|
2019-09-12 01:20:42 +00:00
|
|
|
|
|
|
|
group('runSync', () {
|
|
|
|
ProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
|
|
|
BufferLogger testLogger;
|
2019-09-12 01:20:42 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockProcessManager = MockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
testLogger = BufferLogger(
|
|
|
|
terminal: AnsiTerminal(
|
|
|
|
stdio: MockStdio(),
|
|
|
|
platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
|
|
|
|
),
|
|
|
|
outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
|
|
|
|
);
|
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
|
|
|
logger: testLogger,
|
|
|
|
);
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' succeeds on success', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['whoohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 0, '', '')
|
|
|
|
);
|
|
|
|
expect(processUtils.runSync(<String>['whoohoo']).exitCode, 0);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' fails on failure', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['boohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 1, '', '')
|
|
|
|
);
|
|
|
|
expect(processUtils.runSync(<String>['boohoo']).exitCode, 1);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' throws on failure with throwOnError', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['kaboom'])).thenReturn(
|
|
|
|
ProcessResult(0, 1, '', '')
|
|
|
|
);
|
|
|
|
expect(() => processUtils.runSync(<String>['kaboom'], throwOnError: true),
|
|
|
|
throwsA(isA<ProcessException>()));
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' does not throw on failure with whitelist', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['kaboom'])).thenReturn(
|
|
|
|
ProcessResult(0, 1, '', '')
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
processUtils.runSync(
|
|
|
|
<String>['kaboom'],
|
|
|
|
throwOnError: true,
|
|
|
|
whiteListFailures: (int c) => c == 1,
|
|
|
|
).exitCode,
|
|
|
|
1);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' throws on failure when not in whitelist', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['kaboom'])).thenReturn(
|
|
|
|
ProcessResult(0, 2, '', '')
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
() => processUtils.runSync(
|
|
|
|
<String>['kaboom'],
|
|
|
|
throwOnError: true,
|
|
|
|
whiteListFailures: (int c) => c == 1,
|
|
|
|
),
|
|
|
|
throwsA(isA<ProcessException>()));
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' prints stdout and stderr to trace on success', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['whoohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 0, 'stdout', 'stderr')
|
|
|
|
);
|
|
|
|
expect(processUtils.runSync(<String>['whoohoo']).exitCode, 0);
|
|
|
|
expect(testLogger.traceText, contains('stdout'));
|
|
|
|
expect(testLogger.traceText, contains('stderr'));
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' prints stdout to status and stderr to error on failure with throwOnError', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['kaboom'])).thenReturn(
|
|
|
|
ProcessResult(0, 1, 'stdout', 'stderr')
|
|
|
|
);
|
|
|
|
expect(() => processUtils.runSync(<String>['kaboom'], throwOnError: true),
|
|
|
|
throwsA(isA<ProcessException>()));
|
|
|
|
expect(testLogger.statusText, contains('stdout'));
|
|
|
|
expect(testLogger.errorText, contains('stderr'));
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' does not print stdout with hideStdout', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['whoohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 0, 'stdout', 'stderr')
|
|
|
|
);
|
|
|
|
expect(processUtils.runSync(<String>['whoohoo'], hideStdout: true).exitCode, 0);
|
|
|
|
expect(testLogger.traceText.contains('stdout'), isFalse);
|
|
|
|
expect(testLogger.traceText, contains('stderr'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('exitsHappySync', () {
|
|
|
|
ProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
2019-09-12 01:20:42 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockProcessManager = MockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
2020-03-03 00:23:56 +00:00
|
|
|
logger: BufferLogger.test(),
|
2020-01-08 23:20:32 +00:00
|
|
|
);
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' succeeds on success', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['whoohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 0, '', '')
|
|
|
|
);
|
|
|
|
expect(processUtils.exitsHappySync(<String>['whoohoo']), isTrue);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' fails on failure', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.runSync(<String>['boohoo'])).thenReturn(
|
|
|
|
ProcessResult(0, 1, '', '')
|
|
|
|
);
|
|
|
|
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
|
|
|
|
});
|
2020-03-17 19:55:57 +00:00
|
|
|
|
|
|
|
testWithoutContext('catches Exception and returns false', () {
|
|
|
|
when(mockProcessManager.runSync(<String>['boohoo'])).thenThrow(
|
|
|
|
const ProcessException('Process failed', <String>[]),
|
|
|
|
);
|
|
|
|
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('catches ArgumentError and returns false', () {
|
|
|
|
when(mockProcessManager.runSync(<String>['nonesuch'])).thenThrow(
|
|
|
|
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch')
|
|
|
|
);
|
|
|
|
expect(processUtils.exitsHappySync(<String>['nonesuch']), isFalse);
|
|
|
|
});
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
group('exitsHappy', () {
|
|
|
|
ProcessManager mockProcessManager;
|
2020-01-08 23:20:32 +00:00
|
|
|
ProcessUtils processUtils;
|
2019-09-12 01:20:42 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockProcessManager = MockProcessManager();
|
2020-01-08 23:20:32 +00:00
|
|
|
processUtils = ProcessUtils(
|
|
|
|
processManager: mockProcessManager,
|
2020-03-03 00:23:56 +00:00
|
|
|
logger: BufferLogger.test(),
|
2020-01-08 23:20:32 +00:00
|
|
|
);
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' succeeds on success', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['whoohoo'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 0, '', ''));
|
|
|
|
});
|
|
|
|
expect(await processUtils.exitsHappy(<String>['whoohoo']), isTrue);
|
|
|
|
});
|
|
|
|
|
2020-01-08 23:20:32 +00:00
|
|
|
testWithoutContext(' fails on failure', () async {
|
2019-09-12 01:20:42 +00:00
|
|
|
when(mockProcessManager.run(<String>['boohoo'])).thenAnswer((_) {
|
|
|
|
return Future<ProcessResult>.value(ProcessResult(0, 1, '', ''));
|
|
|
|
});
|
|
|
|
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
|
|
|
|
});
|
2020-03-17 19:55:57 +00:00
|
|
|
|
|
|
|
testWithoutContext('catches Exception and returns false', () async {
|
|
|
|
when(mockProcessManager.run(<String>['boohoo'])).thenThrow(
|
|
|
|
const ProcessException('Process failed', <String>[]),
|
|
|
|
);
|
|
|
|
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('catches ArgumentError and returns false', () async {
|
|
|
|
when(mockProcessManager.run(<String>['nonesuch'])).thenThrow(
|
|
|
|
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch'),
|
|
|
|
);
|
|
|
|
expect(await processUtils.exitsHappy(<String>['nonesuch']), isFalse);
|
|
|
|
});
|
2019-09-12 01:20:42 +00:00
|
|
|
});
|
|
|
|
|
2017-02-27 23:38:47 +00:00
|
|
|
}
|
2018-10-09 02:11:31 +00:00
|
|
|
|
2018-12-18 09:05:12 +00:00
|
|
|
class PlainMockProcessManager extends Mock implements ProcessManager {}
|