flutter/packages/flutter_tools/test/integration.shard
Nate Wilson 5ecf10052f
pattern-matching refactor (#154753)
This pull request aims to improve code readability, based on feedback gathered in a recent design doc.

<br>

There are two factors that hugely impact how easy it is to understand a piece of code: **verbosity** and **complexity**.

Reducing **verbosity** is important, because boilerplate makes a project more difficult to navigate. It also has a tendency to make one's eyes gloss over, and subtle typos/bugs become more likely to slip through.

Reducing **complexity** makes the code more accessible to more people. This is especially important for open-source projects like Flutter, where the code is read by those who make contributions, as well as others who read through source code as they debug their own projects.

<hr>

<br>

The following examples show how pattern-matching might affect these two factors:

<details> <summary><h3>Example 1 (GOOD)</h3> [click to expand]</summary>

```dart
if (ancestor case InheritedElement(:final InheritedTheme widget)) {
  themes.add(widget);
}
```

Without using patterns, this might expand to

```dart
if (ancestor is InheritedElement) {
  final InheritedWidget widget = ancestor.widget;
  if (widget is InheritedTheme) {
    themes.add(widget);
  }
}
```

Had `ancestor` been a non-local variable, it would need to be "converted" as well:

```dart
final Element ancestor = this.ancestor;
if (ancestor is InheritedElement) {
  final InheritedWidget inheritedWidget = ancestor.widget;
  if (widget is InheritedTheme) {
    themes.add(theme);
  }
}
```

</details>

<details> <summary><h3>Example 2 (BAD) </h3> [click to expand]</summary>

```dart
if (widget case PreferredSizeWidget(preferredSize: Size(:final double height))) {
  return height;
}
```

Assuming `widget` is a non-local variable, this would expand to:

```dart
final Widget widget = this.widget;
if (widget is PreferredSizeWidget) {
  return widget.preferredSize.height;
}
```

<br>

</details>

In both of the examples above, an `if-case` statement simultaneously verifies that an object meets the specified criteria and performs a variable assignment accordingly.

But there are some differences: Example 2 uses a more deeply-nested pattern than Example 1 but makes fewer useful checks.

**Example 1:**
- checks that `ancestor` is an `InheritedElement`
- checks that the inherited element's `widget` is an `InheritedTheme`

**Example 2:**
- checks that `widget` is a `PreferredSizeWidget`
(every `PreferredSizeWidget` has a `size` field, and every `Size` has a `height` field)

<br>

<hr>

I feel hesitant to try presenting a set of cut-and-dry rules as to which scenarios should/shouldn't use pattern-matching, since there are an abundance of different types of patterns, and an abundance of different places where they might be used.

But hopefully the conversations we've had recently will help us converge toward a common intuition of how pattern-matching can best be utilized for improved readability.

<br><br>

- resolves https://github.com/flutter/flutter/issues/152313
- Design Doc: [flutter.dev/go/dart-patterns](https://flutter.dev/go/dart-patterns)
2024-10-03 18:21:04 +00:00
..
debug_adapter [flutter_tools] Fix encoded stderr in "dart.log" from debug adapter to client (#155249) 2024-09-24 12:30:06 +01:00
isolated [native assets] Roll dependencies (#155432) 2024-09-24 07:19:09 +00:00
test_data Stop reading .packages from flutter_tools. (#154912) 2024-09-13 13:53:05 +02:00
analyze_all_templates_test.dart [flutter_tools] Use process matcher for multidex test (#127996) 2023-06-01 22:24:08 +00:00
analyze_once_test.dart Roll Flutter Engine from c58d87d62c20 to 31bb9f98472a (8 revisions) (#152555) 2024-07-30 16:42:10 +00:00
analyze_size_test.dart [flutter_tools] Use process matcher for multidex test (#127996) 2023-06-01 22:24:08 +00:00
analyze_suggestions_integration_test.dart [flutter_tools] cache flutter sdk version to disk (#124558) 2023-06-15 00:20:30 +00:00
android_e2e_api_test.dart [flutter_tools] Migrate more integration tests to process result matcher (#128737) 2023-06-15 13:25:32 -07:00
android_gradle_daemon_cache_test.dart Reland (2): "Fix how Gradle resolves Android plugin" (#142498) 2024-02-19 18:07:33 +00:00
android_gradle_deprecated_plugin_apply_test.dart Reland "Update template/test compileSdk, targetSdk, ndk versions" (#153795) 2024-08-21 18:27:00 +00:00
android_gradle_flutter_source_path_test.dart Set default flutter source directory for gradle builds (#142934) 2024-02-08 22:28:39 +00:00
android_gradle_java_version_test.dart [flutter_tools] Migrate more integration tests to process result matcher (#128737) 2023-06-15 13:25:32 -07:00
android_gradle_outputs_app_link_settings_test.dart Update the gradle task to add fallback scheme and host if needed when retrieving deep links. (#146470) 2024-04-11 14:24:51 -07:00
android_gradle_print_build_variants_test.dart Add vmservice for android build options (#123034) 2023-04-18 18:16:09 +00:00
android_plugin_compilesdkversion_mismatch_test.dart Improve Android SDK and NDK mistmatch warning message (#147809) 2024-05-07 15:11:00 +00:00
android_plugin_example_app_build_test.dart Restore log dumps for gradle OOM crashes, and set a value for MaxMetaspaceSize (#143085) 2024-02-07 19:25:39 +00:00
android_plugin_ndkversion_mismatch_test.dart Improve Android SDK and NDK mistmatch warning message (#147809) 2024-05-07 15:11:00 +00:00
android_plugin_new_output_dir_test.dart Change android_plugin_new_output_dir_test.dart test description (#149198) 2024-05-28 23:04:10 +00:00
android_plugin_skip_unsupported_test.dart Reland (2): "Fix how Gradle resolves Android plugin" (#142498) 2024-02-19 18:07:33 +00:00
asset_transformation_test.dart Add integration test for asset transformation feature (#145715) 2024-04-26 21:42:06 +00:00
background_isolate_test.dart
bash_entrypoint_test.dart [flutter_tools] do not try to build tool from dart.sh (#129186) 2023-11-03 00:42:25 +00:00
batch_entrypoint_test.dart [flutter_tools] print out the unzipping method used by update_dart_sdk.ps1 (#133364) 2023-08-31 21:06:47 +00:00
break_on_framework_exceptions_test.dart Eliminate more window singleton usages (#145560) 2024-03-21 20:59:25 +00:00
build_ios_config_only_test.dart [flutter_tools] Migrate more integration tests to process result matcher (#128737) 2023-06-15 13:25:32 -07:00
build_macos_config_only_test.dart Migrate more integration tests to process result matcher (#130994) 2023-07-20 21:02:12 +00:00
build_preview_test.dart [flutter_tools] move build_preview_test from commands/permeable to integration shard (#136912) 2023-10-19 22:03:04 +00:00
cache_test.dart Remove redundant arguments passed to redirecting factory constructors (#115497) 2022-11-17 00:47:14 +00:00
command_output_test.dart Stop reading .packages from flutter_tools. (#154912) 2024-09-13 13:53:05 +02:00
coverage_collection_test.dart
daemon_mode_test.dart
debugger_stepping_test.dart
deferred_components_test.dart Migrate more integration tests to process result matcher (#130994) 2023-07-20 21:02:12 +00:00
deprecated_gradle_settings_test.dart Fix implementation imports outside of lib (#143594) 2024-02-16 22:38:10 +00:00
devtools_uri_test.dart Reland "Fix issue where DevTools would not be immediately available when using --start-paused (#126698)" (#129368) 2023-06-28 00:16:13 +05:30
downgrade_upgrade_integration_test.dart [flutter_tools] Fix flutter upgrade not finding git tags (#133778) 2023-08-31 22:01:10 +00:00
exit_code_test.dart [flutter_tools] Migrate more integration tests to process result matcher (#128737) 2023-06-15 13:25:32 -07:00
expression_evaluation_test.dart Unskip expression evaluation test (#149253) 2024-05-29 23:24:36 +01:00
flutter_attach_test.dart Stop serving Observatory by default (#122419) 2023-03-23 12:52:30 -04:00
flutter_build_android_app_project_builddir_test.dart
flutter_build_apk_verbose_test.dart Update integration tests regexes. (#144847) 2024-03-12 01:31:25 +00:00
flutter_build_config_only_test.dart [flutter_tools] cache flutter sdk version to disk (#124558) 2023-06-15 00:20:30 +00:00
flutter_build_wasm_test.dart [flutter_tools] Enable WebAssembly compilation everywhere, remove feature flag (#145562) 2024-03-26 18:23:49 +00:00
flutter_build_windows_test.dart Enable native compilation for windows-arm64 (#141930) 2024-01-26 00:08:20 +00:00
flutter_build_with_compilation_error_test.dart Change flutter_build_with_compilation_error_test to check stdout or stderr (#152404) 2024-07-26 23:12:14 +00:00
flutter_gen_test.dart
flutter_run_test.dart [flutter_tools] Include mode in app.start event, and forward app.start to DAP clients (#121239) 2023-04-05 05:39:09 +00:00
flutter_run_with_error_test.dart Reland "Remove references to Observatory (#118577)" (#121606) 2023-02-28 11:57:04 -05:00
forbidden_imports_test.dart Revert "Allow Flutter golden file tests to be flaky (#114450)" (#114902) 2022-11-08 09:26:55 -08:00
gen_l10n_test.dart Gen l10n add named argument option (#138663) 2024-01-05 21:28:08 +00:00
gradle_non_android_plugin_test.dart [flutter_tools] Use process matcher for multidex test (#127996) 2023-06-01 22:24:08 +00:00
hot_reload_errors_test.dart
hot_reload_test.dart Do not cancel the VmService's subscription to the isolate event stream in FlutterVmService.findExtensionIsolate (#153607) 2024-08-19 17:40:07 +00:00
hot_reload_with_asset_test.dart
lifetime_test.dart
observatory_port_test.dart Add spaces after flow control statements (#126320) 2023-05-15 11:07:30 +02:00
overall_experience_test.dart [Reland] Introduce double Flex.spacing parameter for Row/Column spacing (#152890) 2024-08-05 23:04:50 +00:00
plist_parser_test.dart Add Swift Package Manager as new opt-in feature for iOS and macOS (#146256) 2024-04-18 21:12:36 +00:00
README.md Added missing code block language in docs (#147481) 2024-05-01 14:44:27 +00:00
shader_compiler_test.dart Avoid depending on files from build_system/targets other than from top level entrypoints in flutter_tools. (#142760) 2024-02-02 18:23:08 +00:00
stateless_stateful_hot_reload_test.dart Remove test that verifies we can switch to stateless (#120390) 2023-02-09 20:58:57 +00:00
swift_package_manager_create_app_test.dart Add create app and plugin templates for Swift Package Manager (#147082) 2024-04-24 22:46:20 +00:00
swift_package_manager_create_plugin_test.dart Add create app and plugin templates for Swift Package Manager (#147082) 2024-04-24 22:46:20 +00:00
swift_package_manager_test.dart Add test that app builds if migrated to SwiftPM but SwiftPM is turned off (#153800) 2024-08-21 22:18:05 +00:00
swift_package_manager_utils.dart [Swift Package Manager] Test removing the last Flutter plugin (#153519) 2024-08-16 14:03:13 +00:00
template_manifest_test.dart Simplify null check. (#117026) 2023-01-03 20:51:48 +00:00
test_driver.dart pattern-matching refactor (#154753) 2024-10-03 18:21:04 +00:00
test_test.dart Support using lightweight Flutter Engines to run tests (#141726) 2024-02-22 13:32:29 -05:00
test_utils.dart Stop reading .packages from flutter_tools. (#154912) 2024-09-13 13:53:05 +02:00
timeline_test.dart [flutter_tools] timeline_test.dart flaky (#116667) 2023-01-03 20:44:53 +00:00
tool_backend_test.dart Update flutter_tools/bin/*.(dart|sh) to provide, if set, --local-engine-host. (#132336) 2023-08-10 15:25:57 -07:00
transition_test_utils.dart Implementing switch expressions in flutter_tools/ (#145632) 2024-03-29 22:31:19 +00:00
unit_coverage_test.dart
variable_expansion_windows_test.dart
variable_expansion_windows.dart
vmservice_integration_test.dart add verbose logging to select hot reload/hot restart tests (#147673) 2024-05-02 04:03:32 +00:00
web_plugin_registrant_test.dart Migrate more integration tests to process result matcher (#130994) 2023-07-20 21:02:12 +00:00
xcode_backend_test.dart [Reland] Skip injecting Bonjour settings when port publication is disabled (#136842) 2023-10-19 17:38:52 +00:00

Integration tests

These tests are not hermetic, and use the actual Flutter SDK. While they don't require actual devices, they run flutter_tester to test Dart VM and Flutter integration.

Use this command to run (from the flutter_tools directory):

../../bin/cache/dart-sdk/bin/dart run test test/integration.shard

You need to have downloaded the Dart SDK in your Flutter clone for this to work. Running ../../bin/flutter will automatically download it.

Coverage exclusion

These tests are expensive to run and do not give meaningful coverage information for the flutter tool (since they are black-box tests that run the tool as a subprocess, rather than being unit tests). For this reason, they are in a separate shard when running on continuous integration and are not run when calculating coverage.

Adding new test files

When adding a new test file make sure that it ends with _test.dart, or else it will not be run.