[flutter_tools] migrate flutter_goldens, flutter_goldens client to null-safety (#64201)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.10
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
@@ -61,15 +62,15 @@ class LocalFileComparator extends GoldenFileComparator with LocalComparisonOutpu
|
||||
/// directory in which [testFile] resides.
|
||||
///
|
||||
/// The [testFile] URL must represent a file.
|
||||
LocalFileComparator(Uri testFile, {path.Style pathStyle})
|
||||
LocalFileComparator(Uri testFile, {path.Style? pathStyle})
|
||||
: basedir = _getBasedir(testFile, pathStyle),
|
||||
_path = _getPath(pathStyle);
|
||||
|
||||
static path.Context _getPath(path.Style style) {
|
||||
static path.Context _getPath(path.Style? style) {
|
||||
return path.Context(style: style ?? path.Style.platform);
|
||||
}
|
||||
|
||||
static Uri _getBasedir(Uri testFile, path.Style pathStyle) {
|
||||
static Uri _getBasedir(Uri testFile, path.Style? pathStyle) {
|
||||
final path.Context context = _getPath(pathStyle);
|
||||
final String testFilePath = context.fromUri(testFile);
|
||||
final String testDirectoryPath = context.dirname(testFilePath);
|
||||
@@ -135,7 +136,7 @@ class LocalComparisonOutput {
|
||||
if (result.diffs != null) {
|
||||
additionalFeedback = '\nFailure feedback can be found at '
|
||||
'${path.join(basedir.path, 'failures')}';
|
||||
final Map<String, Image> diffs = result.diffs.cast<String, Image>();
|
||||
final Map<String, Image> diffs = result.diffs!.cast<String, Image>();
|
||||
for (final MapEntry<String, Image> entry in diffs.entries) {
|
||||
final File output = getFailureFile(
|
||||
key.isEmpty ? entry.key : entry.key + '_' + key,
|
||||
@@ -143,9 +144,9 @@ class LocalComparisonOutput {
|
||||
basedir,
|
||||
);
|
||||
output.parent.createSync(recursive: true);
|
||||
final ByteData pngBytes =
|
||||
final ByteData? pngBytes =
|
||||
await entry.value.toByteData(format: ImageByteFormat.png);
|
||||
output.writeAsBytesSync(pngBytes.buffer.asUint8List());
|
||||
output.writeAsBytesSync(pngBytes!.buffer.asUint8List());
|
||||
}
|
||||
}
|
||||
throw test_package.TestFailure(
|
||||
@@ -169,7 +170,7 @@ class LocalComparisonOutput {
|
||||
|
||||
/// Returns a [ComparisonResult] to describe the pixel differential of the
|
||||
/// [test] and [master] image bytes provided.
|
||||
Future<ComparisonResult> compareLists(List<int> test, List<int> master) async {
|
||||
Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async {
|
||||
if (identical(test, master))
|
||||
return ComparisonResult(passed: true);
|
||||
|
||||
@@ -183,15 +184,12 @@ Future<ComparisonResult> compareLists(List<int> test, List<int> master) async {
|
||||
final Codec testImageCodec =
|
||||
await instantiateImageCodec(Uint8List.fromList(test));
|
||||
final Image testImage = (await testImageCodec.getNextFrame()).image;
|
||||
final ByteData testImageRgba = await testImage.toByteData();
|
||||
final ByteData? testImageRgba = await testImage.toByteData();
|
||||
|
||||
final Codec masterImageCodec =
|
||||
await instantiateImageCodec(Uint8List.fromList(master));
|
||||
final Image masterImage = (await masterImageCodec.getNextFrame()).image;
|
||||
final ByteData masterImageRgba = await masterImage.toByteData();
|
||||
|
||||
assert(testImage != null);
|
||||
assert(masterImage != null);
|
||||
final ByteData? masterImageRgba = await masterImage.toByteData();
|
||||
|
||||
final int width = testImage.width;
|
||||
final int height = testImage.height;
|
||||
@@ -207,10 +205,10 @@ Future<ComparisonResult> compareLists(List<int> test, List<int> master) async {
|
||||
|
||||
int pixelDiffCount = 0;
|
||||
final int totalPixels = width * height;
|
||||
final ByteData invertedMasterRgba = _invert(masterImageRgba);
|
||||
final ByteData invertedTestRgba = _invert(testImageRgba);
|
||||
final ByteData invertedMasterRgba = _invert(masterImageRgba!);
|
||||
final ByteData invertedTestRgba = _invert(testImageRgba!);
|
||||
|
||||
final Uint8List testImageBytes = (await testImage.toByteData()).buffer.asUint8List();
|
||||
final Uint8List testImageBytes = (await testImage.toByteData())!.buffer.asUint8List();
|
||||
final ByteData maskedDiffRgba = ByteData(testImageBytes.length);
|
||||
maskedDiffRgba.buffer.asUint8List().setRange(0, testImageBytes.length, testImageBytes);
|
||||
final ByteData isolatedDiffRgba = ByteData(width * height * 4);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.10
|
||||
import 'dart:convert';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:typed_data';
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.10
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '_goldens_io.dart' if (dart.library.html) '_goldens_web.dart' as _goldens;
|
||||
|
||||
@@ -82,7 +82,7 @@ abstract class GoldenFileComparator {
|
||||
///
|
||||
/// Version numbers are used in golden file tests for package:flutter. You can
|
||||
/// learn more about these tests [here](https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter).
|
||||
Uri getTestUri(Uri key, int version) {
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
if (version == null)
|
||||
return key;
|
||||
final String keyString = key.toString();
|
||||
@@ -130,7 +130,6 @@ abstract class GoldenFileComparator {
|
||||
GoldenFileComparator get goldenFileComparator => _goldenFileComparator;
|
||||
GoldenFileComparator _goldenFileComparator = const TrivialComparator._();
|
||||
set goldenFileComparator(GoldenFileComparator value) {
|
||||
assert(value != null);
|
||||
_goldenFileComparator = value;
|
||||
}
|
||||
|
||||
@@ -194,7 +193,7 @@ abstract class WebGoldenComparator {
|
||||
///
|
||||
/// Version numbers are used in golden file tests for package:flutter. You can
|
||||
/// learn more about these tests [here](https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter).
|
||||
Uri getTestUri(Uri key, int version) {
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
if (version == null)
|
||||
return key;
|
||||
final String keyString = key.toString();
|
||||
@@ -239,7 +238,6 @@ abstract class WebGoldenComparator {
|
||||
WebGoldenComparator get webGoldenComparator => _webGoldenComparator;
|
||||
WebGoldenComparator _webGoldenComparator = const _TrivialWebGoldenComparator._();
|
||||
set webGoldenComparator(WebGoldenComparator value) {
|
||||
assert(value != null);
|
||||
_webGoldenComparator = value;
|
||||
}
|
||||
|
||||
@@ -289,7 +287,7 @@ class TrivialComparator implements GoldenFileComparator {
|
||||
}
|
||||
|
||||
@override
|
||||
Uri getTestUri(Uri key, int version) {
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -309,7 +307,7 @@ class _TrivialWebGoldenComparator implements WebGoldenComparator {
|
||||
}
|
||||
|
||||
@override
|
||||
Uri getTestUri(Uri key, int version) {
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -322,10 +320,10 @@ class _TrivialWebGoldenComparator implements WebGoldenComparator {
|
||||
class ComparisonResult {
|
||||
/// Creates a new [ComparisonResult] for the current test.
|
||||
ComparisonResult({
|
||||
@required this.passed,
|
||||
required this.passed,
|
||||
this.error,
|
||||
this.diffs,
|
||||
}) : assert(passed != null);
|
||||
});
|
||||
|
||||
/// Indicates whether or not a pixel comparison test has failed.
|
||||
///
|
||||
@@ -333,10 +331,10 @@ class ComparisonResult {
|
||||
final bool passed;
|
||||
|
||||
/// Error message used to describe the cause of the pixel comparison failure.
|
||||
final String error;
|
||||
final String? error;
|
||||
|
||||
/// Map containing differential images to illustrate found variants in pixel
|
||||
/// values in the execution of the pixel test.
|
||||
// TODO(jonahwilliams): fix type signature when image is updated to support web.
|
||||
final Map<String, Object> diffs;
|
||||
final Map<String, Object>? diffs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user