give throwsToolExit a more useful description (#136694)

Fixes https://github.com/flutter/flutter/issues/136698.

Alters how `throwToolExit` creates its matcher. This results is an improved description of the matcher.

The mismatch description isn't improved by this, but I writing an entirely custom matcher to fix this isn't ideal either. We can instead mitigate the issue by augmenting the `toString` implementation of `ToolExit` to include the exit code, if it is non-null.

With these changes, the first few lines of output from a test would look like this:

```
Expected: throws <Instance of 'ToolExit'> with `exitCode`: <42> and `message`: contains 'message'
  Actual: <Closure: () => Never>
   Which: threw ToolExit:<Exit code: 41232. Error: message>
```
This commit is contained in:
Andrew Kolos
2023-10-26 23:18:17 -07:00
committed by GitHub
parent 37da62a6eb
commit 1328997b08
4 changed files with 11 additions and 10 deletions

View File

@@ -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';
}