diff --git a/packages/flutter_tools/dart_test.yaml b/packages/flutter_tools/dart_test.yaml index f437c0fdb2..c4e8817b63 100644 --- a/packages/flutter_tools/dart_test.yaml +++ b/packages/flutter_tools/dart_test.yaml @@ -16,3 +16,9 @@ tags: # the --test-randomize-ordering-seed for the suites that have this tag. no-shuffle: allow_test_randomization: false + + # Tests that invoke `flutter build apk` for integration. + flutter-build-apk: {} + + # Tests that invoke `flutter test ...` or `flutter run ...` for integration. + flutter-test-driver: {} diff --git a/packages/flutter_tools/test/integration.shard/background_isolate_test.dart b/packages/flutter_tools/test/integration.shard/background_isolate_test.dart index eef89db5fc..aa92825a2d 100644 --- a/packages/flutter_tools/test/integration.shard/background_isolate_test.dart +++ b/packages/flutter_tools/test/integration.shard/background_isolate_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/break_on_framework_exceptions_test.dart b/packages/flutter_tools/test/integration.shard/break_on_framework_exceptions_test.dart index 8599d6230f..dd699b5a46 100644 --- a/packages/flutter_tools/test/integration.shard/break_on_framework_exceptions_test.dart +++ b/packages/flutter_tools/test/integration.shard/break_on_framework_exceptions_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/coverage_collection_test.dart b/packages/flutter_tools/test/integration.shard/coverage_collection_test.dart index 22a52a3a01..e14a5a2a47 100644 --- a/packages/flutter_tools/test/integration.shard/coverage_collection_test.dart +++ b/packages/flutter_tools/test/integration.shard/coverage_collection_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:file_testing/file_testing.dart'; diff --git a/packages/flutter_tools/test/integration.shard/debugger_stepping_test.dart b/packages/flutter_tools/test/integration.shard/debugger_stepping_test.dart index 652ca84875..09ef630e47 100644 --- a/packages/flutter_tools/test/integration.shard/debugger_stepping_test.dart +++ b/packages/flutter_tools/test/integration.shard/debugger_stepping_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import '../src/common.dart'; diff --git a/packages/flutter_tools/test/integration.shard/deferred_components_test.dart b/packages/flutter_tools/test/integration.shard/deferred_components_test.dart index 0402e8d4d7..8f82cab078 100644 --- a/packages/flutter_tools/test/integration.shard/deferred_components_test.dart +++ b/packages/flutter_tools/test/integration.shard/deferred_components_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:archive/archive.dart'; import 'package:file/file.dart'; import 'package:file_testing/file_testing.dart'; diff --git a/packages/flutter_tools/test/integration.shard/flutter_attach_test.dart b/packages/flutter_tools/test/integration.shard/flutter_attach_test.dart index 1d92a7a4b7..079b4908d0 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_attach_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_attach_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:convert'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/flutter_gen_test.dart b/packages/flutter_tools/test/integration.shard/flutter_gen_test.dart index 674d5a1c58..c9e9490089 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_gen_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_gen_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:convert'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/flutter_run_test.dart b/packages/flutter_tools/test/integration.shard/flutter_run_test.dart index bff3bae35c..345e3bdd80 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_run_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_run_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:process/process.dart'; diff --git a/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart b/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart index b980f1db82..84281150cb 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/gen_l10n_test.dart b/packages/flutter_tools/test/integration.shard/gen_l10n_test.dart index 268ec5e024..3567844e3d 100644 --- a/packages/flutter_tools/test/integration.shard/gen_l10n_test.dart +++ b/packages/flutter_tools/test/integration.shard/gen_l10n_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_errors_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_errors_test.dart index edddb6864b..966d2b558a 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_errors_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_errors_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import '../src/common.dart'; diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart index ca2d13b7fc..7a83d96208 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_with_asset_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_with_asset_test.dart index 4de27d074f..aca0f0e41b 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_with_asset_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_with_asset_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/lifetime_test.dart b/packages/flutter_tools/test/integration.shard/lifetime_test.dart index bab2ee3e9f..82a592a2b1 100644 --- a/packages/flutter_tools/test/integration.shard/lifetime_test.dart +++ b/packages/flutter_tools/test/integration.shard/lifetime_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import '../src/common.dart'; diff --git a/packages/flutter_tools/test/integration.shard/stateless_stateful_hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/stateless_stateful_hot_reload_test.dart index 21f911d192..5b7de6ad32 100644 --- a/packages/flutter_tools/test/integration.shard/stateless_stateful_hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/stateless_stateful_hot_reload_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/test_driver.dart b/packages/flutter_tools/test/integration.shard/test_driver.dart index 04941ba2e8..810680751f 100644 --- a/packages/flutter_tools/test/integration.shard/test_driver.dart +++ b/packages/flutter_tools/test/integration.shard/test_driver.dart @@ -10,6 +10,7 @@ import 'package:file/file.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/utils.dart'; +import 'package:meta/meta.dart'; import 'package:process/process.dart'; import 'package:vm_service/vm_service.dart'; import 'package:vm_service/vm_service_io.dart'; @@ -35,7 +36,7 @@ const Duration defaultTimeout = Duration(seconds: 5); const Duration appStartTimeout = Duration(seconds: 120); const Duration quitTimeout = Duration(seconds: 10); -abstract class FlutterTestDriver { +abstract final class FlutterTestDriver { FlutterTestDriver( this._projectFolder, { String? logPrefix, @@ -86,12 +87,17 @@ abstract class FlutterTestDriver { } } + @mustCallSuper Future _setupProcess( List arguments, { String? script, bool withDebugger = false, bool verbose = false, }) async { + if (_process != null && !_hasExited) { + throw StateError('Cannot start another process while the previous runs'); + } + if (withDebugger) { arguments.add('--start-paused'); } @@ -120,6 +126,9 @@ abstract class FlutterTestDriver { // via a getter for external uses. unawaited(_process!.exitCode.then((int code) { _debugPrint('Process exited ($code)'); + // The timing of this signal is important to the implementation of the + // "quit" method, so only change how this is implemented by careful + // testing of tests that use FlutterTestDriver. _hasExited = true; })); transformToLines(_process!.stdout).listen(_stdout.add); @@ -183,8 +192,24 @@ abstract class FlutterTestDriver { ); } - Future quit() => _killGracefully(); + /// Quits the currently running process. + @nonVirtual + Future quit() async { + final int result = await _killGracefully(); + if (result != 0) { + _debugPrint('Expected process to terminate gracefully, got exit code $result.'); + } + // The _hasExited signal could be on the microtask queue. Waiting for a + // Future(...) queues an event similar to Timer.run(Duration.zero), which + // guarantees the current queue has elapsed before moving on. + await Future(() {}); + if (!_hasExited) { + throw StateError('Process did not exit'); + } + } + + @nonVirtual Future _killGracefully() async { if (_processPid == null) { return -1; @@ -484,7 +509,7 @@ abstract class FlutterTestDriver { } } -class FlutterRunTestDriver extends FlutterTestDriver { +final class FlutterRunTestDriver extends FlutterTestDriver { FlutterRunTestDriver( super.projectFolder, { super.logPrefix, @@ -770,7 +795,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { final bool spawnDdsInstance; } -class FlutterTestTestDriver extends FlutterTestDriver { +final class FlutterTestTestDriver extends FlutterTestDriver { FlutterTestTestDriver(super.projectFolder, {super.logPrefix}); Future test({ diff --git a/packages/flutter_tools/test/integration.shard/timeline_test.dart b/packages/flutter_tools/test/integration.shard/timeline_test.dart index d2344c00bb..61ba301b79 100644 --- a/packages/flutter_tools/test/integration.shard/timeline_test.dart +++ b/packages/flutter_tools/test/integration.shard/timeline_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart index ab66ed3d46..0defcf44ce 100644 --- a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart +++ b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:vm_service/vm_service.dart'; diff --git a/packages/flutter_tools/test/web.shard/debugger_stepping_web_test.dart b/packages/flutter_tools/test/web.shard/debugger_stepping_web_test.dart index 0663bb6da3..6631eae825 100644 --- a/packages/flutter_tools/test/web.shard/debugger_stepping_web_test.dart +++ b/packages/flutter_tools/test/web.shard/debugger_stepping_web_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import '../integration.shard/test_data/stepping_project.dart'; diff --git a/packages/flutter_tools/test/web.shard/expression_evaluation_web_test.dart b/packages/flutter_tools/test/web.shard/expression_evaluation_web_test.dart index 737f5e7d4d..de8283a4ac 100644 --- a/packages/flutter_tools/test/web.shard/expression_evaluation_web_test.dart +++ b/packages/flutter_tools/test/web.shard/expression_evaluation_web_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:vm_service/vm_service.dart'; diff --git a/packages/flutter_tools/test/web.shard/hot_reload_web_test.dart b/packages/flutter_tools/test/web.shard/hot_reload_web_test.dart index 6999255b02..7648634299 100644 --- a/packages/flutter_tools/test/web.shard/hot_reload_web_test.dart +++ b/packages/flutter_tools/test/web.shard/hot_reload_web_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/web.shard/output_web_test.dart b/packages/flutter_tools/test/web.shard/output_web_test.dart index 65dd60f9e5..a820eb1dd7 100644 --- a/packages/flutter_tools/test/web.shard/output_web_test.dart +++ b/packages/flutter_tools/test/web.shard/output_web_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:vm_service/vm_service.dart'; diff --git a/packages/flutter_tools/test/web.shard/vm_service_web_test.dart b/packages/flutter_tools/test/web.shard/vm_service_web_test.dart index 5dd5a0bde4..d13ec6f404 100644 --- a/packages/flutter_tools/test/web.shard/vm_service_web_test.dart +++ b/packages/flutter_tools/test/web.shard/vm_service_web_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'dart:async'; import 'package:file/file.dart'; diff --git a/packages/flutter_tools/test/web.shard/web_run_test.dart b/packages/flutter_tools/test/web.shard/web_run_test.dart index c9c8227051..82a82242e2 100644 --- a/packages/flutter_tools/test/web.shard/web_run_test.dart +++ b/packages/flutter_tools/test/web.shard/web_run_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@Tags(['flutter-test-driver']) +library; + import 'package:file/file.dart'; import 'package:flutter_tools/src/base/file_system.dart';