[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 <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Paul Berry
2026-06-01 18:04:45 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent d7f200b97d
commit 3186c708a2
13 changed files with 27 additions and 26 deletions
+2
View File
@@ -11,6 +11,8 @@ analyzer:
linter: linter:
rules: rules:
- unnecessary_type_name_in_constructor
- unnecessary_const_in_enum_constructor
- always_declare_return_types - always_declare_return_types
- avoid_void_async - avoid_void_async
- lines_longer_than_80_chars - lines_longer_than_80_chars
+4 -5
View File
@@ -28,7 +28,7 @@ class Analyze extends Suite {
final List<String>? gitGrepPatterns; final List<String>? gitGrepPatterns;
Analyze( new(
this.analysisOptions, this.analysisOptions,
this.uris, this.uris,
this.exclude, this.exclude,
@@ -114,7 +114,7 @@ class AnalyzerDiagnostic {
static final Pattern unescapePattern = RegExp(r"\\(.)"); static final Pattern unescapePattern = RegExp(r"\\(.)");
AnalyzerDiagnostic( new(
this.kind, this.kind,
this.detailedKind, this.detailedKind,
this.code, this.code,
@@ -125,10 +125,9 @@ class AnalyzerDiagnostic {
this.message, this.message,
); );
AnalyzerDiagnostic.malformed(String line) new malformed(String line) : this(null, null, null, null, -1, -1, -1, line);
: this(null, null, null, null, -1, -1, -1, line);
factory AnalyzerDiagnostic.fromLine(String line) { factory fromLine(String line) {
List<String> parts = <String>[]; List<String> parts = <String>[];
int start = 0; int start = 0;
int index = line.indexOf(potentialSplitPattern); int index = line.indexOf(potentialSplitPattern);
+8 -8
View File
@@ -36,7 +36,7 @@ class Chain extends Suite {
final List<String> excludeContains; final List<String> excludeContains;
final List<String> excludeEndsWith; final List<String> excludeEndsWith;
Chain( new(
String name, String name,
String kind, String kind,
this.source, this.source,
@@ -50,7 +50,7 @@ class Chain extends Suite {
this.excludeEndsWith, this.excludeEndsWith,
) : super(name, kind, statusFile); ) : 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"]); Uri source = base.resolve(json["source"]);
String root = json["root"]; String root = json["root"];
if (!root.endsWith("/")) { if (!root.endsWith("/")) {
@@ -138,7 +138,7 @@ class Chain extends Suite {
} }
abstract class ChainContext { abstract class ChainContext {
const ChainContext(); const new();
List<Step> get steps; List<Step> get steps;
@@ -403,7 +403,7 @@ abstract class ChainContext {
} }
abstract class Step<I, O, C extends ChainContext> { abstract class Step<I, O, C extends ChainContext> {
const Step(); const new();
String get name; String get name;
@@ -467,7 +467,7 @@ class Result<O> {
/// ///
final bool canBeFixWithUpdateExpectations; final bool canBeFixWithUpdateExpectations;
Result( new(
this.output, this.output,
this.outcome, this.outcome,
this.error, { this.error, {
@@ -476,12 +476,12 @@ class Result<O> {
this.canBeFixWithUpdateExpectations = false, 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); : 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); : this(output, Expectation.fail, error, trace: trace);
bool get isPass => outcome == Expectation.pass; bool get isPass => outcome == Expectation.pass;
+3 -3
View File
@@ -30,7 +30,7 @@ class Expectation {
final ExpectationGroup group; 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 /// Returns the canonical expectation representing [group]. That is, one of
/// the above expectations (except for `Meta` which returns `this`). /// the above expectations (except for `Meta` which returns `this`).
@@ -78,14 +78,14 @@ class ExpectationSet {
final Map<String, Expectation> internalMap; final Map<String, Expectation> internalMap;
const ExpectationSet(this.internalMap); const new(this.internalMap);
Expectation operator [](String name) { Expectation operator [](String name) {
return internalMap[name.toLowerCase()] ?? return internalMap[name.toLowerCase()] ??
(throw "No expectation named: '$name'."); (throw "No expectation named: '$name'.");
} }
factory ExpectationSet.fromJsonList(List data) { factory fromJsonList(List data) {
Map<String, Expectation> internalMap = Map<String, Expectation>.from( Map<String, Expectation> internalMap = Map<String, Expectation>.from(
defaultExpectations.internalMap, defaultExpectations.internalMap,
); );
+1 -1
View File
@@ -106,7 +106,7 @@ abstract class Logger {
} }
class StdoutLogger implements Logger { class StdoutLogger implements Logger {
const StdoutLogger(); const new();
@override @override
void logTestStart( void logTestStart(
+1 -1
View File
@@ -171,7 +171,7 @@ class SuiteRunner {
final List<Uri> testUris = <Uri>[]; final List<Uri> testUris = <Uri>[];
SuiteRunner( new(
this.suites, this.suites,
this.environment, this.environment,
Iterable<String> selectors, Iterable<String> selectors,
+1 -1
View File
@@ -26,7 +26,7 @@ class CommandLine {
final Set<String> options; final Set<String> options;
final List<String> arguments; final List<String> arguments;
CommandLine(this.options, this.arguments); new(this.options, this.arguments);
bool get verbose => options.contains("--verbose") || options.contains("-v"); bool get verbose => options.contains("--verbose") || options.contains("-v");
+1 -1
View File
@@ -52,7 +52,7 @@ class TestExpectations {
final ExpectationSet expectationSet; final ExpectationSet expectationSet;
final Map<String, Set<Expectation>> _map = {}; final Map<String, Set<Expectation>> _map = {};
TestExpectations(this.expectationSet); new(this.expectationSet);
void add(String name, List<String> allowedStatus) { void add(String name, List<String> allowedStatus) {
Set<Expectation> expectations = (_map[name] ??= {}); Set<Expectation> expectations = (_map[name] ??= {});
+1 -1
View File
@@ -21,7 +21,7 @@ class StdioProcess {
final String output; final String output;
StdioProcess(this.exitCode, this.output); new(this.exitCode, this.output);
Result<int> toResult({int expected = 0}) { Result<int> toResult({int expected = 0}) {
if (exitCode == expected) { if (exitCode == expected) {
+2 -2
View File
@@ -14,9 +14,9 @@ abstract class Suite {
final Uri? statusFile; 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 kind = json["kind"].toLowerCase();
String name = json["name"]; String name = json["name"];
switch (kind) { switch (kind) {
+1 -1
View File
@@ -19,7 +19,7 @@ class FileBasedTestDescription extends TestDescription {
final Uri root; final Uri root;
final File file; final File file;
FileBasedTestDescription(this.root, this.file); new(this.root, this.file);
@override @override
Uri get uri => file.uri; Uri get uri => file.uri;
+1 -1
View File
@@ -47,7 +47,7 @@ class TestRoot {
final List<Suite> suites; final List<Suite> suites;
TestRoot(this.packages, this.suites); new(this.packages, this.suites);
Analyze get analyze => suites.last as Analyze; Analyze get analyze => suites.last as Analyze;
+1 -1
View File
@@ -5,7 +5,7 @@ name: testing
publish_to: none publish_to: none
environment: environment:
sdk: '^3.12.0-0' sdk: '^3.13.0-0'
resolution: workspace resolution: workspace