From f39f734a0b8416dae35c81a8dbeb977ed2d2bdcc Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 9 Jul 2024 14:13:09 -0700 Subject: [PATCH 1/7] Add screenshot functionality to drive --- script/tool/lib/src/common/core.dart | 11 ++ script/tool/lib/src/common/xcode.dart | 54 +++++++- .../tool/lib/src/drive_examples_command.dart | 19 ++- script/tool/lib/src/native_test_command.dart | 15 +-- .../tool/lib/src/xcode_analyze_command.dart | 15 +-- script/tool/test/common/xcode_test.dart | 4 + .../test/drive_examples_command_test.dart | 119 ++++++++++++++++++ 7 files changed, 216 insertions(+), 21 deletions(-) diff --git a/script/tool/lib/src/common/core.dart b/script/tool/lib/src/common/core.dart index a26c8391596..9fef751ab56 100644 --- a/script/tool/lib/src/common/core.dart +++ b/script/tool/lib/src/common/core.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:file/file.dart'; +import 'package:platform/platform.dart'; import 'package:pub_semver/pub_semver.dart'; /// The signature for a print handler for commands that allow overriding the @@ -127,3 +128,13 @@ const int exitCommandFoundErrors = 1; /// A exit code for [ToolExit] for a failure to run due to invalid arguments. const int exitInvalidArguments = 2; + +/// The directory to which to write logs and other artifacts, if set in CI. +Directory? ciLogsDirectory(Platform platform, FileSystem fileSystem) { + final String? logsDirectoryPath = platform.environment['FLUTTER_LOGS_DIR']; + Directory? logsDirectory; + if (logsDirectoryPath != null) { + logsDirectory = fileSystem.directory(logsDirectoryPath); + } + return logsDirectory; +} diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index 4a4bf03ba54..af75667ff5d 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -6,7 +6,9 @@ import 'dart:convert'; import 'dart:io' as io; import 'package:file/file.dart'; +import 'package:platform/platform.dart'; +import 'core.dart'; import 'output_utils.dart'; import 'process_runner.dart'; @@ -33,17 +35,29 @@ class Xcode { /// Runs an `xcodebuild` in [directory] with the given parameters. Future runXcodeBuild( Directory exampleDirectory, - String platform, { + String targetPlatform, { List actions = const ['build'], required String workspace, required String scheme, String? configuration, List extraFlags = const [], - }) { + required Platform platform, + }) async { + final FileSystem fileSystem = exampleDirectory.fileSystem; + String? resultBundlePath; + final Directory? logsDirectory = ciLogsDirectory(platform, fileSystem); + Directory? resultBundleTemp; + if (logsDirectory != null) { + resultBundleTemp = fileSystem.systemTempDirectory + .createTempSync('flutter_xcresult.'); + resultBundlePath = resultBundleTemp + .childDirectory('result') + .path; + } File? disabledSandboxEntitlementFile; - if (actions.contains('test') && platform.toLowerCase() == 'macos') { + if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') { disabledSandboxEntitlementFile = _createDisabledSandboxEntitlementFile( - exampleDirectory.childDirectory(platform.toLowerCase()), + exampleDirectory.childDirectory(targetPlatform.toLowerCase()), configuration ?? 'Debug', ); } @@ -52,6 +66,8 @@ class Xcode { ...actions, ...['-workspace', workspace], ...['-scheme', scheme], + if (resultBundlePath != null) + ...['-resultBundlePath', resultBundlePath], if (configuration != null) ...['-configuration', configuration], ...extraFlags, if (disabledSandboxEntitlementFile != null) @@ -61,8 +77,36 @@ class Xcode { if (log) { print(completeTestCommand); } - return processRunner.runAndStream(_xcRunCommand, args, + final int resultExit = await processRunner.runAndStream(_xcRunCommand, args, workingDir: exampleDirectory); + + if (resultExit != 0 && resultBundleTemp != null) { + final Directory xcresultBundle = resultBundleTemp.childDirectory( + 'result.xcresult'); + if (logsDirectory != null) { + if (xcresultBundle.existsSync()) { + // Zip the test results to the artifacts directory for upload. + final File zipPath = logsDirectory.childFile( + 'xcodebuild-${DateTime.now().toLocal().toIso8601String()}.zip'); + await processRunner.run( + 'zip', + [ + '-r', + '-9', + '-q', + zipPath.path, + xcresultBundle.basename, + ], + workingDir: resultBundleTemp, + ); + } else { + print('xcresult bundle ${xcresultBundle + .path} does not exist, skipping upload'); + } + } + } + return resultExit; + } /// Returns true if [project], which should be an .xcodeproj directory, diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index a5ddd3bd4a9..620840265fc 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -228,8 +228,12 @@ class DriveExamplesCommand extends PackageLoopingCommand { } for (final File driver in drivers) { final List failingTargets = await _driveTests( - example, driver, testTargets, - deviceFlags: deviceFlags); + example, + driver, + testTargets, + deviceFlags: deviceFlags, + exampleName: exampleName, + ); for (final File failingTarget in failingTargets) { errors.add( getRelativePosixPath(failingTarget, from: package.directory)); @@ -376,12 +380,18 @@ class DriveExamplesCommand extends PackageLoopingCommand { File driver, List targets, { required List deviceFlags, + required String exampleName, }) async { final List failures = []; final String enableExperiment = getStringArg(kEnableExperiment); + final Directory? logsDirectory = ciLogsDirectory(platform, driver.fileSystem); for (final File target in targets) { + Directory? screenshotDirectory; + if (logsDirectory != null) { + screenshotDirectory = logsDirectory.childDirectory('$exampleName-drive'); + } final int exitCode = await processRunner.runAndStream( flutterCommand, [ @@ -389,6 +399,8 @@ class DriveExamplesCommand extends PackageLoopingCommand { ...deviceFlags, if (enableExperiment.isNotEmpty) '--enable-experiment=$enableExperiment', + if (screenshotDirectory != null) + '--screenshot=${screenshotDirectory.path}', '--driver', getRelativePosixPath(driver, from: example.directory), '--target', @@ -416,6 +428,7 @@ class DriveExamplesCommand extends PackageLoopingCommand { required List testFiles, }) async { final String enableExperiment = getStringArg(kEnableExperiment); + final Directory? logsDirectory = testFiles.isNotEmpty ? ciLogsDirectory(platform, testFiles.first.fileSystem) : null; // Workaround for https://github.com/flutter/flutter/issues/135673 // Once that is fixed on stable, this logic can be removed and the command @@ -438,6 +451,8 @@ class DriveExamplesCommand extends PackageLoopingCommand { ...deviceFlags, if (enableExperiment.isNotEmpty) '--enable-experiment=$enableExperiment', + if (logsDirectory != null) + '--debug-logs-dir=${logsDirectory.path}', target, ], workingDir: example.directory); diff --git a/script/tool/lib/src/native_test_command.dart b/script/tool/lib/src/native_test_command.dart index 1cd7afb6b4a..33f3a5b0af2 100644 --- a/script/tool/lib/src/native_test_command.dart +++ b/script/tool/lib/src/native_test_command.dart @@ -431,7 +431,7 @@ this command. /// usually at "example/{ios,macos}/Runner.xcworkspace". Future<_PlatformResult> _runXcodeTests( RepositoryPackage plugin, - String platform, + String targetPlatform, _TestMode mode, { List extraFlags = const [], }) async { @@ -456,7 +456,7 @@ this command. final String? targetToCheck = testTarget ?? (mode.unit ? unitTestTarget : null); final Directory xcodeProject = example.directory - .childDirectory(platform.toLowerCase()) + .childDirectory(targetPlatform.toLowerCase()) .childDirectory('Runner.xcodeproj'); if (targetToCheck != null) { final bool? hasTarget = @@ -473,16 +473,17 @@ this command. } } - _printRunningExampleTestsMessage(example, platform); + _printRunningExampleTestsMessage(example, targetPlatform); final int exitCode = await _xcode.runXcodeBuild( example.directory, - platform, + targetPlatform, // Clean before testing to remove cached swiftmodules from previous // runs, which can cause conflicts. actions: ['clean', 'test'], - workspace: '${platform.toLowerCase()}/Runner.xcworkspace', + workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace', scheme: 'Runner', configuration: 'Debug', + platform: platform, extraFlags: [ if (testTarget != null) '-only-testing:$testTarget', ...extraFlags, @@ -494,9 +495,9 @@ this command. const int xcodebuildNoTestExitCode = 66; switch (exitCode) { case xcodebuildNoTestExitCode: - _printNoExampleTestsMessage(example, platform); + _printNoExampleTestsMessage(example, targetPlatform); case 0: - printSuccess('Successfully ran $platform xctest for $exampleName'); + printSuccess('Successfully ran $targetPlatform xctest for $exampleName'); // If this is the first test, assume success until something fails. if (overallResult == RunState.skipped) { overallResult = RunState.succeeded; diff --git a/script/tool/lib/src/xcode_analyze_command.dart b/script/tool/lib/src/xcode_analyze_command.dart index 707a3f08b6d..5104794f100 100644 --- a/script/tool/lib/src/xcode_analyze_command.dart +++ b/script/tool/lib/src/xcode_analyze_command.dart @@ -97,10 +97,10 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand { multiplePlatformsRequested ? failures : []); } - /// Analyzes [plugin] for [platform], returning true if it passed analysis. + /// Analyzes [plugin] for [targetPlatform], returning true if it passed analysis. Future _analyzePlugin( RepositoryPackage plugin, - String platform, { + String targetPlatform, { List extraFlags = const [], }) async { bool passing = true; @@ -108,25 +108,26 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand { // Running tests and static analyzer. final String examplePath = getRelativePosixPath(example.directory, from: plugin.directory.parent); - print('Running $platform tests and analyzer for $examplePath...'); + print('Running $targetPlatform tests and analyzer for $examplePath...'); final int exitCode = await _xcode.runXcodeBuild( example.directory, - platform, + targetPlatform, // Clean before analyzing to remove cached swiftmodules from previous // runs, which can cause conflicts. actions: ['clean', 'analyze'], - workspace: '${platform.toLowerCase()}/Runner.xcworkspace', + workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace', scheme: 'Runner', configuration: 'Debug', + platform: platform, extraFlags: [ ...extraFlags, 'GCC_TREAT_WARNINGS_AS_ERRORS=YES', ], ); if (exitCode == 0) { - printSuccess('$examplePath ($platform) passed analysis.'); + printSuccess('$examplePath ($targetPlatform) passed analysis.'); } else { - printError('$examplePath ($platform) failed analysis.'); + printError('$examplePath ($targetPlatform) failed analysis.'); passing = false; } } diff --git a/script/tool/test/common/xcode_test.dart b/script/tool/test/common/xcode_test.dart index 8fd41516001..61f2b942888 100644 --- a/script/tool/test/common/xcode_test.dart +++ b/script/tool/test/common/xcode_test.dart @@ -165,6 +165,7 @@ void main() { 'ios', workspace: 'A.xcworkspace', scheme: 'AScheme', + platform: MockPlatform(), ); expect(exitCode, 0); @@ -193,6 +194,7 @@ void main() { workspace: 'A.xcworkspace', scheme: 'AScheme', configuration: 'Debug', + platform: MockPlatform(), extraFlags: ['-a', '-b', 'c=d']); expect(exitCode, 0); @@ -230,6 +232,7 @@ void main() { 'ios', workspace: 'A.xcworkspace', scheme: 'AScheme', + platform: MockPlatform(), ); expect(exitCode, 1); @@ -264,6 +267,7 @@ void main() { 'macos', workspace: 'A.xcworkspace', scheme: 'AScheme', + platform: MockPlatform(), actions: ['test'], ); diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index 6bbd5e301ad..7f86745056e 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -41,6 +41,7 @@ void main() { // TODO(dit): Clean this up, https://github.com/flutter/flutter/issues/151869 mockPlatform.environment['CHANNEL'] = 'master'; + mockPlatform.environment['FLUTTER_LOGS_DIR'] = '/path/to/logs'; }); void setMockFlutterDevicesOutput({ @@ -306,6 +307,57 @@ void main() { final Directory pluginExampleDirectory = getExampleDir(plugin); + setMockFlutterDevicesOutput(); + final List output = + await runCapturingPrint(runner, ['drive-examples', '--ios']); + + expect( + output, + containsAllInOrder([ + contains('Running for plugin'), + contains('No issues found!'), + ]), + ); + + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall(getFlutterCommand(mockPlatform), + const ['devices', '--machine'], null), + ProcessCall( + getFlutterCommand(mockPlatform), + const [ + 'test', + '-d', + _fakeIOSDevice, + '--debug-logs-dir=/path/to/logs', + 'integration_test', + ], + pluginExampleDirectory.path), + ])); + }); + + test('handles missing CI debug logs directory', () async { + mockPlatform.environment.remove('FLUTTER_LOGS_DIR'); + + final RepositoryPackage plugin = createFakePlugin( + 'plugin', + packagesDir, + extraFiles: [ + 'example/integration_test/bar_test.dart', + 'example/integration_test/foo_test.dart', + 'example/integration_test/ignore_me.dart', + 'example/android/android.java', + 'example/ios/ios.m', + ], + platformSupport: { + platformAndroid: const PlatformDetails(PlatformSupport.inline), + platformIOS: const PlatformDetails(PlatformSupport.inline), + }, + ); + + final Directory pluginExampleDirectory = getExampleDir(plugin); + setMockFlutterDevicesOutput(); final List output = await runCapturingPrint(runner, ['drive-examples', '--ios']); @@ -396,6 +448,7 @@ void main() { 'test', '-d', 'linux', + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -463,6 +516,7 @@ void main() { 'test', '-d', 'macos', + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -510,6 +564,7 @@ void main() { 'test', '-d', 'macos', + '--debug-logs-dir=/path/to/logs', 'integration_test/first_test.dart', ], pluginExampleDirectory.path), @@ -519,6 +574,7 @@ void main() { 'test', '-d', 'macos', + '--debug-logs-dir=/path/to/logs', 'integration_test/second_test.dart', ], pluginExampleDirectory.path), @@ -565,6 +621,7 @@ void main() { 'test', '-d', 'linux', + '--debug-logs-dir=/path/to/logs', 'integration_test/first_test.dart', ], pluginExampleDirectory.path), @@ -574,6 +631,7 @@ void main() { 'test', '-d', 'linux', + '--debug-logs-dir=/path/to/logs', 'integration_test/second_test.dart', ], pluginExampleDirectory.path), @@ -620,6 +678,7 @@ void main() { 'test', '-d', 'windows', + '--debug-logs-dir=/path/to/logs', 'integration_test/first_test.dart', ], pluginExampleDirectory.path), @@ -629,6 +688,7 @@ void main() { 'test', '-d', 'windows', + '--debug-logs-dir=/path/to/logs', 'integration_test/second_test.dart', ], pluginExampleDirectory.path), @@ -700,6 +760,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -751,6 +812,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--wasm', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -805,6 +867,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=html', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -854,6 +917,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -907,6 +971,7 @@ void main() { '--browser-name=chrome', '--web-renderer=canvaskit', '--chrome-binary=/path/to/chrome', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -977,6 +1042,7 @@ void main() { 'test', '-d', 'windows', + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -1023,6 +1089,7 @@ void main() { 'test', '-d', _fakeAndroidDevice, + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -1069,6 +1136,7 @@ void main() { 'test', '-d', _fakeAndroidDevice, + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -1197,6 +1265,7 @@ void main() { '-d', _fakeIOSDevice, '--enable-experiment=exp1', + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -1353,6 +1422,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1368,6 +1438,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/plugin/example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1425,6 +1496,7 @@ void main() { 'test', '-d', _fakeIOSDevice, + '--debug-logs-dir=/path/to/logs', 'integration_test', ], pluginExampleDirectory.path), @@ -1454,6 +1526,52 @@ void main() { ]), ); + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall( + getFlutterCommand(mockPlatform), + const [ + 'drive', + '-d', + 'web-server', + '--web-port=7357', + '--browser-name=chrome', + '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/a_package/example-drive', + '--driver', + 'test_driver/integration_test.dart', + '--target', + 'integration_test/foo_test.dart' + ], + exampleDirectory.path), + ])); + }); + + test('drive handles missing CI screenshot directory', () async { + mockPlatform.environment.remove('FLUTTER_LOGS_DIR'); + + final RepositoryPackage package = + createFakePackage('a_package', packagesDir, extraFiles: [ + 'example/integration_test/foo_test.dart', + 'example/test_driver/integration_test.dart', + 'example/web/index.html', + ]); + final Directory exampleDirectory = getExampleDir(package); + + final List output = await runCapturingPrint(runner, [ + 'drive-examples', + '--web', + ]); + + expect( + output, + containsAllInOrder([ + contains('Running for a_package'), + contains('No issues found!'), + ]), + ); + expect( processRunner.recordedCalls, orderedEquals([ @@ -1546,6 +1664,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', + '--screenshot=/path/to/logs/a_package/example/with_web-drive', '--driver', 'test_driver/integration_test.dart', '--target', From 8ac52ff7878c7de24c42473cca5dfed5576db2e6 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 25 Oct 2024 09:45:58 -0700 Subject: [PATCH 2/7] test failures --- .../darwin/RunnerTests/VideoPlayerTests.m | 1 + .../example/integration_test/video_player_test.dart | 3 ++- .../video_player_avfoundation/example/ios/Runner/AppDelegate.m | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m index 3ec96e78538..a9ceae2cf33 100644 --- a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m +++ b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m @@ -191,6 +191,7 @@ - (void)testBlankVideoBugWithEncryptedVideoStreamAndInvertedAspectRatioBugForSom } - (void)testSeekToWhilePausedStartsDisplayLinkTemporarily { + XCTFail(@"Failing to test xcresult upload"); NSObject *mockTextureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); NSObject *registrar = diff --git a/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart b/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart index d8a73b09d24..95fd6914b94 100644 --- a/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart +++ b/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart @@ -133,7 +133,8 @@ void main() { await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(await controller.position, greaterThan(Duration.zero)); + // test xcresult upload + expect(await controller.position, lessThan(Duration.zero)); }); }); diff --git a/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m b/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m index 30b87969f44..def188356c1 100644 --- a/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m +++ b/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m @@ -9,6 +9,8 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Test analyzer warning still works. + BOOL x = @"true"; [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. return [super application:application didFinishLaunchingWithOptions:launchOptions]; From 54003a8f010f563bcd60e8ec652c14ba55ca9eed Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 25 Oct 2024 10:21:11 -0700 Subject: [PATCH 3/7] Revert "test failures" This reverts commit d329678b5be29c3c03ac0d3e9dc18d3bc0d8d154. --- .../darwin/RunnerTests/VideoPlayerTests.m | 1 - .../example/integration_test/video_player_test.dart | 3 +-- .../video_player_avfoundation/example/ios/Runner/AppDelegate.m | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m index a9ceae2cf33..3ec96e78538 100644 --- a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m +++ b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m @@ -191,7 +191,6 @@ - (void)testBlankVideoBugWithEncryptedVideoStreamAndInvertedAspectRatioBugForSom } - (void)testSeekToWhilePausedStartsDisplayLinkTemporarily { - XCTFail(@"Failing to test xcresult upload"); NSObject *mockTextureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); NSObject *registrar = diff --git a/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart b/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart index 95fd6914b94..d8a73b09d24 100644 --- a/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart +++ b/packages/video_player/video_player_avfoundation/example/integration_test/video_player_test.dart @@ -133,8 +133,7 @@ void main() { await controller.play(); await tester.pumpAndSettle(_playDuration); - // test xcresult upload - expect(await controller.position, lessThan(Duration.zero)); + expect(await controller.position, greaterThan(Duration.zero)); }); }); diff --git a/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m b/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m index def188356c1..30b87969f44 100644 --- a/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m +++ b/packages/video_player/video_player_avfoundation/example/ios/Runner/AppDelegate.m @@ -9,8 +9,6 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Test analyzer warning still works. - BOOL x = @"true"; [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. return [super application:application didFinishLaunchingWithOptions:launchOptions]; From 937765c3fa2398a9b1b56d376f23faa110f5b4f4 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Mon, 4 Nov 2024 21:34:31 -0800 Subject: [PATCH 4/7] Review edits --- script/tool/lib/src/common/xcode.dart | 120 +++++++++--------- .../tool/lib/src/drive_examples_command.dart | 11 +- script/tool/lib/src/native_test_command.dart | 2 +- .../tool/lib/src/xcode_analyze_command.dart | 2 +- script/tool/test/common/xcode_test.dart | 8 +- .../test/drive_examples_command_test.dart | 2 +- 6 files changed, 74 insertions(+), 71 deletions(-) diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index af75667ff5d..24f36a002fd 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -41,72 +41,76 @@ class Xcode { required String scheme, String? configuration, List extraFlags = const [], - required Platform platform, + required Platform hostPlatform, }) async { final FileSystem fileSystem = exampleDirectory.fileSystem; String? resultBundlePath; - final Directory? logsDirectory = ciLogsDirectory(platform, fileSystem); + final Directory? logsDirectory = ciLogsDirectory(hostPlatform, fileSystem); Directory? resultBundleTemp; - if (logsDirectory != null) { - resultBundleTemp = fileSystem.systemTempDirectory - .createTempSync('flutter_xcresult.'); - resultBundlePath = resultBundleTemp - .childDirectory('result') - .path; - } - File? disabledSandboxEntitlementFile; - if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') { - disabledSandboxEntitlementFile = _createDisabledSandboxEntitlementFile( - exampleDirectory.childDirectory(targetPlatform.toLowerCase()), - configuration ?? 'Debug', - ); - } - final List args = [ - _xcodeBuildCommand, - ...actions, - ...['-workspace', workspace], - ...['-scheme', scheme], - if (resultBundlePath != null) - ...['-resultBundlePath', resultBundlePath], - if (configuration != null) ...['-configuration', configuration], - ...extraFlags, - if (disabledSandboxEntitlementFile != null) - 'CODE_SIGN_ENTITLEMENTS=${disabledSandboxEntitlementFile.path}', - ]; - final String completeTestCommand = '$_xcRunCommand ${args.join(' ')}'; - if (log) { - print(completeTestCommand); - } - final int resultExit = await processRunner.runAndStream(_xcRunCommand, args, - workingDir: exampleDirectory); - - if (resultExit != 0 && resultBundleTemp != null) { - final Directory xcresultBundle = resultBundleTemp.childDirectory( - 'result.xcresult'); + try { if (logsDirectory != null) { - if (xcresultBundle.existsSync()) { - // Zip the test results to the artifacts directory for upload. - final File zipPath = logsDirectory.childFile( - 'xcodebuild-${DateTime.now().toLocal().toIso8601String()}.zip'); - await processRunner.run( - 'zip', - [ - '-r', - '-9', - '-q', - zipPath.path, - xcresultBundle.basename, - ], - workingDir: resultBundleTemp, - ); - } else { - print('xcresult bundle ${xcresultBundle - .path} does not exist, skipping upload'); + resultBundleTemp = fileSystem.systemTempDirectory + .createTempSync('flutter_xcresult.'); + resultBundlePath = resultBundleTemp + .childDirectory('result') + .path; + } + File? disabledSandboxEntitlementFile; + if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') { + disabledSandboxEntitlementFile = _createDisabledSandboxEntitlementFile( + exampleDirectory.childDirectory(targetPlatform.toLowerCase()), + configuration ?? 'Debug', + ); + } + final List args = [ + _xcodeBuildCommand, + ...actions, + ...['-workspace', workspace], + ...['-scheme', scheme], + if (resultBundlePath != null) + ...['-resultBundlePath', resultBundlePath], + if (configuration != null) ...['-configuration', configuration], + ...extraFlags, + if (disabledSandboxEntitlementFile != null) + 'CODE_SIGN_ENTITLEMENTS=${disabledSandboxEntitlementFile.path}', + ]; + final String completeTestCommand = '$_xcRunCommand ${args.join(' ')}'; + if (log) { + print(completeTestCommand); + } + final int resultExit = await processRunner.runAndStream( + _xcRunCommand, args, + workingDir: exampleDirectory); + + if (resultExit != 0 && resultBundleTemp != null) { + final Directory xcresultBundle = resultBundleTemp.childDirectory( + 'result.xcresult'); + if (logsDirectory != null) { + if (xcresultBundle.existsSync()) { + // Zip the test results to the artifacts directory for upload. + final File zipPath = logsDirectory.childFile( + 'xcodebuild-${DateTime.now().toLocal().toIso8601String()}.zip'); + await processRunner.run( + 'zip', + [ + '-r', + '-9', + '-q', + zipPath.path, + xcresultBundle.basename, + ], + workingDir: resultBundleTemp, + ); + } else { + print('xcresult bundle ${xcresultBundle + .path} does not exist, skipping upload'); + } } } + return resultExit; + } finally { + resultBundleTemp?.deleteSync(); } - return resultExit; - } /// Returns true if [project], which should be an .xcodeproj directory, diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index 620840265fc..3b2e317b55c 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -385,13 +385,12 @@ class DriveExamplesCommand extends PackageLoopingCommand { final List failures = []; final String enableExperiment = getStringArg(kEnableExperiment); - final Directory? logsDirectory = ciLogsDirectory(platform, driver.fileSystem); + final String screenshotBasename = + '${exampleName.replaceAll(platform.pathSeparator, '_')}-drive'; + final Directory? screenshotDirectory = ciLogsDirectory(platform, driver.fileSystem) + ?.childDirectory(screenshotBasename); for (final File target in targets) { - Directory? screenshotDirectory; - if (logsDirectory != null) { - screenshotDirectory = logsDirectory.childDirectory('$exampleName-drive'); - } final int exitCode = await processRunner.runAndStream( flutterCommand, [ @@ -428,7 +427,7 @@ class DriveExamplesCommand extends PackageLoopingCommand { required List testFiles, }) async { final String enableExperiment = getStringArg(kEnableExperiment); - final Directory? logsDirectory = testFiles.isNotEmpty ? ciLogsDirectory(platform, testFiles.first.fileSystem) : null; + final Directory? logsDirectory = ciLogsDirectory(platform, testFiles.first.fileSystem); // Workaround for https://github.com/flutter/flutter/issues/135673 // Once that is fixed on stable, this logic can be removed and the command diff --git a/script/tool/lib/src/native_test_command.dart b/script/tool/lib/src/native_test_command.dart index 33f3a5b0af2..9329578697c 100644 --- a/script/tool/lib/src/native_test_command.dart +++ b/script/tool/lib/src/native_test_command.dart @@ -483,7 +483,7 @@ this command. workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace', scheme: 'Runner', configuration: 'Debug', - platform: platform, + hostPlatform: platform, extraFlags: [ if (testTarget != null) '-only-testing:$testTarget', ...extraFlags, diff --git a/script/tool/lib/src/xcode_analyze_command.dart b/script/tool/lib/src/xcode_analyze_command.dart index 5104794f100..ba4b3fb5e95 100644 --- a/script/tool/lib/src/xcode_analyze_command.dart +++ b/script/tool/lib/src/xcode_analyze_command.dart @@ -118,7 +118,7 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand { workspace: '${targetPlatform.toLowerCase()}/Runner.xcworkspace', scheme: 'Runner', configuration: 'Debug', - platform: platform, + hostPlatform: platform, extraFlags: [ ...extraFlags, 'GCC_TREAT_WARNINGS_AS_ERRORS=YES', diff --git a/script/tool/test/common/xcode_test.dart b/script/tool/test/common/xcode_test.dart index 61f2b942888..4d27372890f 100644 --- a/script/tool/test/common/xcode_test.dart +++ b/script/tool/test/common/xcode_test.dart @@ -165,7 +165,7 @@ void main() { 'ios', workspace: 'A.xcworkspace', scheme: 'AScheme', - platform: MockPlatform(), + hostPlatform: MockPlatform(), ); expect(exitCode, 0); @@ -194,7 +194,7 @@ void main() { workspace: 'A.xcworkspace', scheme: 'AScheme', configuration: 'Debug', - platform: MockPlatform(), + hostPlatform: MockPlatform(), extraFlags: ['-a', '-b', 'c=d']); expect(exitCode, 0); @@ -232,7 +232,7 @@ void main() { 'ios', workspace: 'A.xcworkspace', scheme: 'AScheme', - platform: MockPlatform(), + hostPlatform: MockPlatform(), ); expect(exitCode, 1); @@ -267,7 +267,7 @@ void main() { 'macos', workspace: 'A.xcworkspace', scheme: 'AScheme', - platform: MockPlatform(), + hostPlatform: MockPlatform(), actions: ['test'], ); diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index 7f86745056e..e886ded7067 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -1664,7 +1664,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/a_package/example/with_web-drive', + '--screenshot=/path/to/logs/a_package/example_with_web-drive', '--driver', 'test_driver/integration_test.dart', '--target', From 7e6e02c98cea40142ab42253de72a6b768659eea Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 5 Nov 2024 10:50:15 -0800 Subject: [PATCH 5/7] path separator --- .../tool/test/drive_examples_command_test.dart | 18 +++++++++--------- script/tool/test/mocks.dart | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index e886ded7067..5505db2bfe7 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -760,7 +760,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -812,7 +812,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--wasm', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -867,7 +867,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=html', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -917,7 +917,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -971,7 +971,7 @@ void main() { '--browser-name=chrome', '--web-renderer=canvaskit', '--chrome-binary=/path/to/chrome', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1422,7 +1422,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1438,7 +1438,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/plugin/example-drive', + '--screenshot=/path/to/logs/plugin_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1538,7 +1538,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/a_package/example-drive', + '--screenshot=/path/to/logs/a_package_example-drive', '--driver', 'test_driver/integration_test.dart', '--target', @@ -1664,7 +1664,7 @@ void main() { '--web-port=7357', '--browser-name=chrome', '--web-renderer=canvaskit', - '--screenshot=/path/to/logs/a_package/example_with_web-drive', + '--screenshot=/path/to/logs/a_package_example_with_web-drive', '--driver', 'test_driver/integration_test.dart', '--target', diff --git a/script/tool/test/mocks.dart b/script/tool/test/mocks.dart index 3ce9512ad01..2c84ecedd12 100644 --- a/script/tool/test/mocks.dart +++ b/script/tool/test/mocks.dart @@ -33,6 +33,9 @@ class MockPlatform extends Mock implements Platform { @override Map environment = {}; + + @override + String get pathSeparator => isWindows ? r'\' : '/'; } class MockProcess extends Mock implements io.Process { From 885a40732fec2b2393fd9c10e7d2c13d6ed8728c Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 5 Nov 2024 10:51:39 -0800 Subject: [PATCH 6/7] deletesync --- script/tool/lib/src/common/xcode.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index 24f36a002fd..1e01999533c 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -109,7 +109,7 @@ class Xcode { } return resultExit; } finally { - resultBundleTemp?.deleteSync(); + resultBundleTemp?.deleteSync(recursive: true); } } From a45f6345c07eb47965e2d71583dcbf4cfab56ab1 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 5 Nov 2024 16:06:05 -0800 Subject: [PATCH 7/7] New formatter --- script/tool/lib/src/common/xcode.dart | 27 +++++++++---------- .../tool/lib/src/drive_examples_command.dart | 11 ++++---- script/tool/lib/src/native_test_command.dart | 3 ++- .../test/drive_examples_command_test.dart | 4 +-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index 1e01999533c..7ba23fc000d 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -49,11 +49,9 @@ class Xcode { Directory? resultBundleTemp; try { if (logsDirectory != null) { - resultBundleTemp = fileSystem.systemTempDirectory - .createTempSync('flutter_xcresult.'); - resultBundlePath = resultBundleTemp - .childDirectory('result') - .path; + resultBundleTemp = + fileSystem.systemTempDirectory.createTempSync('flutter_xcresult.'); + resultBundlePath = resultBundleTemp.childDirectory('result').path; } File? disabledSandboxEntitlementFile; if (actions.contains('test') && targetPlatform.toLowerCase() == 'macos') { @@ -67,8 +65,10 @@ class Xcode { ...actions, ...['-workspace', workspace], ...['-scheme', scheme], - if (resultBundlePath != null) - ...['-resultBundlePath', resultBundlePath], + if (resultBundlePath != null) ...[ + '-resultBundlePath', + resultBundlePath + ], if (configuration != null) ...['-configuration', configuration], ...extraFlags, if (disabledSandboxEntitlementFile != null) @@ -78,13 +78,12 @@ class Xcode { if (log) { print(completeTestCommand); } - final int resultExit = await processRunner.runAndStream( - _xcRunCommand, args, - workingDir: exampleDirectory); + final int resultExit = await processRunner + .runAndStream(_xcRunCommand, args, workingDir: exampleDirectory); if (resultExit != 0 && resultBundleTemp != null) { - final Directory xcresultBundle = resultBundleTemp.childDirectory( - 'result.xcresult'); + final Directory xcresultBundle = + resultBundleTemp.childDirectory('result.xcresult'); if (logsDirectory != null) { if (xcresultBundle.existsSync()) { // Zip the test results to the artifacts directory for upload. @@ -102,8 +101,8 @@ class Xcode { workingDir: resultBundleTemp, ); } else { - print('xcresult bundle ${xcresultBundle - .path} does not exist, skipping upload'); + print( + 'xcresult bundle ${xcresultBundle.path} does not exist, skipping upload'); } } } diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index 3b2e317b55c..8ae12485602 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -387,8 +387,9 @@ class DriveExamplesCommand extends PackageLoopingCommand { final String enableExperiment = getStringArg(kEnableExperiment); final String screenshotBasename = '${exampleName.replaceAll(platform.pathSeparator, '_')}-drive'; - final Directory? screenshotDirectory = ciLogsDirectory(platform, driver.fileSystem) - ?.childDirectory(screenshotBasename); + final Directory? screenshotDirectory = + ciLogsDirectory(platform, driver.fileSystem) + ?.childDirectory(screenshotBasename); for (final File target in targets) { final int exitCode = await processRunner.runAndStream( @@ -427,7 +428,8 @@ class DriveExamplesCommand extends PackageLoopingCommand { required List testFiles, }) async { final String enableExperiment = getStringArg(kEnableExperiment); - final Directory? logsDirectory = ciLogsDirectory(platform, testFiles.first.fileSystem); + final Directory? logsDirectory = + ciLogsDirectory(platform, testFiles.first.fileSystem); // Workaround for https://github.com/flutter/flutter/issues/135673 // Once that is fixed on stable, this logic can be removed and the command @@ -450,8 +452,7 @@ class DriveExamplesCommand extends PackageLoopingCommand { ...deviceFlags, if (enableExperiment.isNotEmpty) '--enable-experiment=$enableExperiment', - if (logsDirectory != null) - '--debug-logs-dir=${logsDirectory.path}', + if (logsDirectory != null) '--debug-logs-dir=${logsDirectory.path}', target, ], workingDir: example.directory); diff --git a/script/tool/lib/src/native_test_command.dart b/script/tool/lib/src/native_test_command.dart index 9329578697c..47fd5799876 100644 --- a/script/tool/lib/src/native_test_command.dart +++ b/script/tool/lib/src/native_test_command.dart @@ -497,7 +497,8 @@ this command. case xcodebuildNoTestExitCode: _printNoExampleTestsMessage(example, targetPlatform); case 0: - printSuccess('Successfully ran $targetPlatform xctest for $exampleName'); + printSuccess( + 'Successfully ran $targetPlatform xctest for $exampleName'); // If this is the first test, assume success until something fails. if (overallResult == RunState.skipped) { overallResult = RunState.succeeded; diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index 5505db2bfe7..a1d48865bc4 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -309,7 +309,7 @@ void main() { setMockFlutterDevicesOutput(); final List output = - await runCapturingPrint(runner, ['drive-examples', '--ios']); + await runCapturingPrint(runner, ['drive-examples', '--ios']); expect( output, @@ -1552,7 +1552,7 @@ void main() { mockPlatform.environment.remove('FLUTTER_LOGS_DIR'); final RepositoryPackage package = - createFakePackage('a_package', packagesDir, extraFiles: [ + createFakePackage('a_package', packagesDir, extraFiles: [ 'example/integration_test/foo_test.dart', 'example/test_driver/integration_test.dart', 'example/web/index.html',