From a65a0693e0819dd6f1f36561a4f3a1f0e2ae6fd8 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 27 Aug 2024 00:56:32 +0000 Subject: [PATCH 1/3] Remove the Pair utility Use record types. --- pkgs/test_core/lib/src/runner/load_suite.dart | 15 ++++++------ .../lib/src/runner/parse_metadata.dart | 8 +++---- pkgs/test_core/lib/src/util/pair.dart | 23 ------------------- 3 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 pkgs/test_core/lib/src/util/pair.dart diff --git a/pkgs/test_core/lib/src/runner/load_suite.dart b/pkgs/test_core/lib/src/runner/load_suite.dart index 550881e0c..a618705b9 100644 --- a/pkgs/test_core/lib/src/runner/load_suite.dart +++ b/pkgs/test_core/lib/src/runner/load_suite.dart @@ -15,7 +15,6 @@ import 'package:test_api/src/backend/suite_platform.dart'; // ignore: implementa import 'package:test_api/src/backend/test.dart'; // ignore: implementation_imports import '../util/io_stub.dart' if (dart.library.io) '../util/io.dart'; -import '../util/pair.dart'; import 'load_exception.dart'; import 'plugin/environment.dart'; import 'runner_suite.dart'; @@ -61,13 +60,13 @@ class LoadSuite extends Suite implements RunnerSuite { /// /// This will return `null` if the suite is unavailable for some reason (for /// example if an error occurred while loading it). - Future get suite async => (await _suiteAndZone)?.first; + Future get suite async => (await _suiteAndZone)?.$1; /// A future that completes to a pair of [suite] and the load test's [Zone]. /// /// This will return `null` if the suite is unavailable for some reason (for /// example if an error occurred while loading it). - final Future?> _suiteAndZone; + final Future<(RunnerSuite, Zone)?> _suiteAndZone; /// Returns the test that loads the suite. /// @@ -86,7 +85,7 @@ class LoadSuite extends Suite implements RunnerSuite { factory LoadSuite(String name, SuiteConfiguration config, SuitePlatform platform, FutureOr Function() body, {String? path}) { - var completer = Completer?>.sync(); + var completer = Completer<(RunnerSuite, Zone)?>.sync(); return LoadSuite._(name, config, platform, () { var invoker = Invoker.current; invoker!.addOutstandingCallback(); @@ -106,7 +105,7 @@ class LoadSuite extends Suite implements RunnerSuite { return; } - completer.complete(suite == null ? null : Pair(suite, Zone.current)); + completer.complete(suite == null ? null : (suite, Zone.current)); invoker.removeOutstandingCallback(); }()); @@ -179,12 +178,12 @@ class LoadSuite extends Suite implements RunnerSuite { return LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { if (pair == null) return null; - var zone = pair.last; + var (suite, zone) = pair; RunnerSuite? newSuite; zone.runGuarded(() { - newSuite = change(pair.first); + newSuite = change(suite); }); - return newSuite == null ? null : Pair(newSuite!, zone); + return newSuite == null ? null : (newSuite!, zone); })); } diff --git a/pkgs/test_core/lib/src/runner/parse_metadata.dart b/pkgs/test_core/lib/src/runner/parse_metadata.dart index 63b5e59c8..fd2b5ee0b 100644 --- a/pkgs/test_core/lib/src/runner/parse_metadata.dart +++ b/pkgs/test_core/lib/src/runner/parse_metadata.dart @@ -12,7 +12,6 @@ import 'package:test_api/src/backend/platform_selector.dart'; // ignore: impleme import 'package:test_api/src/backend/util/identifier_regex.dart'; // ignore: implementation_imports import '../util/dart.dart'; -import '../util/pair.dart'; /// Parse the test metadata for the test file at [path] with [contents]. /// @@ -80,8 +79,7 @@ class _Parser { for (var annotation in _annotations) { var pair = _resolveConstructor(annotation.name, annotation.constructorName); - var name = pair.first; - var constructorName = pair.last; + var (name, constructorName) = pair; if (name == 'TestOn') { _assertSingle(testOn, 'TestOn', annotation); @@ -309,7 +307,7 @@ class _Parser { /// /// Since the parsed file isn't fully resolved, this is necessary to /// disambiguate between prefixed names and named constructors. - Pair _resolveConstructor( + (String, String?) _resolveConstructor( Identifier identifier, SimpleIdentifier? constructorName) { // The syntax is ambiguous between named constructors and prefixed // annotations, so we need to resolve that ambiguity using the known @@ -329,7 +327,7 @@ class _Parser { : identifier.name; if (constructorName != null) namedConstructor = constructorName.name; } - return Pair(className, namedConstructor); + return (className, namedConstructor); } /// Parses a constructor invocation for [className]. diff --git a/pkgs/test_core/lib/src/util/pair.dart b/pkgs/test_core/lib/src/util/pair.dart deleted file mode 100644 index 89a3d14c1..000000000 --- a/pkgs/test_core/lib/src/util/pair.dart +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// A pair of values. -class Pair { - E first; - F last; - - Pair(this.first, this.last); - - @override - String toString() => '($first, $last)'; - - @override - bool operator ==(Object other) { - if (other is! Pair) return false; - return other.first == first && other.last == last; - } - - @override - int get hashCode => first.hashCode ^ last.hashCode; -} From 0042bbfc17820e56e5ab6045988f9e2d73995195 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 28 Aug 2024 00:56:32 +0000 Subject: [PATCH 2/3] Use a named field over $1 --- pkgs/test_core/lib/src/runner/load_suite.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/load_suite.dart b/pkgs/test_core/lib/src/runner/load_suite.dart index a618705b9..8ffd3075d 100644 --- a/pkgs/test_core/lib/src/runner/load_suite.dart +++ b/pkgs/test_core/lib/src/runner/load_suite.dart @@ -60,13 +60,13 @@ class LoadSuite extends Suite implements RunnerSuite { /// /// This will return `null` if the suite is unavailable for some reason (for /// example if an error occurred while loading it). - Future get suite async => (await _suiteAndZone)?.$1; + Future get suite async => (await _suiteAndZone)?.suite; /// A future that completes to a pair of [suite] and the load test's [Zone]. /// /// This will return `null` if the suite is unavailable for some reason (for /// example if an error occurred while loading it). - final Future<(RunnerSuite, Zone)?> _suiteAndZone; + final Future<(Zone, {RunnerSuite suite})?> _suiteAndZone; /// Returns the test that loads the suite. /// @@ -85,7 +85,7 @@ class LoadSuite extends Suite implements RunnerSuite { factory LoadSuite(String name, SuiteConfiguration config, SuitePlatform platform, FutureOr Function() body, {String? path}) { - var completer = Completer<(RunnerSuite, Zone)?>.sync(); + var completer = Completer<(Zone, {RunnerSuite suite})?>.sync(); return LoadSuite._(name, config, platform, () { var invoker = Invoker.current; invoker!.addOutstandingCallback(); @@ -105,7 +105,7 @@ class LoadSuite extends Suite implements RunnerSuite { return; } - completer.complete(suite == null ? null : (suite, Zone.current)); + completer.complete(suite == null ? null : (suite: suite, Zone.current)); invoker.removeOutstandingCallback(); }()); @@ -178,12 +178,12 @@ class LoadSuite extends Suite implements RunnerSuite { return LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { if (pair == null) return null; - var (suite, zone) = pair; + var (:suite, zone) = pair; RunnerSuite? newSuite; zone.runGuarded(() { newSuite = change(suite); }); - return newSuite == null ? null : (newSuite!, zone); + return newSuite == null ? null : (suite: newSuite!, zone); })); } From 04775609479ee029efd34a2f26edf3124c4ee8ed Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 28 Aug 2024 00:58:50 +0000 Subject: [PATCH 3/3] Both named --- pkgs/test_core/lib/src/runner/load_suite.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/load_suite.dart b/pkgs/test_core/lib/src/runner/load_suite.dart index 8ffd3075d..633739afc 100644 --- a/pkgs/test_core/lib/src/runner/load_suite.dart +++ b/pkgs/test_core/lib/src/runner/load_suite.dart @@ -66,7 +66,7 @@ class LoadSuite extends Suite implements RunnerSuite { /// /// This will return `null` if the suite is unavailable for some reason (for /// example if an error occurred while loading it). - final Future<(Zone, {RunnerSuite suite})?> _suiteAndZone; + final Future<({RunnerSuite suite, Zone zone})?> _suiteAndZone; /// Returns the test that loads the suite. /// @@ -85,7 +85,7 @@ class LoadSuite extends Suite implements RunnerSuite { factory LoadSuite(String name, SuiteConfiguration config, SuitePlatform platform, FutureOr Function() body, {String? path}) { - var completer = Completer<(Zone, {RunnerSuite suite})?>.sync(); + var completer = Completer<({RunnerSuite suite, Zone zone})?>.sync(); return LoadSuite._(name, config, platform, () { var invoker = Invoker.current; invoker!.addOutstandingCallback(); @@ -105,7 +105,8 @@ class LoadSuite extends Suite implements RunnerSuite { return; } - completer.complete(suite == null ? null : (suite: suite, Zone.current)); + completer.complete( + suite == null ? null : (suite: suite, zone: Zone.current)); invoker.removeOutstandingCallback(); }()); @@ -178,12 +179,12 @@ class LoadSuite extends Suite implements RunnerSuite { return LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { if (pair == null) return null; - var (:suite, zone) = pair; + var (:suite, :zone) = pair; RunnerSuite? newSuite; zone.runGuarded(() { newSuite = change(suite); }); - return newSuite == null ? null : (suite: newSuite!, zone); + return newSuite == null ? null : (suite: newSuite!, zone: zone); })); }