Files
packages/script/tool/test/mocks.dart
Jenn Magder bb5a25815c [ci] Upload screenshots, logs, and Xcode test results for drive and integration_test runs (#7430)
1. Native Xcode tests will output a helpful "xcresult" package on failure containing logs, screenshots, and screen recordings.  Zip and upload these results when tests fail.

2. Pass `flutter test --debug-logs-dir` flag to upload logs  like https://github.com/flutter/flutter/pull/142643.

3. Pass `flutter drive --screenshot` flag to upload screenshots on timeout like https://github.com/flutter/flutter/pull/96973.

Example of [failing Xcode analyzer build](https://ci.chromium.org/ui/p/flutter/builders/try/Mac_arm64%20ios_platform_tests_shard_5%20master/17374/overview) has the [zipped xcresult](https://storage.googleapis.com/flutter_logs/flutter/ff98c32e-18ca-4ad4-a910-9db1d7f7e4b0/xcode%20analyze/ff98c32e-18ca-4ad4-a910-9db1d7f7e4b0/xcodebuild-2024-10-25T09:56:46.440913.zip) attached as a log.
![Screenshot 2024-10-25 at 10 10 36 AM](https://github.com/user-attachments/assets/dd7ae9bc-6161-4381-8a4f-f10b8c981801)

The unzipped xcresult looks like this in Xcode:

![Screenshot 2024-10-25 at 10 11 55 AM](https://github.com/user-attachments/assets/d4dd8420-f272-459c-9785-ab0c03887a74)

A [failing "native test" step build](https://ci.chromium.org/ui/p/flutter/builders/try/Mac_arm64%20macos_platform_tests%20master%20-%20packages/17315/overview):

![Screenshot 2024-10-25 at 10 19 55 AM](https://github.com/user-attachments/assets/76a86a15-2150-482a-8b15-e3e7ac90485e)

Fixes https://github.com/flutter/flutter/issues/144795
2024-11-06 06:58:26 +00:00

96 lines
2.4 KiB
Dart

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
import 'package:file/file.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
class MockPlatform extends Mock implements Platform {
MockPlatform({
this.isLinux = false,
this.isMacOS = false,
this.isWindows = false,
});
@override
bool isLinux;
@override
bool isMacOS;
@override
bool isWindows;
@override
Uri get script => isWindows
? Uri.file(r'C:\foo\bar', windows: true)
: Uri.file('/foo/bar', windows: false);
@override
Map<String, String> environment = <String, String>{};
@override
String get pathSeparator => isWindows ? r'\' : '/';
}
class MockProcess extends Mock implements io.Process {
/// Creates a mock process with the given results.
///
/// The default encodings match the ProcessRunner defaults; mocks for
/// processes run with a different encoding will need to be created with
/// the matching encoding.
MockProcess({
int exitCode = 0,
String? stdout,
String? stderr,
Encoding stdoutEncoding = io.systemEncoding,
Encoding stderrEncoding = io.systemEncoding,
}) : _exitCode = exitCode {
if (stdout != null) {
_stdoutController.add(stdoutEncoding.encoder.convert(stdout));
}
if (stderr != null) {
_stderrController.add(stderrEncoding.encoder.convert(stderr));
}
_stdoutController.close();
_stderrController.close();
}
final int _exitCode;
final StreamController<List<int>> _stdoutController =
StreamController<List<int>>();
final StreamController<List<int>> _stderrController =
StreamController<List<int>>();
final MockIOSink stdinMock = MockIOSink();
@override
int get pid => 99;
@override
Future<int> get exitCode async => _exitCode;
@override
Stream<List<int>> get stdout => _stdoutController.stream;
@override
Stream<List<int>> get stderr => _stderrController.stream;
@override
IOSink get stdin => stdinMock;
@override
bool kill([io.ProcessSignal signal = io.ProcessSignal.sigterm]) => true;
}
class MockIOSink extends Mock implements IOSink {
List<String> lines = <String>[];
@override
void writeln([Object? obj = '']) => lines.add(obj.toString());
}