Refactor flutter command exit code - part 2 (#6817)
* convert pubGet to throw ToolExit on non-zero exit code * convert commandValidator to throw ToolExit for non-zero exit code * convert flutter commands to throw ToolExit for non-zero exit code * use convenience method throwToolExit * only show "if this problem persists" for unusual exceptions
This commit is contained in:
@@ -6,6 +6,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/android/android_device.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
@@ -58,19 +59,19 @@ void main() {
|
||||
restoreTargetDeviceFinder();
|
||||
});
|
||||
|
||||
testUsingContext('returns 1 when test file is not found', () {
|
||||
testUsingContext('returns 1 when test file is not found', () async {
|
||||
withMockDevice();
|
||||
List<String> args = <String>[
|
||||
'drive',
|
||||
'--target=/some/app/test/e2e.dart',
|
||||
];
|
||||
return createTestCommandRunner(command).run(args).then((int code) {
|
||||
expect(code, 1);
|
||||
BufferLogger buffer = logger;
|
||||
expect(buffer.errorText, contains(
|
||||
'Test file not found: /some/app/test_driver/e2e_test.dart'
|
||||
));
|
||||
});
|
||||
try {
|
||||
await createTestCommandRunner(command).run(args);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 1);
|
||||
expect(e.message, contains('Test file not found: /some/app/test_driver/e2e_test.dart'));
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('returns 1 when app fails to run', () async {
|
||||
@@ -88,13 +89,13 @@ void main() {
|
||||
'drive',
|
||||
'--target=$testApp',
|
||||
];
|
||||
return createTestCommandRunner(command).run(args).then((int code) {
|
||||
expect(code, 1);
|
||||
BufferLogger buffer = logger;
|
||||
expect(buffer.errorText, contains(
|
||||
'Application failed to start. Will not run test. Quitting.'
|
||||
));
|
||||
});
|
||||
try {
|
||||
await createTestCommandRunner(command).run(args);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode, 1);
|
||||
expect(e.message, contains('Application failed to start (1). Will not run test. Quitting.'));
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('returns 1 when app file is outside package', () async {
|
||||
@@ -106,13 +107,15 @@ void main() {
|
||||
'drive',
|
||||
'--target=$appFile',
|
||||
];
|
||||
return createTestCommandRunner(command).run(args).then((int code) {
|
||||
expect(code, 1);
|
||||
BufferLogger buffer = logger;
|
||||
expect(buffer.errorText, contains(
|
||||
'Application file $appFile is outside the package directory $packageDir'
|
||||
try {
|
||||
await createTestCommandRunner(command).run(args);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 1);
|
||||
expect(testLogger.errorText, contains(
|
||||
'Application file $appFile is outside the package directory $packageDir',
|
||||
));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('returns 1 when app file is in the root dir', () async {
|
||||
@@ -124,14 +127,16 @@ void main() {
|
||||
'drive',
|
||||
'--target=$appFile',
|
||||
];
|
||||
return createTestCommandRunner(command).run(args).then((int code) {
|
||||
expect(code, 1);
|
||||
BufferLogger buffer = logger;
|
||||
expect(buffer.errorText, contains(
|
||||
try {
|
||||
await createTestCommandRunner(command).run(args);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 1);
|
||||
expect(testLogger.errorText, contains(
|
||||
'Application file main.dart must reside in one of the '
|
||||
'sub-directories of the package structure, not in the root directory.'
|
||||
'sub-directories of the package structure, not in the root directory.',
|
||||
));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('returns 0 when test ends successfully', () async {
|
||||
@@ -175,9 +180,9 @@ void main() {
|
||||
appStarter = expectAsync((_) {
|
||||
return new Future<int>.value(0);
|
||||
});
|
||||
testRunner = expectAsync((_) {
|
||||
return new Future<int>.value(123);
|
||||
});
|
||||
testRunner = (_) {
|
||||
throwToolExit(null, exitCode: 123);
|
||||
};
|
||||
appStopper = expectAsync((_) {
|
||||
return new Future<int>.value(0);
|
||||
});
|
||||
@@ -190,14 +195,15 @@ void main() {
|
||||
'drive',
|
||||
'--target=$testApp',
|
||||
];
|
||||
return createTestCommandRunner(command).run(args).then((int code) {
|
||||
expect(code, 123);
|
||||
BufferLogger buffer = logger;
|
||||
expect(buffer.errorText, isEmpty);
|
||||
});
|
||||
try {
|
||||
await createTestCommandRunner(command).run(args);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 123);
|
||||
expect(e.message, isNull);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
group('findTargetDevice', () {
|
||||
testUsingContext('uses specified device', () async {
|
||||
testDeviceManager.specifiedDeviceId = '123';
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/commands/logs.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -11,12 +12,15 @@ import 'src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('logs', () {
|
||||
testUsingContext('fail with a bad device id', () {
|
||||
testUsingContext('fail with a bad device id', () async {
|
||||
LogsCommand command = new LogsCommand();
|
||||
applyMocksToCommand(command);
|
||||
return createTestCommandRunner(command).run(<String>['-d', 'abc123', 'logs']).then((int code) {
|
||||
expect(code, 1);
|
||||
});
|
||||
try {
|
||||
await createTestCommandRunner(command).run(<String>['-d', 'abc123', 'logs']);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/commands/run.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -11,12 +12,15 @@ import 'src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('run', () {
|
||||
testUsingContext('fails when target not found', () {
|
||||
testUsingContext('fails when target not found', () async {
|
||||
RunCommand command = new RunCommand();
|
||||
applyMocksToCommand(command);
|
||||
return createTestCommandRunner(command).run(<String>['run', '-t', 'abc123']).then((int code) {
|
||||
expect(code, 1);
|
||||
});
|
||||
try {
|
||||
await createTestCommandRunner(command).run(<String>['run', '-t', 'abc123']);
|
||||
fail('Expect exception');
|
||||
} on ToolExit catch (e) {
|
||||
expect(e.exitCode ?? 1, 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user