Auto-format Framework (#160545)
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>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -45,19 +45,12 @@ final class NativeDriverCommandExtension implements CommandExtension {
|
||||
if (await _builtInCall(command.method) case final Result result) {
|
||||
return result;
|
||||
}
|
||||
final Object? result = await _channel.invokeMethod<Object>(
|
||||
command.method,
|
||||
command.arguments,
|
||||
);
|
||||
final Object? result = await _channel.invokeMethod<Object>(command.method, command.arguments);
|
||||
if (result == null) {
|
||||
return const _MethodChannelResult(<String, Object?>{});
|
||||
}
|
||||
if (result is! Map<String, Object?>) {
|
||||
throw ArgumentError.value(
|
||||
result,
|
||||
'result',
|
||||
'Expected a Map<String, Object?>',
|
||||
);
|
||||
throw ArgumentError.value(result, 'result', 'Expected a Map<String, Object?>');
|
||||
}
|
||||
return _MethodChannelResult(result);
|
||||
}
|
||||
@@ -68,14 +61,12 @@ final class NativeDriverCommandExtension implements CommandExtension {
|
||||
Future<Result?> _builtInCall(String method) async {
|
||||
switch (method) {
|
||||
case 'rotate_landscape':
|
||||
await flt.SystemChrome.setPreferredOrientations(
|
||||
const <flt.DeviceOrientation>[flt.DeviceOrientation.landscapeLeft],
|
||||
);
|
||||
await flt.SystemChrome.setPreferredOrientations(const <flt.DeviceOrientation>[
|
||||
flt.DeviceOrientation.landscapeLeft,
|
||||
]);
|
||||
return Result.empty;
|
||||
case 'rotate_default':
|
||||
await flt.SystemChrome.setPreferredOrientations(
|
||||
const <flt.DeviceOrientation>[],
|
||||
);
|
||||
await flt.SystemChrome.setPreferredOrientations(const <flt.DeviceOrientation>[]);
|
||||
return Result.empty;
|
||||
default:
|
||||
return null;
|
||||
@@ -102,11 +93,7 @@ final class NativeDriverCommandExtension implements CommandExtension {
|
||||
} else {
|
||||
final Object? intermediate = json.decode(arguments);
|
||||
if (intermediate is! Map<String, Object?>) {
|
||||
throw ArgumentError.value(
|
||||
arguments,
|
||||
'arguments',
|
||||
'Expected a Map<String, Object?>',
|
||||
);
|
||||
throw ArgumentError.value(arguments, 'arguments', 'Expected a Map<String, Object?>');
|
||||
}
|
||||
decoded = intermediate;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import 'package:test_api/test_api.dart';
|
||||
import 'src/common.dart';
|
||||
|
||||
export 'src/backend/android.dart' show AndroidDeviceTarget, AndroidNativeDriver;
|
||||
export 'src/common.dart'
|
||||
show ByNativeAccessibilityLabel, ByNativeIntegerId, NativeFinder;
|
||||
export 'src/common.dart' show ByNativeAccessibilityLabel, ByNativeIntegerId, NativeFinder;
|
||||
|
||||
part 'src/driver.dart';
|
||||
part 'src/goldens.dart';
|
||||
|
||||
@@ -46,12 +46,8 @@ Future<void> enableSkiaGoldComparator({String? namePrefix}) async {
|
||||
'Set it to use Skia Gold.',
|
||||
);
|
||||
}
|
||||
final io.Directory tmpDir = io.Directory.systemTemp.createTempSync(
|
||||
'android_driver_test',
|
||||
);
|
||||
final bool isPresubmit = io.Platform.environment.containsKey(
|
||||
_kGoldctlPresubmitKey,
|
||||
);
|
||||
final io.Directory tmpDir = io.Directory.systemTemp.createTempSync('android_driver_test');
|
||||
final bool isPresubmit = io.Platform.environment.containsKey(_kGoldctlPresubmitKey);
|
||||
io.stderr.writeln(
|
||||
'=== Using Skia Gold ===\n'
|
||||
'Environment variable $_kGoldctlKey is set, using Skia Gold: \n'
|
||||
@@ -76,12 +72,8 @@ Future<void> enableSkiaGoldComparator({String? namePrefix}) async {
|
||||
}
|
||||
|
||||
final class _GoldenFileComparator extends GoldenFileComparator {
|
||||
_GoldenFileComparator(
|
||||
this.skiaClient, {
|
||||
required this.isPresubmit,
|
||||
this.namePrefix,
|
||||
Uri? baseDir,
|
||||
}) : baseDir = baseDir ?? Uri.parse(path.dirname(io.Platform.script.path));
|
||||
_GoldenFileComparator(this.skiaClient, {required this.isPresubmit, this.namePrefix, Uri? baseDir})
|
||||
: baseDir = baseDir ?? Uri.parse(path.dirname(io.Platform.script.path));
|
||||
|
||||
final Uri baseDir;
|
||||
final SkiaGoldClient skiaClient;
|
||||
@@ -104,14 +96,10 @@ final class _GoldenFileComparator extends GoldenFileComparator {
|
||||
_localFs.file(goldenFile.path),
|
||||
);
|
||||
if (result != null) {
|
||||
io.stderr.writeln(
|
||||
'Skia Gold detected an error when comparing "$golden":\n\n$result',
|
||||
);
|
||||
io.stderr.writeln('Skia Gold detected an error when comparing "$golden":\n\n$result');
|
||||
io.stderr.writeln('Still succeeding, will be triaged in Flutter Gold');
|
||||
} else {
|
||||
io.stderr.writeln(
|
||||
'Skia Gold comparison succeeded comparing "$golden".',
|
||||
);
|
||||
io.stderr.writeln('Skia Gold comparison succeeded comparing "$golden".');
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@@ -121,9 +109,7 @@ final class _GoldenFileComparator extends GoldenFileComparator {
|
||||
|
||||
@override
|
||||
Future<io.File> update(Uri golden, Uint8List imageBytes) async {
|
||||
io.stderr.writeln(
|
||||
'Updating golden file: $golden (${imageBytes.length} bytes)...',
|
||||
);
|
||||
io.stderr.writeln('Updating golden file: $golden (${imageBytes.length} bytes)...');
|
||||
final io.File goldenFile = _getGoldenFile(golden);
|
||||
await goldenFile.parent.create(recursive: true);
|
||||
await goldenFile.writeAsBytes(imageBytes, flush: true);
|
||||
@@ -140,10 +126,12 @@ final class _GoldenFileComparator extends GoldenFileComparator {
|
||||
'Golden files in the Flutter framework must end with the file extension '
|
||||
'.png.',
|
||||
);
|
||||
return Uri.parse(<String>[
|
||||
if (namePrefix != null) namePrefix!,
|
||||
baseDir.pathSegments[baseDir.pathSegments.length - 2],
|
||||
golden.toString(),
|
||||
].join('.'));
|
||||
return Uri.parse(
|
||||
<String>[
|
||||
if (namePrefix != null) namePrefix!,
|
||||
baseDir.pathSegments[baseDir.pathSegments.length - 2],
|
||||
golden.toString(),
|
||||
].join('.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ class Adb {
|
||||
}) async {
|
||||
target ??= const AndroidDeviceTarget.onlyEmulatorOrDevice();
|
||||
final String tool = adbPath ?? 'adb';
|
||||
final Adb adb = Adb._(
|
||||
<String>[tool, ...target._toAdbArgs()],
|
||||
processManager ?? const LocalProcessManager(),
|
||||
);
|
||||
final Adb adb = Adb._(<String>[
|
||||
tool,
|
||||
...target._toAdbArgs(),
|
||||
], processManager ?? const LocalProcessManager());
|
||||
final (bool connected, String? error) = await adb.isDeviceConnected();
|
||||
if (!connected) {
|
||||
throw StateError('No device connected: $error');
|
||||
@@ -41,12 +41,7 @@ class Adb {
|
||||
}
|
||||
|
||||
Future<AdbStringResult> _runString(List<String> args) async {
|
||||
final io.ProcessResult result = await _process.run(
|
||||
<String>[
|
||||
..._prefixArgs,
|
||||
...args,
|
||||
],
|
||||
);
|
||||
final io.ProcessResult result = await _process.run(<String>[..._prefixArgs, ...args]);
|
||||
return AdbStringResult(
|
||||
result.stdout as String,
|
||||
exitCode: result.exitCode,
|
||||
@@ -55,13 +50,10 @@ class Adb {
|
||||
}
|
||||
|
||||
Future<AdbBinaryResult> _runBinary(List<String> args) async {
|
||||
final io.ProcessResult result = await _process.run(
|
||||
<String>[
|
||||
..._prefixArgs,
|
||||
...args,
|
||||
],
|
||||
stdoutEncoding: null,
|
||||
);
|
||||
final io.ProcessResult result = await _process.run(<String>[
|
||||
..._prefixArgs,
|
||||
...args,
|
||||
], stdoutEncoding: null);
|
||||
return AdbBinaryResult(
|
||||
result.stdout as Uint8List,
|
||||
exitCode: result.exitCode,
|
||||
@@ -78,11 +70,7 @@ class Adb {
|
||||
/// and an error message if the device is not connected. If the device is
|
||||
/// connected, the error message is `null`.
|
||||
Future<(bool connected, String? error)> isDeviceConnected() async {
|
||||
final AdbStringResult result = await _runString(<String>[
|
||||
'shell',
|
||||
'echo',
|
||||
'connected',
|
||||
]);
|
||||
final AdbStringResult result = await _runString(<String>['shell', 'echo', 'connected']);
|
||||
if (result.exitCode != 0) {
|
||||
return (false, result.stderr);
|
||||
} else {
|
||||
@@ -92,11 +80,7 @@ class Adb {
|
||||
|
||||
/// Takes a screenshot of the device.
|
||||
Future<Uint8List> screencap() async {
|
||||
final AdbBinaryResult result = await _runBinary(<String>[
|
||||
'exec-out',
|
||||
'screencap',
|
||||
'-p',
|
||||
]);
|
||||
final AdbBinaryResult result = await _runBinary(<String>['exec-out', 'screencap', '-p']);
|
||||
if (result.exitCode != 0) {
|
||||
throw StateError('Failed to take screenshot: ${result.stderr}');
|
||||
}
|
||||
@@ -105,13 +89,7 @@ class Adb {
|
||||
|
||||
/// Taps on the screen at the given [x] and [y] coordinates.
|
||||
Future<void> tap(int x, int y) async {
|
||||
final AdbStringResult result = await _runString(<String>[
|
||||
'shell',
|
||||
'input',
|
||||
'tap',
|
||||
'$x',
|
||||
'$y',
|
||||
]);
|
||||
final AdbStringResult result = await _runString(<String>['shell', 'input', 'tap', '$x', '$y']);
|
||||
if (result.exitCode != 0) {
|
||||
throw StateError('Failed to tap at $x, $y: ${result.stderr}');
|
||||
}
|
||||
@@ -145,10 +123,7 @@ class Adb {
|
||||
}
|
||||
|
||||
/// Resume a backgrounded app (i.e. after [sendToHome]).
|
||||
Future<void> resumeApp({
|
||||
required String appName,
|
||||
String activityName = '.MainActivity',
|
||||
}) async {
|
||||
Future<void> resumeApp({required String appName, String activityName = '.MainActivity'}) async {
|
||||
final AdbStringResult result = await _runString(<String>[
|
||||
'shell',
|
||||
'am',
|
||||
@@ -172,9 +147,7 @@ class Adb {
|
||||
'confirmed',
|
||||
]);
|
||||
if (result.exitCode != 0) {
|
||||
throw StateError(
|
||||
'Failed to disable immersive mode confirmations: ${result.stderr}',
|
||||
);
|
||||
throw StateError('Failed to disable immersive mode confirmations: ${result.stderr}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,9 +223,7 @@ sealed class AndroidDeviceTarget {
|
||||
/// ```dart
|
||||
/// const AndroidDeviceTarget target = AndroidDeviceTarget.bySerial('emulator-5554');
|
||||
/// ```
|
||||
const factory AndroidDeviceTarget.bySerial(
|
||||
String serialNumber,
|
||||
) = _SerialDeviceTarget;
|
||||
const factory AndroidDeviceTarget.bySerial(String serialNumber) = _SerialDeviceTarget;
|
||||
|
||||
/// Represents the only running emulator _or_ connected device.
|
||||
///
|
||||
@@ -314,5 +285,5 @@ enum AdbUserRotation {
|
||||
reversePortrait,
|
||||
|
||||
/// Reverse landscape orientation, i.e., landscape upside down.
|
||||
reverseLandscape;
|
||||
reverseLandscape,
|
||||
}
|
||||
|
||||
@@ -44,10 +44,7 @@ final class AndroidNativeDriver implements NativeDriver {
|
||||
String? adbPath,
|
||||
io.Directory? tempDirectory,
|
||||
}) async {
|
||||
final Adb adb = await Adb.create(
|
||||
adbPath: adbPath,
|
||||
target: target,
|
||||
);
|
||||
final Adb adb = await Adb.create(adbPath: adbPath, target: target);
|
||||
tempDirectory ??= io.Directory.systemTemp.createTempSync('native_driver.');
|
||||
final AndroidNativeDriver nativeDriver = AndroidNativeDriver.forTesting(
|
||||
adb: adb,
|
||||
|
||||
@@ -19,19 +19,13 @@ final class NativeCommand extends Command {
|
||||
}
|
||||
|
||||
/// Requests that the device be rotated to landscape mode.
|
||||
static const NativeCommand rotateLandscape = NativeCommand(
|
||||
'rotate_landscape',
|
||||
);
|
||||
static const NativeCommand rotateLandscape = NativeCommand('rotate_landscape');
|
||||
|
||||
/// Requests that the device reset its rotation to the default orientation.
|
||||
static const NativeCommand rotateDefault = NativeCommand(
|
||||
'rotate_default',
|
||||
);
|
||||
static const NativeCommand rotateDefault = NativeCommand('rotate_default');
|
||||
|
||||
/// Pings the device to ensure it is responsive.
|
||||
static const NativeCommand ping = NativeCommand(
|
||||
'ping',
|
||||
);
|
||||
static const NativeCommand ping = NativeCommand('ping');
|
||||
|
||||
/// The method to call on the plugin.
|
||||
final String method;
|
||||
@@ -88,10 +82,7 @@ final class ByNativeAccessibilityLabel extends NativeFinder {
|
||||
|
||||
@override
|
||||
Map<String, String> toJson() {
|
||||
return <String, String>{
|
||||
'kind': 'byNativeAccessibilityLabel',
|
||||
'label': label,
|
||||
};
|
||||
return <String, String>{'kind': 'byNativeAccessibilityLabel', 'label': label};
|
||||
}
|
||||
|
||||
/// Deserializes this finder from the value generated by [serialize].
|
||||
@@ -118,10 +109,7 @@ final class ByNativeIntegerId extends NativeFinder {
|
||||
|
||||
@override
|
||||
Map<String, String> toJson() {
|
||||
return <String, String>{
|
||||
'kind': 'byNativeIntegerId',
|
||||
'id': id.toString(),
|
||||
};
|
||||
return <String, String>{'kind': 'byNativeIntegerId', 'id': id.toString()};
|
||||
}
|
||||
|
||||
/// Deserializes this finder from the value generated by [serialize].
|
||||
|
||||
@@ -171,8 +171,7 @@ AsyncMatcher matchesGoldenFile(Object key, {int? version}) {
|
||||
return switch (key) {
|
||||
Uri() => _MatchesGoldenFile(key, version),
|
||||
String() => _MatchesGoldenFile.forStringPath(key, version),
|
||||
_ => throw ArgumentError(
|
||||
'Unexpected type for golden file: ${key.runtimeType}'),
|
||||
_ => throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -182,8 +181,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
|
||||
const _MatchesGoldenFile(this.key, this.version);
|
||||
|
||||
/// Creates an instance of [MatchesGoldenFile] from a [String] path.
|
||||
_MatchesGoldenFile.forStringPath(String path, this.version)
|
||||
: key = Uri.parse(path);
|
||||
_MatchesGoldenFile.forStringPath(String path, this.version) : key = Uri.parse(path);
|
||||
|
||||
/// The [key] to the golden image.
|
||||
final Uri key;
|
||||
@@ -201,9 +199,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
|
||||
} else if (item is FutureOr<NativeScreenshot>) {
|
||||
buffer = await (await item).readAsBytes();
|
||||
} else {
|
||||
throw ArgumentError(
|
||||
'Unexpected type for golden file: ${item.runtimeType}',
|
||||
);
|
||||
throw ArgumentError('Unexpected type for golden file: ${item.runtimeType}');
|
||||
}
|
||||
|
||||
if (autoUpdateGoldenFiles) {
|
||||
@@ -211,10 +207,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final bool success = await goldenFileComparator.compare(
|
||||
buffer,
|
||||
testNameUri,
|
||||
);
|
||||
final bool success = await goldenFileComparator.compare(buffer, testNameUri);
|
||||
return success ? null : 'does not match';
|
||||
} on TestFailure catch (e) {
|
||||
return e.message;
|
||||
|
||||
@@ -18,10 +18,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
caughtArgs = <String>[];
|
||||
processManager = FakeProcessManager((
|
||||
String exec,
|
||||
List<String> args,
|
||||
) async {
|
||||
processManager = FakeProcessManager((String exec, List<String> args) async {
|
||||
assert(caughtArgs.isEmpty, 'Should only catch one call to run');
|
||||
caughtArgs = args;
|
||||
return FakeProcessManager.ok();
|
||||
@@ -74,14 +71,14 @@ void main() {
|
||||
});
|
||||
|
||||
expect(
|
||||
Adb.create(
|
||||
processManager: processManager,
|
||||
Adb.create(processManager: processManager),
|
||||
throwsA(
|
||||
isA<StateError>().having(
|
||||
(StateError e) => e.message,
|
||||
'message',
|
||||
'No device connected: error',
|
||||
),
|
||||
),
|
||||
throwsA(isA<StateError>().having(
|
||||
(StateError e) => e.message,
|
||||
'message',
|
||||
'No device connected: error',
|
||||
)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -100,9 +97,7 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
final Adb adb = await Adb.create(
|
||||
processManager: processManager,
|
||||
);
|
||||
final Adb adb = await Adb.create(processManager: processManager);
|
||||
|
||||
final Uint8List result = await adb.screencap();
|
||||
expect(result, <int>[0, 1, 2, 3]);
|
||||
@@ -123,9 +118,7 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
final Adb adb = await Adb.create(
|
||||
processManager: processManager,
|
||||
);
|
||||
final Adb adb = await Adb.create(processManager: processManager);
|
||||
|
||||
await adb.tap(1, 2);
|
||||
});
|
||||
|
||||
@@ -13,9 +13,7 @@ import 'src/fake_driver.dart';
|
||||
|
||||
void main() async {
|
||||
test('screenshot calls ADB screencap', () async {
|
||||
final FakeAdb adb = FakeAdb(
|
||||
screencap: () async => Uint8List.fromList(<int>[1, 2, 3, 4]),
|
||||
);
|
||||
final FakeAdb adb = FakeAdb(screencap: () async => Uint8List.fromList(<int>[1, 2, 3, 4]));
|
||||
final io.Directory tmpDir = io.Directory.systemTemp.createTempSync();
|
||||
final AndroidNativeDriver driver = AndroidNativeDriver.forTesting(
|
||||
adb: adb,
|
||||
|
||||
@@ -19,14 +19,14 @@ final class FakeAdb implements Adb {
|
||||
Future<void> Function()? sendToHome,
|
||||
Future<void> Function(String appName, [String? activityName])? resumeApp,
|
||||
Future<void> Function(String appName)? trimMemory,
|
||||
}) : _isDeviceConnected = isDeviceConnected,
|
||||
_screencap = screencap,
|
||||
_tap = tap,
|
||||
_disableImmersiveModeConfirmations = disableImmersiveModeConfirmations,
|
||||
_disableAnimations = disableAnimations,
|
||||
_sendToHome = sendToHome,
|
||||
_resumeApp = resumeApp,
|
||||
_trimMemory = trimMemory;
|
||||
}) : _isDeviceConnected = isDeviceConnected,
|
||||
_screencap = screencap,
|
||||
_tap = tap,
|
||||
_disableImmersiveModeConfirmations = disableImmersiveModeConfirmations,
|
||||
_disableAnimations = disableAnimations,
|
||||
_sendToHome = sendToHome,
|
||||
_resumeApp = resumeApp,
|
||||
_trimMemory = trimMemory;
|
||||
|
||||
@override
|
||||
Future<(bool, String?)> isDeviceConnected() async {
|
||||
@@ -75,10 +75,7 @@ final class FakeAdb implements Adb {
|
||||
return _resumeApp?.call(appName, activityName) ?? Future<void>.value();
|
||||
}
|
||||
|
||||
final Future<void> Function(
|
||||
String appName, [
|
||||
String? activityName,
|
||||
])? _resumeApp;
|
||||
final Future<void> Function(String appName, [String? activityName])? _resumeApp;
|
||||
|
||||
@override
|
||||
Future<void> trimMemory({required String appName}) {
|
||||
|
||||
@@ -13,10 +13,7 @@ import 'package:process/process.dart';
|
||||
final class FakeProcessManager extends ProcessManager {
|
||||
/// Creates a new [FakeProcessManager] with the given delegate callback.
|
||||
FakeProcessManager(this._runDelegate);
|
||||
final Future<ProcessResult> Function(
|
||||
String executable,
|
||||
List<String> arguments,
|
||||
) _runDelegate;
|
||||
final Future<ProcessResult> Function(String executable, List<String> arguments) _runDelegate;
|
||||
|
||||
@override
|
||||
Never noSuchMethod(_) => throw UnimplementedError();
|
||||
|
||||
Reference in New Issue
Block a user