Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bab1944

Browse files
committed
moved to tools
1 parent 0ae618e commit bab1944

File tree

5 files changed

+55
-32
lines changed

5 files changed

+55
-32
lines changed

tools/compare_goldens/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compare Goldens
2+
3+
This is a script that will let you check golden image diffs locally.
4+
5+
The directories are scanned for png files that match in name, then the diff
6+
is written to `diff_<name of file>` in the CWD. This allows you to get
7+
results quicker than having to upload to skia gold. By default it uses fuzzy
8+
RMSE to compare.
9+
10+
## Usage
11+
12+
```sh
13+
dart run compare_goldens <dir path> <dir path>
14+
```
15+
16+
Here's the steps for using this with something like impeller golden tests:
17+
18+
1) Checkout a base revision
19+
2) Build impeller_golden_tests
20+
3) Execute `impeller_golden_tests --working_dir=\<path a\>
21+
4) Checkout test revision
22+
5) Build impeller_golden_tests
23+
6) Execute `impeller_golden_tests --working_dir=\<path b\>
24+
7) Execute `compare_goldens \<path a\> \<path b\>
25+
26+
## Requirements
27+
28+
- ImageMagick is installed on $PATH
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:compare_goldens/compare_goldens.dart' as compare_goldens;
6+
7+
void main(List<String> args) {
8+
compare_goldens.run(args);
9+
}

testing/compare_goldens.dart renamed to tools/compare_goldens/lib/compare_goldens.dart

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// #############################################################################
6-
// This is a script that will let you check golden image diffs locally.
7-
//
8-
// Usage: compare_goldens.dart <dir path> <dir path>
9-
//
10-
// The directories are scanned for png files that match in name, then the diff
11-
// is written to `diff_<name of file>` in the CWD. This allows you to get
12-
// results quicker than having to upload to skia gold. By default it uses fuzzy
13-
// RMSE to compare.
14-
//
15-
// Here's the steps for using this with something like impeller golden tests:
16-
// 1) Checkout a base revision
17-
// 2) Build impeller_golden_tests
18-
// 3) Execute `impeller_golden_tests --working_dir=<path a>
19-
// 4) Checkout test revision
20-
// 5) Build impeller_golden_tests
21-
// 6) Execute `impeller_golden_tests --working_dir=<path b>
22-
// 7) Execute `compare_goldens.dart <path a> <path b>
23-
//
24-
// Requirements: ImageMagick is installed on $PATH
25-
// #############################################################################
26-
275
import 'dart:io';
286

29-
bool hasCommandOnPath(String name) {
7+
bool _hasCommandOnPath(String name) {
308
final ProcessResult result = Process.runSync('which', <String>[name]);
319
return result.exitCode == 0;
3210
}
3311

34-
List<String> findPairs(Set<String> as, Set<String> bs) {
12+
List<String> _findPairs(Set<String> as, Set<String> bs) {
3513
final List<String> result = <String>[];
3614
for (final String a in as) {
3715
if (bs.contains(a)) {
@@ -50,19 +28,19 @@ List<String> findPairs(Set<String> as, Set<String> bs) {
5028
return result;
5129
}
5230

53-
String basename(String path) {
31+
String _basename(String path) {
5432
return path.split(Platform.pathSeparator).last;
5533
}
5634

57-
Set<String> grabPngFilenames(Directory dir) {
35+
Set<String> _grabPngFilenames(Directory dir) {
5836
return dir.listSync()
59-
.map((e) => basename(e.path))
37+
.map((e) => _basename(e.path))
6038
.where((e) => e.endsWith('.png'))
6139
.toSet();
6240
}
6341

64-
void main(List<String> args) {
65-
if (!hasCommandOnPath('compare')) {
42+
void run(List<String> args) {
43+
if (!_hasCommandOnPath('compare')) {
6644
throw Exception(r'Could not find `compare` from ImageMagick on $PATH.');
6745
}
6846
if (args.length != 2) {
@@ -78,9 +56,9 @@ void main(List<String> args) {
7856
throw Exception('Unable to find $dirB');
7957
}
8058

81-
final Set<String> filesA = grabPngFilenames(dirA);
82-
final Set<String> filesB = grabPngFilenames(dirB);
83-
final List<String> pairs = findPairs(filesA, filesB);
59+
final Set<String> filesA = _grabPngFilenames(dirA);
60+
final Set<String> filesB = _grabPngFilenames(dirB);
61+
final List<String> pairs = _findPairs(filesA, filesB);
8462

8563
int count = 0;
8664
for (final String name in pairs) {

tools/compare_goldens/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: compare_goldens
2+
environment:
3+
sdk: '^3.0.0'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
void main() {}

0 commit comments

Comments
 (0)