From 3186c708a247f92a458446bcdfe15449264b69cd Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 1 Jun 2026 18:04:45 -0700 Subject: [PATCH] [testing] Migrate to new constructor decl syntax. (Part of https://github.com/dart-lang/sdk/issues/63288) This change migrates the testing package to use the new constructor declaration syntax, described in https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations. This change was performed in an automated fashion, by (a) bumping the package's SDK constraint to `3.13.0-0`, (b) enabling the lints `unnecessary_type_name_in_constructor` and `unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint failures using `dart fix`, and then (d) reformatting the affected files. To ease code review, I've reverted unrelated formatting changes. Change-Id: I01dab822f08d804d5c7ce997dee6d7866a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508427 Commit-Queue: Paul Berry Reviewed-by: Konstantin Shcheglov --- pkg/testing/analysis_options.yaml | 2 ++ pkg/testing/lib/src/analyze.dart | 9 ++++----- pkg/testing/lib/src/chain.dart | 16 ++++++++-------- pkg/testing/lib/src/expectation.dart | 6 +++--- pkg/testing/lib/src/log.dart | 2 +- pkg/testing/lib/src/run.dart | 2 +- pkg/testing/lib/src/run_tests.dart | 2 +- pkg/testing/lib/src/status_file_parser.dart | 2 +- pkg/testing/lib/src/stdio_process.dart | 2 +- pkg/testing/lib/src/suite.dart | 4 ++-- pkg/testing/lib/src/test_description.dart | 2 +- pkg/testing/lib/src/test_root.dart | 2 +- pkg/testing/pubspec.yaml | 2 +- 13 files changed, 27 insertions(+), 26 deletions(-) diff --git a/pkg/testing/analysis_options.yaml b/pkg/testing/analysis_options.yaml index d37843c43be..799a81e8769 100644 --- a/pkg/testing/analysis_options.yaml +++ b/pkg/testing/analysis_options.yaml @@ -11,6 +11,8 @@ analyzer: linter: rules: + - unnecessary_type_name_in_constructor + - unnecessary_const_in_enum_constructor - always_declare_return_types - avoid_void_async - lines_longer_than_80_chars diff --git a/pkg/testing/lib/src/analyze.dart b/pkg/testing/lib/src/analyze.dart index 46a1a045727..0400c89af94 100644 --- a/pkg/testing/lib/src/analyze.dart +++ b/pkg/testing/lib/src/analyze.dart @@ -28,7 +28,7 @@ class Analyze extends Suite { final List? gitGrepPatterns; - Analyze( + new( this.analysisOptions, this.uris, this.exclude, @@ -114,7 +114,7 @@ class AnalyzerDiagnostic { static final Pattern unescapePattern = RegExp(r"\\(.)"); - AnalyzerDiagnostic( + new( this.kind, this.detailedKind, this.code, @@ -125,10 +125,9 @@ class AnalyzerDiagnostic { this.message, ); - AnalyzerDiagnostic.malformed(String line) - : this(null, null, null, null, -1, -1, -1, line); + new malformed(String line) : this(null, null, null, null, -1, -1, -1, line); - factory AnalyzerDiagnostic.fromLine(String line) { + factory fromLine(String line) { List parts = []; int start = 0; int index = line.indexOf(potentialSplitPattern); diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index e5c74e7dab9..db8cbaf8bd6 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -36,7 +36,7 @@ class Chain extends Suite { final List excludeContains; final List excludeEndsWith; - Chain( + new( String name, String kind, this.source, @@ -50,7 +50,7 @@ class Chain extends Suite { this.excludeEndsWith, ) : super(name, kind, statusFile); - factory Chain.fromJsonMap(Uri base, Map json, String name, String kind) { + factory fromJsonMap(Uri base, Map json, String name, String kind) { Uri source = base.resolve(json["source"]); String root = json["root"]; if (!root.endsWith("/")) { @@ -138,7 +138,7 @@ class Chain extends Suite { } abstract class ChainContext { - const ChainContext(); + const new(); List get steps; @@ -403,7 +403,7 @@ abstract class ChainContext { } abstract class Step { - const Step(); + const new(); String get name; @@ -467,7 +467,7 @@ class Result { /// final bool canBeFixWithUpdateExpectations; - Result( + new( this.output, this.outcome, this.error, { @@ -476,12 +476,12 @@ class Result { this.canBeFixWithUpdateExpectations = false, }); - Result.pass(O output) : this(output, Expectation.pass, null); + new pass(O output) : this(output, Expectation.pass, null); - Result.crash(Object? error, StackTrace trace) + new crash(Object? error, StackTrace trace) : this(null, Expectation.crash, error, trace: trace); - Result.fail(O output, [error, StackTrace? trace]) + new fail(O output, [error, StackTrace? trace]) : this(output, Expectation.fail, error, trace: trace); bool get isPass => outcome == Expectation.pass; diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart index 994c7ecf817..329b87e006b 100644 --- a/pkg/testing/lib/src/expectation.dart +++ b/pkg/testing/lib/src/expectation.dart @@ -30,7 +30,7 @@ class Expectation { final ExpectationGroup group; - const Expectation(this.name, this.group); + const new(this.name, this.group); /// Returns the canonical expectation representing [group]. That is, one of /// the above expectations (except for `Meta` which returns `this`). @@ -78,14 +78,14 @@ class ExpectationSet { final Map internalMap; - const ExpectationSet(this.internalMap); + const new(this.internalMap); Expectation operator [](String name) { return internalMap[name.toLowerCase()] ?? (throw "No expectation named: '$name'."); } - factory ExpectationSet.fromJsonList(List data) { + factory fromJsonList(List data) { Map internalMap = Map.from( defaultExpectations.internalMap, ); diff --git a/pkg/testing/lib/src/log.dart b/pkg/testing/lib/src/log.dart index 5013557fbd3..b72fe5e3b6c 100644 --- a/pkg/testing/lib/src/log.dart +++ b/pkg/testing/lib/src/log.dart @@ -106,7 +106,7 @@ abstract class Logger { } class StdoutLogger implements Logger { - const StdoutLogger(); + const new(); @override void logTestStart( diff --git a/pkg/testing/lib/src/run.dart b/pkg/testing/lib/src/run.dart index f3c998f35ee..9e044440e18 100644 --- a/pkg/testing/lib/src/run.dart +++ b/pkg/testing/lib/src/run.dart @@ -171,7 +171,7 @@ class SuiteRunner { final List testUris = []; - SuiteRunner( + new( this.suites, this.environment, Iterable selectors, diff --git a/pkg/testing/lib/src/run_tests.dart b/pkg/testing/lib/src/run_tests.dart index 9447bec70ad..5383a096165 100644 --- a/pkg/testing/lib/src/run_tests.dart +++ b/pkg/testing/lib/src/run_tests.dart @@ -26,7 +26,7 @@ class CommandLine { final Set options; final List arguments; - CommandLine(this.options, this.arguments); + new(this.options, this.arguments); bool get verbose => options.contains("--verbose") || options.contains("-v"); diff --git a/pkg/testing/lib/src/status_file_parser.dart b/pkg/testing/lib/src/status_file_parser.dart index 2afd1374c24..ba156338fbd 100644 --- a/pkg/testing/lib/src/status_file_parser.dart +++ b/pkg/testing/lib/src/status_file_parser.dart @@ -52,7 +52,7 @@ class TestExpectations { final ExpectationSet expectationSet; final Map> _map = {}; - TestExpectations(this.expectationSet); + new(this.expectationSet); void add(String name, List allowedStatus) { Set expectations = (_map[name] ??= {}); diff --git a/pkg/testing/lib/src/stdio_process.dart b/pkg/testing/lib/src/stdio_process.dart index 1bed1c14912..2e3fe5e83bc 100644 --- a/pkg/testing/lib/src/stdio_process.dart +++ b/pkg/testing/lib/src/stdio_process.dart @@ -21,7 +21,7 @@ class StdioProcess { final String output; - StdioProcess(this.exitCode, this.output); + new(this.exitCode, this.output); Result toResult({int expected = 0}) { if (exitCode == expected) { diff --git a/pkg/testing/lib/src/suite.dart b/pkg/testing/lib/src/suite.dart index 8aa37ad1882..b65322bde4d 100644 --- a/pkg/testing/lib/src/suite.dart +++ b/pkg/testing/lib/src/suite.dart @@ -14,9 +14,9 @@ abstract class Suite { final Uri? statusFile; - Suite(this.name, this.kind, this.statusFile); + new(this.name, this.kind, this.statusFile); - factory Suite.fromJsonMap(Uri base, Map json) { + factory fromJsonMap(Uri base, Map json) { String kind = json["kind"].toLowerCase(); String name = json["name"]; switch (kind) { diff --git a/pkg/testing/lib/src/test_description.dart b/pkg/testing/lib/src/test_description.dart index 8dec54b8ec2..c4395ef82c2 100644 --- a/pkg/testing/lib/src/test_description.dart +++ b/pkg/testing/lib/src/test_description.dart @@ -19,7 +19,7 @@ class FileBasedTestDescription extends TestDescription { final Uri root; final File file; - FileBasedTestDescription(this.root, this.file); + new(this.root, this.file); @override Uri get uri => file.uri; diff --git a/pkg/testing/lib/src/test_root.dart b/pkg/testing/lib/src/test_root.dart index 5773ff07c9a..be104cece14 100644 --- a/pkg/testing/lib/src/test_root.dart +++ b/pkg/testing/lib/src/test_root.dart @@ -47,7 +47,7 @@ class TestRoot { final List suites; - TestRoot(this.packages, this.suites); + new(this.packages, this.suites); Analyze get analyze => suites.last as Analyze; diff --git a/pkg/testing/pubspec.yaml b/pkg/testing/pubspec.yaml index 131abb09b69..9f04e21ff11 100644 --- a/pkg/testing/pubspec.yaml +++ b/pkg/testing/pubspec.yaml @@ -5,7 +5,7 @@ name: testing publish_to: none environment: - sdk: '^3.12.0-0' + sdk: '^3.13.0-0' resolution: workspace