Update android_device.dart to have clearLogs not print to standard error (#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 https://github.com/flutter/flutter/issues/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.
This commit is contained in:
Reid Baker 2024-06-24 14:38:27 -04:00 committed by GitHub
parent fd3f769ec5
commit 7292c94bac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -778,7 +778,12 @@ class AndroidDevice extends Device {
@override
void clearLogs() {
_processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
final RunResult result = _processUtils.runSync(adbCommandForDevice(<String>['logcat', '-c']));
// Do not log to standard error because that causes test to fail.
if (result.exitCode != 0) {
_logger.printTrace('"adb logcat -c" failed: exitCode: ${result.exitCode}'
' stdout: ${result.stdout} stderr: ${result.stderr}');
}
}
@override

View file

@ -331,6 +331,18 @@ flutter:
expect(await device.emulatorId, isNull);
});
testWithoutContext('AndroidDevice clearLogs does not crash', () async {
final AndroidDevice device = setUpAndroidDevice(
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['adb', '-s', '1234', 'logcat', '-c'],
exitCode: 1,
),
])
);
device.clearLogs();
});
testWithoutContext('AndroidDevice lastLogcatTimestamp returns null if shell command failed', () async {
final AndroidDevice device = setUpAndroidDevice(
processManager: FakeProcessManager.list(<FakeCommand>[