mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
159 lines
3.5 KiB
Dart
159 lines
3.5 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// See also packages/flutter_goldens/test/flutter_goldens_test.dart
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:file/file.dart';
|
|
import 'package:file/memory.dart';
|
|
import 'package:flutter_goldens/flutter_goldens.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:platform/platform.dart';
|
|
|
|
// 1x1 colored pixel
|
|
const List<int> _kFailPngBytes = <int>[
|
|
137,
|
|
80,
|
|
78,
|
|
71,
|
|
13,
|
|
10,
|
|
26,
|
|
10,
|
|
0,
|
|
0,
|
|
0,
|
|
13,
|
|
73,
|
|
72,
|
|
68,
|
|
82,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
8,
|
|
6,
|
|
0,
|
|
0,
|
|
0,
|
|
31,
|
|
21,
|
|
196,
|
|
137,
|
|
0,
|
|
0,
|
|
0,
|
|
13,
|
|
73,
|
|
68,
|
|
65,
|
|
84,
|
|
120,
|
|
1,
|
|
99,
|
|
249,
|
|
207,
|
|
240,
|
|
255,
|
|
63,
|
|
0,
|
|
7,
|
|
18,
|
|
3,
|
|
2,
|
|
164,
|
|
147,
|
|
160,
|
|
197,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
73,
|
|
69,
|
|
78,
|
|
68,
|
|
174,
|
|
66,
|
|
96,
|
|
130,
|
|
];
|
|
|
|
void main() {
|
|
final List<String> log = <String>[];
|
|
final MemoryFileSystem fs = MemoryFileSystem();
|
|
final Directory basedir = fs.directory('flutter/test/library/')..createSync(recursive: true);
|
|
final FakeSkiaGoldClient fakeSkiaClient =
|
|
FakeSkiaGoldClient()..expectationForTestValues['flutter.new_golden_test.1'] = '';
|
|
final FlutterLocalFileComparator comparator = FlutterLocalFileComparator(
|
|
basedir.uri,
|
|
fakeSkiaClient,
|
|
fs: fs,
|
|
platform: FakePlatform(
|
|
environment: <String, String>{'FLUTTER_ROOT': '/flutter'},
|
|
operatingSystem: 'macos',
|
|
),
|
|
log: log.add,
|
|
);
|
|
|
|
test('Local passes non-existent baseline for new test, null expectation', () async {
|
|
log.clear();
|
|
expect(
|
|
await comparator.compare(
|
|
Uint8List.fromList(_kFailPngBytes),
|
|
Uri.parse('flutter.new_golden_test.1.png'),
|
|
),
|
|
isTrue,
|
|
);
|
|
const String expectation =
|
|
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.1.png. '
|
|
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
|
|
'Validate image output found at flutter/test/library/';
|
|
expect(log, const <String>[expectation]);
|
|
});
|
|
|
|
test('Local passes non-existent baseline for new test, empty expectation', () async {
|
|
log.clear();
|
|
expect(
|
|
await comparator.compare(
|
|
Uint8List.fromList(_kFailPngBytes),
|
|
Uri.parse('flutter.new_golden_test.2.png'),
|
|
),
|
|
isTrue,
|
|
);
|
|
const String expectation =
|
|
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.2.png. '
|
|
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
|
|
'Validate image output found at flutter/test/library/';
|
|
expect(log, const <String>[expectation]);
|
|
});
|
|
}
|
|
|
|
// See also packages/flutter_goldens/test/flutter_goldens_test.dart
|
|
class FakeSkiaGoldClient extends Fake implements SkiaGoldClient {
|
|
Map<String, String> expectationForTestValues = <String, String>{};
|
|
Object? getExpectationForTestThrowable;
|
|
@override
|
|
Future<String> getExpectationForTest(String testName) async {
|
|
if (getExpectationForTestThrowable != null) {
|
|
throw getExpectationForTestThrowable!;
|
|
}
|
|
return expectationForTestValues[testName] ?? '';
|
|
}
|
|
|
|
Map<String, List<int>> imageBytesValues = <String, List<int>>{};
|
|
@override
|
|
Future<List<int>> getImageBytes(String imageHash) async => imageBytesValues[imageHash]!;
|
|
|
|
Map<String, String> cleanTestNameValues = <String, String>{};
|
|
@override
|
|
String cleanTestName(String fileName) => cleanTestNameValues[fileName] ?? '';
|
|
}
|