Skip to content

Commit 7292c94

Browse files
authored
Update android_device.dart to have clearLogs not print to standard error (flutter#150197)
Even though this does not fix the below issue lets land this anyway as not logging to stderr when clearing logs makes sense to me. related flutter#150093 The test added is bad. It does not verify the behavior changed. To verify the behavior changed correctly I would need to modify the generic device class to have clearLogs be an async function like many of the other calls. That would mean modifying every other device type and their implementations and their tests. Then I would need to update android_device to expose its logger. That is more than I have time for to validate a 2% flake error. Feel free to disagree in the comments on this pr.
1 parent fd3f769 commit 7292c94

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/flutter_tools/lib/src/android/android_device.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,12 @@ class AndroidDevice extends Device {
778778

779779
@override
780780
void clearLogs() {
781-
_processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
781+
final RunResult result = _processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
782+
// Do not log to standard error because that causes test to fail.
783+
if (result.exitCode != 0) {
784+
_logger.printTrace('"adb logcat -c" failed: exitCode: ${result.exitCode}'
785+
' stdout: ${result.stdout} stderr: ${result.stderr}');
786+
}
782787
}
783788

784789
@override

packages/flutter_tools/test/general.shard/android/android_device_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ flutter:
331331
expect(await device.emulatorId, isNull);
332332
});
333333

334+
testWithoutContext('AndroidDevice clearLogs does not crash', () async {
335+
final AndroidDevice device = setUpAndroidDevice(
336+
processManager: FakeProcessManager.list(<FakeCommand>[
337+
const FakeCommand(
338+
command: <String>['adb', '-s', '1234', 'logcat', '-c'],
339+
exitCode: 1,
340+
),
341+
])
342+
);
343+
device.clearLogs();
344+
});
345+
334346
testWithoutContext('AndroidDevice lastLogcatTimestamp returns null if shell command failed', () async {
335347
final AndroidDevice device = setUpAndroidDevice(
336348
processManager: FakeProcessManager.list(<FakeCommand>[

0 commit comments

Comments
 (0)