diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index e387d0b81f..eff723fa28 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -853,21 +853,26 @@ void main() { ) ); +// await expectLater( +// find.byType(CupertinoDatePicker), +// matchesGoldenFile('date_picker_test.datetime.initial.png'), +// skip: !Platform.isLinux +// ); + await expectLater( find.byType(CupertinoDatePicker), - matchesGoldenFile('date_picker_test.datetime.initial.png'), - skip: !Platform.isLinux + matchesSkiaGoldFile('date_picker_test.datetime.initial.png'), ); // Slightly drag the hour component to make the current hour off-center. await tester.drag(find.text('4'), Offset(0, _kRowOffset.dy / 2)); await tester.pump(); - await expectLater( - find.byType(CupertinoDatePicker), - matchesGoldenFile('date_picker_test.datetime.drag.png'), - skip: !Platform.isLinux - ); +// await expectLater( +// find.byType(CupertinoDatePicker), +// matchesGoldenFile('date_picker_test.datetime.drag.png'), +// skip: !Platform.isLinux +// ); }); } diff --git a/packages/flutter_goldens/lib/flutter_goldens.dart b/packages/flutter_goldens/lib/flutter_goldens.dart index e02630b9c0..5ee18ead54 100644 --- a/packages/flutter_goldens/lib/flutter_goldens.dart +++ b/packages/flutter_goldens/lib/flutter_goldens.dart @@ -9,6 +9,7 @@ import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meta/meta.dart'; +import 'package:test_api/test_api.dart' as test_package show TestFailure; import 'package:flutter_goldens_client/client.dart'; export 'package:flutter_goldens_client/client.dart'; @@ -77,12 +78,12 @@ class FlutterGoldenFileComparator implements GoldenFileComparator { @override Future compare(Uint8List imageBytes, Uri golden) async { + final bool authorized = await _skiaClient.auth(fs.directory(basedir)); final File goldenFile = _getGoldenFile(golden); - bool authorized = await _skiaClient.auth(fs.directory(basedir)); - bool tested = await _skiaClient.imgtest(golden.path, goldenFile); - return true; // TEMP - //TODO(katelovett): Process results + if (!authorized) + throw test_package.TestFailure('Could not authorize golctl.'); + return await _skiaClient.imgtest(golden.path, goldenFile); } @override diff --git a/packages/flutter_goldens_client/lib/client.dart b/packages/flutter_goldens_client/lib/client.dart index 4ff5ddfebf..29e724d21e 100644 --- a/packages/flutter_goldens_client/lib/client.dart +++ b/packages/flutter_goldens_client/lib/client.dart @@ -20,24 +20,62 @@ const String _kGoldctlKey = 'GOLDCTL'; const String _kServiceAccountKey = 'GOLD_SERVICE_ACCOUNT'; const String _kSkiaGoldInstance = 'SKIA_GOLD_INSTANCE'; +/// A class that represents the Skia Gold client for golden file testing. class SkiaGoldClient { + /// Create a handle to a local workspace for the Skia Gold Client. SkiaGoldClient({ this.fs = const LocalFileSystem(), this.platform = const LocalPlatform(), this.process = const LocalProcessManager(), }); + /// The file system to use for storing local files for running imgtests. + /// + /// This is usefule in tests, where a local file system (the default) can be + /// replaced by a memory file system. final FileSystem fs; + + /// A wrapper for the [dart:io.Platform] API. + /// + /// This is useful in tests, where the system platform (the default) can be + /// replaced by a mock platform instance. final Platform platform; + + /// A controller for launching subprocesses. + /// + /// This is useful in tests, where the real process manager (the default) can + /// be replaced by a mock process manager that doesn't really create + /// subprocesses. final ProcessManager process; + Directory _workDirectory; - //TODO(katelovett): Environment variables swapped out for final CI implementation + //TODO(katelovett): Environment variables swapped out for CI implementation + /// The [path] to the local [Directory] where the goldctl tool is hosted. + /// + /// Uses the [platform] [environment] in this iteration. String get _goldctl => platform.environment[_kGoldctlKey]; + + /// The [path] to the local [Directory] where the service account key is + /// hosted. + /// + /// Uses the [platform] [environment] in this iteration. String get _serviceAccount => platform.environment[_kServiceAccountKey]; + + /// The name of the Skia Gold Flutter instance. + /// + /// Uses the [platform] [environment] in this iteration. String get _skiaGoldInstance => platform.environment[_kSkiaGoldInstance]; + + /// The local [Directory] where the Flutter repository is hosted. + /// + /// Uses the [fs] file system. Directory get _flutterRoot => fs.directory(platform.environment[_kFlutterRootKey]); + /// Prepares the local work space for golden file testing and initializes the + /// goldctl authorization for executing tests. + /// + /// This ensures that the goldctl tool is authorized and ready for testing. Future auth(Directory workDirectory) async { _workDirectory = workDirectory; List authArguments = ['auth']; @@ -61,6 +99,7 @@ class SkiaGoldClient { return true; } + Future imgtest(String testName, File goldenFile) async { List imgtestArguments = [ 'imgtest', @@ -145,165 +184,4 @@ class NonZeroExitCode implements Exception { String toString() { return 'Exit code $exitCode: $stderr'; } -} - -// -///// A class that represents a clone of the https://github.com/flutter/goldens -///// repository, nested within the `bin/cache` directory of the caller's Flutter -///// repository. -//class GoldensClient { -// /// Create a handle to a local clone of the goldens repository. -// GoldensClient({ -// this.fs = const LocalFileSystem(), -// this.platform = const LocalPlatform(), -// this.process = const LocalProcessManager(), -// }); -// -// /// The file system to use for storing the local clone of the repository. -// /// -// /// This is useful in tests, where a local file system (the default) can -// /// be replaced by a memory file system. -// final FileSystem fs; -// -// /// A wrapper for the [dart:io.Platform] API. -// /// -// /// This is useful in tests, where the system platform (the default) can -// /// be replaced by a mock platform instance. -// final Platform platform; -// -// /// A controller for launching subprocesses. -// /// -// /// This is useful in tests, where the real process manager (the default) -// /// can be replaced by a mock process manager that doesn't really create -// /// subprocesses. -// final ProcessManager process; -// -// RandomAccessFile _lock; -// -// /// The local [Directory] where the Flutter repository is hosted. -// /// -// /// Uses the [fs] file system. -// Directory get flutterRoot => fs.directory(platform.environment[_kFlutterRootKey]); -// -// /// The local [Directory] where the goldens repository is hosted. -// /// -// /// Uses the [fs] file system. -// Directory get repositoryRoot => flutterRoot.childDirectory(fs.path.join('bin', 'cache', 'pkg', 'goldens')); -// -// /// Prepares the local clone of the `flutter/goldens` repository for golden -// /// file testing. -// /// -// /// This ensures that the goldens repository has been cloned into its -// /// expected location within `bin/cache` and that it is synced to the Git -// /// revision specified in `bin/internal/goldens.version`. -// /// -// /// While this is preparing the repository, it obtains a file lock such that -// /// [GoldensClient] instances in other processes or isolates will not -// /// duplicate the work that this is doing. -// Future prepare() async { -// print('GoldensClient.prepare'); -// final String goldensCommit = await _getGoldensCommit(); -// String currentCommit = await _getCurrentCommit(); -// if (currentCommit != goldensCommit) { -// await _obtainLock(); -// try { -// // Check the current commit again now that we have the lock. -// currentCommit = await _getCurrentCommit(); -// if (currentCommit != goldensCommit) { -// if (currentCommit == null) { -// await _initRepository(); -// } -// await _checkCanSync(); -// await _syncTo(goldensCommit); -// } -// } finally { -// await _releaseLock(); -// } -// } -// } -// -// Future _getGoldensCommit() async { -// final File versionFile = flutterRoot.childFile(fs.path.join('bin', 'internal', 'goldens.version')); -// return (await versionFile.readAsString()).trim(); -// } -// -// Future _getCurrentCommit() async { -// if (!repositoryRoot.existsSync()) { -// return null; -// } else { -// final io.ProcessResult revParse = await process.run( -// ['git', 'rev-parse', 'HEAD'], -// workingDirectory: repositoryRoot.path, -// ); -// return revParse.exitCode == 0 ? revParse.stdout.trim() : null; -// } -// } -// -// Future _initRepository() async { -// await repositoryRoot.create(recursive: true); -// await _runCommands( -// [ -// 'git init', -// 'git remote add upstream https://github.com/flutter/goldens.git', -// 'git remote set-url --push upstream git@github.com:flutter/goldens.git', -// ], -// workingDirectory: repositoryRoot, -// ); -// } -// -// Future _checkCanSync() async { -// final io.ProcessResult result = await process.run( -// ['git', 'status', '--porcelain'], -// workingDirectory: repositoryRoot.path, -// ); -// if (result.stdout.trim().isNotEmpty) { -// final StringBuffer buf = StringBuffer(); -// buf -// ..writeln('flutter_goldens git checkout at ${repositoryRoot.path} has local changes and cannot be synced.') -// ..writeln('To reset your client to a clean state, and lose any local golden test changes:') -// ..writeln('cd ${repositoryRoot.path}') -// ..writeln('git reset --hard HEAD') -// ..writeln('git clean -x -d -f -f'); -// throw NonZeroExitCode(1, buf.toString()); -// } -// } -// -// Future _syncTo(String commit) async { -// await _runCommands( -// [ -// 'git pull upstream master', -// 'git fetch upstream $commit', -// 'git reset --hard FETCH_HEAD', -// ], -// workingDirectory: repositoryRoot, -// ); -// } -// -// Future _runCommands( -// List commands, { -// Directory workingDirectory, -// }) async { -// for (String command in commands) { -// final List parts = command.split(' '); -// final io.ProcessResult result = await process.run( -// parts, -// workingDirectory: workingDirectory?.path, -// ); -// if (result.exitCode != 0) { -// throw NonZeroExitCode(result.exitCode, result.stderr); -// } -// } -// } -// -// Future _obtainLock() async { -// final File lockFile = flutterRoot.childFile(fs.path.join('bin', 'cache', 'goldens.lockfile')); -// await lockFile.create(recursive: true); -// _lock = await lockFile.open(mode: io.FileMode.write); -// await _lock.lock(io.FileLock.blockingExclusive); -// } -// -// Future _releaseLock() async { -// await _lock.close(); -// _lock = null; -// } -//} \ No newline at end of file +} \ No newline at end of file