Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give throwsToolExit a more useful description #136694

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/base/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class ToolExit implements Exception {
final int? exitCode;

@override
String toString() => 'Exception: $message'; // TODO(ianh): Really this should say "Error".
String toString() => 'Error: $message';
}
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ flutter:

await residentRunner.runSourceGenerators();

expect(testLogger.errorText, allOf(contains('Exception')));
expect(testLogger.errorText, contains('Error'));
expect(testLogger.statusText, isEmpty);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void main() {

final String output = _uniqueOutputLines(outputEvents);
expect(output, contains('this code does not compile'));
expect(output, contains('Exception: Failed to build'));
expect(output, contains('Error: Failed to build'));
expect(output, contains('Exited (1)'));
});

Expand Down
15 changes: 8 additions & 7 deletions packages/flutter_tools/test/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,20 @@ Future<StringBuffer> capturedConsolePrint(Future<void> Function() body) async {
final Matcher throwsAssertionError = throwsA(isA<AssertionError>());

/// Matcher for functions that throw [ToolExit].
///
/// [message] is matched using the [contains] matcher.
Matcher throwsToolExit({ int? exitCode, Pattern? message }) {
Matcher matcher = _isToolExit;
TypeMatcher<ToolExit> result = const TypeMatcher<ToolExit>();

if (exitCode != null) {
matcher = allOf(matcher, (ToolExit e) => e.exitCode == exitCode);
result = result.having((ToolExit e) => e.exitCode, 'exitCode', equals(exitCode));
}
if (message != null) {
matcher = allOf(matcher, (ToolExit e) => e.message?.contains(message) ?? false);
result = result.having((ToolExit e) => e.message, 'message', contains(message));
}
return throwsA(matcher);
}

/// Matcher for [ToolExit]s.
final TypeMatcher<ToolExit> _isToolExit = isA<ToolExit>();
return throwsA(result);
}

/// Matcher for functions that throw [UsageException].
Matcher throwsUsageException({Pattern? message }) {
Expand Down