mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Convert SkiaException
to TestFailure
on post-submit. (#162623)
Fixes https://github.com/flutter/flutter/issues/162621. I believe this has no other implications, other than it's possible to catch `TestFailure` where it should be catchable today.
This commit is contained in:
parent
d0685bf086
commit
bcb305c2ee
@ -320,7 +320,17 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
|
|||||||
golden = _addPrefix(golden);
|
golden = _addPrefix(golden);
|
||||||
await update(golden, imageBytes);
|
await update(golden, imageBytes);
|
||||||
final File goldenFile = getGoldenFile(golden);
|
final File goldenFile = getGoldenFile(golden);
|
||||||
return skiaClient.imgtestAdd(golden.path, goldenFile);
|
try {
|
||||||
|
return await skiaClient.imgtestAdd(golden.path, goldenFile);
|
||||||
|
} on SkiaException catch (e) {
|
||||||
|
// Convert SkiaException -> TestFailure so that this class implements the
|
||||||
|
// contract of GoldenFileComparator, and matchesGoldenFile() converts the
|
||||||
|
// TestFailure into a standard reported test error (with a better stack
|
||||||
|
// trace, for example).
|
||||||
|
//
|
||||||
|
// https://github.com/flutter/flutter/issues/162621
|
||||||
|
throw TestFailure('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decides based on the current environment if goldens tests should be
|
/// Decides based on the current environment if goldens tests should be
|
||||||
|
@ -853,6 +853,43 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(fakeSkiaClient.initCalls, 0);
|
expect(fakeSkiaClient.initCalls, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reports a failure as a TestFailure', () async {
|
||||||
|
final List<String> log = <String>[];
|
||||||
|
final MemoryFileSystem fs = MemoryFileSystem();
|
||||||
|
final FakePlatform platform = FakePlatform(
|
||||||
|
environment: <String, String>{'FLUTTER_ROOT': _kFlutterRoot},
|
||||||
|
operatingSystem: 'macos',
|
||||||
|
);
|
||||||
|
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
||||||
|
final Directory basedir = fs.directory('flutter/test/library/')
|
||||||
|
..createSync(recursive: true);
|
||||||
|
final FlutterGoldenFileComparator comparator = FlutterPostSubmitFileComparator(
|
||||||
|
basedir.uri,
|
||||||
|
ThrowsOnImgTestAddSkiaClient(
|
||||||
|
message: 'Skia Gold received an unapproved image in post-submit',
|
||||||
|
),
|
||||||
|
fs: fs,
|
||||||
|
platform: platform,
|
||||||
|
log: log.add,
|
||||||
|
);
|
||||||
|
await expectLater(
|
||||||
|
() async {
|
||||||
|
return comparator.compare(
|
||||||
|
Uint8List.fromList(_kTestPngBytes),
|
||||||
|
Uri.parse('flutter.golden_test.1.png'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
throwsA(
|
||||||
|
isA<TestFailure>().having(
|
||||||
|
(TestFailure error) => error.toString(),
|
||||||
|
'description',
|
||||||
|
contains('Skia Gold received an unapproved image in post-submit'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(log, isEmpty);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Pre-Submit', () {
|
group('Pre-Submit', () {
|
||||||
@ -1210,6 +1247,21 @@ class FakeSkiaGoldClient extends Fake implements SkiaGoldClient {
|
|||||||
String cleanTestName(String fileName) => cleanTestNameValues[fileName] ?? '';
|
String cleanTestName(String fileName) => cleanTestNameValues[fileName] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ThrowsOnImgTestAddSkiaClient extends Fake implements SkiaGoldClient {
|
||||||
|
ThrowsOnImgTestAddSkiaClient({required this.message});
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> imgtestInit() async {
|
||||||
|
// Assume this function works.
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> imgtestAdd(String testName, File goldenFile) {
|
||||||
|
throw SkiaException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class FakeLocalFileComparator extends Fake implements LocalFileComparator {
|
class FakeLocalFileComparator extends Fake implements LocalFileComparator {
|
||||||
@override
|
@override
|
||||||
late Uri basedir;
|
late Uri basedir;
|
||||||
|
Loading…
Reference in New Issue
Block a user