diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 13301b65324..faad814af20 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -11,7 +11,7 @@ "constraint, update this by running tools/generate_package_config.dart." ], "configVersion": 2, - "generated": "2021-07-26T14:57:34.624319", + "generated": "2021-07-27T19:27:52.638315", "generator": "tools/generate_package_config.dart", "packages": [ { @@ -725,7 +725,7 @@ "name": "testing", "rootUri": "../pkg/testing", "packageUri": "lib/", - "languageVersion": "2.0" + "languageVersion": "2.12" }, { "name": "typed_data", diff --git a/pkg/testing/lib/src/analyze.dart b/pkg/testing/lib/src/analyze.dart index 099d020c453..05009ecbe93 100644 --- a/pkg/testing/lib/src/analyze.dart +++ b/pkg/testing/lib/src/analyze.dart @@ -18,21 +18,21 @@ import 'log.dart' show isVerbose, splitLines; import 'suite.dart' show Suite; class Analyze extends Suite { - final Uri analysisOptions; + final Uri? analysisOptions; final List uris; final List exclude; - final List gitGrepPathspecs; + final List? gitGrepPathspecs; - final List gitGrepPatterns; + final List? gitGrepPatterns; Analyze(this.analysisOptions, this.uris, this.exclude, this.gitGrepPathspecs, this.gitGrepPatterns) : super("analyze", "analyze", null); - Future run(Uri packages, List extraUris) { + Future run(Uri packages, List? extraUris) { List allUris = new List.from(uris); if (extraUris != null) { allUris.addAll(extraUris); @@ -43,8 +43,8 @@ class Analyze extends Suite { static Future fromJsonMap( Uri base, Map json, List suites) async { - String optionsPath = json["options"]; - Uri optionsUri = optionsPath == null ? null : base.resolve(optionsPath); + String? optionsPath = json["options"]; + Uri? optionsUri = optionsPath == null ? null : base.resolve(optionsPath); List uris = json["uris"].map((relative) { String r = relative; @@ -54,9 +54,9 @@ class Analyze extends Suite { List exclude = json["exclude"].map((p) => new RegExp(p)).toList(); - Map gitGrep = json["git grep"]; - List gitGrepPathspecs; - List gitGrepPatterns; + Map? gitGrep = json["git grep"]; + List? gitGrepPathspecs; + List? gitGrepPatterns; if (gitGrep != null) { gitGrepPathspecs = gitGrep["pathspecs"] == null ? const ["."] @@ -73,13 +73,13 @@ class Analyze extends Suite { } class AnalyzerDiagnostic { - final String kind; + final String? kind; - final String detailedKind; + final String? detailedKind; - final String code; + final String? code; - final Uri uri; + final Uri? uri; final int line; @@ -106,7 +106,7 @@ class AnalyzerDiagnostic { addPart() { parts.add(line .substring(start, index == -1 ? null : index) - .replaceAllMapped(unescapePattern, (Match m) => m[1])); + .replaceAllMapped(unescapePattern, (Match m) => m[1]!)); } while (index != -1) { @@ -136,8 +136,8 @@ class AnalyzerDiagnostic { String toString() { return kind == null ? "Malformed output from dartanalyzer:\n$message" - : "${uri.toFilePath()}:$line:$startColumn: " - "${kind == 'INFO' ? 'warning: hint' : kind.toLowerCase()}:\n" + : "${uri!.toFilePath()}:$line:$startColumn: " + "${kind == 'INFO' ? 'warning: hint' : kind!.toLowerCase()}:\n" "[$code] $message"; } } @@ -154,12 +154,12 @@ Stream parseAnalyzerOutput( /// Run dartanalyzer on all tests in [uris]. Future analyzeUris( - Uri analysisOptions, + Uri? analysisOptions, Uri packages, List uris, List exclude, - List gitGrepPathspecs, - List gitGrepPatterns) async { + List? gitGrepPathspecs, + List? gitGrepPatterns) async { if (uris.isEmpty) return; String topLevel; try { @@ -205,7 +205,7 @@ Future analyzeUris( arguments.addAll( gitGrepPatterns.expand((String pattern) => ["-e", pattern])); arguments.add("--"); - arguments.addAll(gitGrepPathspecs); + arguments.addAll(gitGrepPathspecs!); filesToAnalyze.addAll(splitLines(await git("grep", arguments)) .map((String line) => line.trimRight())); } @@ -245,7 +245,7 @@ Future analyzeUris( processAnalyzerOutput(Stream diagnostics) async { await for (AnalyzerDiagnostic diagnostic in diagnostics) { if (diagnostic.uri != null) { - String path = toFilePath(diagnostic.uri); + String path = toFilePath(diagnostic.uri!); if (!filesToAnalyze.contains(path)) continue; } String message = "$diagnostic"; @@ -283,7 +283,7 @@ String _findSdkPath() { } Future git(String command, Iterable arguments, - {String workingDirectory}) async { + {String? workingDirectory}) async { ProcessResult result = await Process.run( Platform.isWindows ? "git.bat" : "git", [command]..addAll(arguments), diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index c56fc216f60..8ab797bcacb 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -115,7 +115,7 @@ abstract class ChainContext { .map((s) => s.substring(0, s.length - 3)) .toList(); TestExpectations expectations = await ReadTestExpectations( - [suite.statusFile.toFilePath()], {}, expectationSet); + [suite.statusFile!.toFilePath()], {}, expectationSet); Stream stream = list(suite); if (suite.processMultitests) { stream = stream.transform(new MultitestTransformer()); @@ -149,12 +149,12 @@ abstract class ChainContext { final Set expectedOutcomes = processExpectedOutcomes( expectations.expectations(description.shortName), description); final StringBuffer sb = new StringBuffer(); - final Step lastStep = steps.isNotEmpty ? steps.last : null; + final Step? lastStep = steps.isNotEmpty ? steps.last : null; final Iterator iterator = steps.iterator; - Result result; + Result? result; // Records the outcome of the last step that was run. - Step lastStepRun; + Step? lastStepRun; /// Performs one step of [iterator]. /// @@ -194,30 +194,30 @@ abstract class ChainContext { future = new Future.value(null); } future = future.then((_currentResult) async { - Result currentResult = _currentResult; + Result? currentResult = _currentResult; if (currentResult != null) { logger.logStepComplete(completed, unexpectedResults.length, - descriptions.length, suite, description, lastStepRun); + descriptions.length, suite, description, lastStepRun!); result = currentResult; if (currentResult.outcome == Expectation.Pass) { // The input to the next step is the output of this step. - return doStep(result.output); + return doStep(result!.output); } } - await cleanUp(description, result); + await cleanUp(description, result!); result = - processTestResult(description, result, lastStep == lastStepRun); - if (!expectedOutcomes.contains(result.outcome) && - !expectedOutcomes.contains(result.outcome.canonical)) { - result.addLog("$sb"); - unexpectedResults[description] = result; + processTestResult(description, result!, lastStep == lastStepRun); + if (!expectedOutcomes.contains(result!.outcome) && + !expectedOutcomes.contains(result!.outcome.canonical)) { + result!.addLog("$sb"); + unexpectedResults[description] = result!; unexpectedOutcomes[description] = expectedOutcomes; logger.logUnexpectedResult( - suite, description, result, expectedOutcomes); + suite, description, result!, expectedOutcomes); exitCode = 1; } else { logger.logExpectedResult( - suite, description, result, expectedOutcomes); + suite, description, result!, expectedOutcomes); logger.logMessage(sb); } logger.logTestComplete(++completed, unexpectedResults.length, @@ -241,7 +241,7 @@ abstract class ChainContext { if (unexpectedResults.isNotEmpty) { unexpectedResults.forEach((TestDescription description, Result result) { logger.logUnexpectedResult( - suite, description, result, unexpectedOutcomes[description]); + suite, description, result, unexpectedOutcomes[description]!); }); print("${unexpectedResults.length} failed:"); unexpectedResults.forEach((TestDescription description, Result result) { @@ -278,7 +278,7 @@ abstract class ChainContext { TestDescription description, Result result, bool last) { if (description is FileBasedTestDescription && description.multitestExpectations != null) { - if (isError(description.multitestExpectations)) { + if (isError(description.multitestExpectations!)) { result = toNegativeTestResult(result, description.multitestExpectations); } @@ -286,14 +286,14 @@ abstract class ChainContext { if (result.outcome == Expectation.Pass) { result.addLog("Negative test didn't report an error.\n"); } else if (result.outcome == Expectation.Fail) { - result.addLog("Negative test reported an error as expeceted.\n"); + result.addLog("Negative test reported an error as expected.\n"); } result = toNegativeTestResult(result); } return result; } - Result toNegativeTestResult(Result result, [Set expectations]) { + Result toNegativeTestResult(Result result, [Set? expectations]) { Expectation outcome = result.outcome; if (outcome == Expectation.Pass) { if (expectations == null) { @@ -312,9 +312,9 @@ abstract class ChainContext { return result.copyWithOutcome(outcome); } - Future cleanUp(TestDescription description, Result result) => null; + Future cleanUp(TestDescription description, Result result) async {} - Future postRun() => null; + Future postRun() async {} } abstract class Step { @@ -355,25 +355,25 @@ abstract class Step { Result crash(error, StackTrace trace) => new Result.crash(error, trace); - Result fail(O output, [error, StackTrace trace]) { + Result fail(O output, [error, StackTrace? trace]) { return new Result.fail(output, error, trace); } } class Result { - final O output; + final O? output; final Expectation outcome; final error; - final StackTrace trace; + final StackTrace? trace; final List logs = []; /// If set, running the test with '-D$autoFixCommand' will automatically /// update the test to match new expectations. - final String autoFixCommand; + final String? autoFixCommand; /// If set, the test can be fixed by running /// @@ -391,7 +391,7 @@ class Result { Result.crash(error, StackTrace trace) : this(null, Expectation.Crash, error, trace: trace); - Result.fail(O output, [error, StackTrace trace]) + Result.fail(O output, [error, StackTrace? trace]) : this(output, Expectation.Fail, error, trace: trace); bool get isPass => outcome == Expectation.Pass; @@ -420,7 +420,8 @@ class Result { Future runChain(CreateContext f, Map environment, Set selectors, String jsonText) { return withErrorHandling(() async { - Chain suite = new Suite.fromJsonMap(Uri.base, json.decode(jsonText)); + Chain suite = + new Suite.fromJsonMap(Uri.base, json.decode(jsonText)) as Chain; print("Running ${suite.name}"); ChainContext context = await f(suite, environment); return context.run(suite, selectors); diff --git a/pkg/testing/lib/src/discover.dart b/pkg/testing/lib/src/discover.dart index 3fd09e996dd..6b761abb90f 100644 --- a/pkg/testing/lib/src/discover.dart +++ b/pkg/testing/lib/src/discover.dart @@ -20,10 +20,10 @@ List get dartArguments => ["-c", "--packages=${packageConfig.toFilePath()}"]; Stream listTests(List testRoots, - {Pattern pattern}) { + {Pattern? pattern}) { StreamController controller = new StreamController(); - Map subscriptions = {}; + Map subscriptions = {}; for (Uri testRootUri in testRoots) { subscriptions[testRootUri] = null; Directory testRoot = new Directory.fromUri(testRootUri); @@ -32,8 +32,9 @@ Stream listTests(List testRoots, Stream stream = testRoot.list(recursive: true, followLinks: false); var subscription = stream.listen((FileSystemEntity entity) { - FileBasedTestDescription description = FileBasedTestDescription - .from(testRootUri, entity, pattern: pattern); + FileBasedTestDescription? description = FileBasedTestDescription.from( + testRootUri, entity, + pattern: pattern); if (description != null) { controller.add(description); } @@ -59,7 +60,7 @@ Stream listTests(List testRoots, } Uri computePackageConfig() { - String path = Platform.packageConfig; + String? path = Platform.packageConfig; if (path != null) return Uri.base.resolve(path); return Uri.base.resolve(".packages"); } @@ -72,7 +73,7 @@ const _dartSdk = (String.fromEnvironment("DART_SDK", defaultValue: "1") == : null; Uri computeDartSdk() { - String dartSdkPath = Platform.environment["DART_SDK"] ?? _dartSdk; + String? dartSdkPath = Platform.environment["DART_SDK"] ?? _dartSdk; if (dartSdkPath != null) { return Uri.base.resolveUri(new Uri.file(dartSdkPath)); } else { @@ -83,7 +84,7 @@ Uri computeDartSdk() { } Future startDart(Uri program, - [List arguments, List vmArguments]) { + [List? arguments, List? vmArguments]) { List allArguments = []; allArguments.addAll(vmArguments ?? dartArguments); allArguments.add(program.toFilePath()); diff --git a/pkg/testing/lib/src/error_handling.dart b/pkg/testing/lib/src/error_handling.dart index 452e4b72f6c..872f2f0ca84 100644 --- a/pkg/testing/lib/src/error_handling.dart +++ b/pkg/testing/lib/src/error_handling.dart @@ -12,13 +12,14 @@ import 'dart:isolate' show ReceivePort; import 'log.dart'; -Future withErrorHandling(Future f(), {Logger logger}) async { +Future withErrorHandling(Future f(), {Logger? logger}) async { final ReceivePort port = new ReceivePort(); try { return await f(); } catch (e, trace) { exitCode = 1; stderr.writeln(e); + // ignore: unnecessary_null_comparison if (trace != null) { stderr.writeln(trace); } diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart index 58efce8268b..153adee7855 100644 --- a/pkg/testing/lib/src/expectation.dart +++ b/pkg/testing/lib/src/expectation.dart @@ -42,7 +42,7 @@ class Expectation { String toString() => name; - static Expectation fromGroup(ExpectationGroup group) { + static Expectation? fromGroup(ExpectationGroup group) { switch (group) { case ExpectationGroup.Crash: return Expectation.Crash; @@ -57,7 +57,6 @@ class Expectation { case ExpectationGroup.Timeout: return Expectation.Timeout; } - throw "Unhandled group: '$group'."; } } @@ -89,8 +88,8 @@ class ExpectationSet { Map internalMap = new Map.from(Default.internalMap); for (Map map in data) { - String name; - String group; + String? name; + String? group; map.forEach((_key, _value) { String key = _key; String value = _value; @@ -113,12 +112,12 @@ class ExpectationSet { if (group == null) { throw "No group provided in '$map'"; } - Expectation expectation = new Expectation(name, groupFromString(group)); - name = name.toLowerCase(); + Expectation expectation = new Expectation(name!, groupFromString(group!)); + name = name!.toLowerCase(); if (internalMap.containsKey(name)) { throw "Duplicated expectation name: '$name'."; } - internalMap[name] = expectation; + internalMap[name!] = expectation; } return new ExpectationSet(internalMap); } diff --git a/pkg/testing/lib/src/log.dart b/pkg/testing/lib/src/log.dart index 7e6fafd0f71..d46ab0a3353 100644 --- a/pkg/testing/lib/src/log.dart +++ b/pkg/testing/lib/src/log.dart @@ -78,19 +78,19 @@ abstract class Logger { class StdoutLogger implements Logger { const StdoutLogger(); - void logTestStart(int completed, int failed, int total, Suite suite, - TestDescription description) {} + void logTestStart(int completed, int failed, int total, Suite? suite, + TestDescription? description) {} - void logTestComplete(int completed, int failed, int total, Suite suite, - TestDescription description) { + void logTestComplete(int completed, int failed, int total, Suite? suite, + TestDescription? description) { String message = formatProgress(completed, failed, total); if (suite != null) { - message += ": ${formatTestDescription(suite, description)}"; + message += ": ${formatTestDescription(suite, description!)}"; } logProgress(message); } - void logStepStart(int completed, int failed, int total, Suite suite, + void logStepStart(int completed, int failed, int total, Suite? suite, TestDescription description, Step step) { String message = formatProgress(completed, failed, total); if (suite != null) { @@ -102,7 +102,7 @@ class StdoutLogger implements Logger { logProgress(message); } - void logStepComplete(int completed, int failed, int total, Suite suite, + void logStepComplete(int completed, int failed, int total, Suite? suite, TestDescription description, Step step) { if (!step.isAsync) return; String message = formatProgress(completed, failed, total); @@ -152,7 +152,7 @@ class StdoutLogger implements Logger { void logUnexpectedResult(Suite suite, TestDescription description, Result result, Set expectedOutcomes) { print("${eraseLine}UNEXPECTED: ${suite.name}/${description.shortName}"); - Uri statusFile = suite.statusFile; + Uri? statusFile = suite.statusFile; if (statusFile != null) { String path = statusFile.toFilePath(); if (result.outcome == Expectation.Pass) { @@ -186,6 +186,7 @@ class StdoutLogger implements Logger { void logUncaughtError(error, StackTrace stackTrace) { logMessage(error); + // ignore: unnecessary_null_comparison if (stackTrace != null) { logMessage(stackTrace); } diff --git a/pkg/testing/lib/src/multitest.dart b/pkg/testing/lib/src/multitest.dart index d87ac1bd3c6..62bb63e550d 100644 --- a/pkg/testing/lib/src/multitest.dart +++ b/pkg/testing/lib/src/multitest.dart @@ -51,8 +51,8 @@ class MultitestTransformer nextTest: await for (TestDescription test in stream) { - FileBasedTestDescription multitest; - String contents; + FileBasedTestDescription? multitest; + String? contents; if (test is FileBasedTestDescription) { contents = await test.file.readAsString(); if (contents.contains(multitestMarker)) { @@ -73,11 +73,11 @@ class MultitestTransformer "none": new Set(), }; int lineNumber = 0; - for (String line in splitLines(contents)) { + for (String line in splitLines(contents!)) { lineNumber++; int index = line.indexOf(multitestMarker); - String subtestName; - List subtestOutcomesList; + String? subtestName; + List? subtestOutcomesList; if (index != -1) { String annotationText = line.substring(index + _multitestMarkerLength).trim(); @@ -102,7 +102,7 @@ class MultitestTransformer lines.add(line); Set subtestOutcomes = outcomes.putIfAbsent(subtestName, () => new Set()); - if (subtestOutcomesList.length != 1 || + if (subtestOutcomesList!.length != 1 || subtestOutcomesList.single != "continued") { for (String outcome in subtestOutcomesList) { if (validOutcomes.contains(outcome)) { @@ -125,8 +125,9 @@ class MultitestTransformer Directory generated = new Directory.fromUri(root.resolve(multitest.shortName)); generated = await generated.create(recursive: true); - for (String name in testsAsLines.keys) { - List lines = testsAsLines[name]; + for (MapEntry> entry in testsAsLines.entries) { + String name = entry.key; + List lines = entry.value; Uri uri = generated.uri.resolve("${name}_generated.dart"); FileBasedTestDescription subtest = new FileBasedTestDescription(root, new File.fromUri(uri)); diff --git a/pkg/testing/lib/src/run.dart b/pkg/testing/lib/src/run.dart index 7ce9bd02dbf..45672364477 100644 --- a/pkg/testing/lib/src/run.dart +++ b/pkg/testing/lib/src/run.dart @@ -34,10 +34,10 @@ import 'zone_helper.dart' show acknowledgeControlMessages; import 'run_tests.dart' show CommandLine; -Future computeTestRoot(String configurationPath, Uri base) { +Future computeTestRoot(String? configurationPath, Uri? base) { Uri configuration = configurationPath == null ? Uri.base.resolve("testing.json") - : base.resolve(configurationPath); + : base!.resolve(configurationPath); return TestRoot.fromUri(configuration); } @@ -50,8 +50,8 @@ Future computeTestRoot(String configurationPath, Uri base) { /// `testing.json` isn't located in the current working directory and is a path /// relative to [me] which defaults to `Platform.script`. Future runMe(List arguments, CreateContext f, - {String configurationPath, - Uri me, + {String? configurationPath, + Uri? me, int shards = 1, int shard = 0, Logger logger: const StdoutLogger()}) { @@ -98,7 +98,7 @@ Future runMe(List arguments, CreateContext f, /// `testing.json` isn't located in the current working directory and is a path /// relative to `Uri.base`. Future run(List arguments, List suiteNames, - [String configurationPath]) { + [String? configurationPath]) { return withErrorHandling(() async { TestRoot root = await computeTestRoot(configurationPath, Uri.base); List suites = root.suites @@ -106,7 +106,7 @@ Future run(List arguments, List suiteNames, .toList(); SuiteRunner runner = new SuiteRunner(suites, {}, const [], new Set(), new Set()); - String program = await runner.generateDartProgram(); + String? program = await runner.generateDartProgram(); await runner.analyze(root.packages); if (program != null) { await runProgram(program, root.packages); @@ -125,7 +125,7 @@ Future runProgram(String program, Uri packages) async { errorsAreFatal: false, checked: true, packageConfig: packages); - List error; + List? error; var subscription = isolate.errors.listen((data) { error = data; exitPort.close(); @@ -137,7 +137,7 @@ Future runProgram(String program, Uri packages) async { subscription.cancel(); return error == null ? null - : new Future.error(error[0], new StackTrace.fromString(error[1])); + : new Future.error(error![0], new StackTrace.fromString(error![1])); } class SuiteRunner { @@ -162,7 +162,7 @@ class SuiteRunner { (selectedSuites.isEmpty || selectedSuites.contains(suite.name)); } - Future generateDartProgram() async { + Future generateDartProgram() async { testUris.clear(); StringBuffer imports = new StringBuffer(); StringBuffer dart = new StringBuffer(); @@ -238,10 +238,10 @@ Future main() async { } Stream listDescriptions() async* { - for (Dart suite in suites.where((Suite suite) => suite is Dart)) { + for (Dart suite in suites.whereType()) { await for (FileBasedTestDescription description in listTests([suite.uri], pattern: "")) { - testUris.add(await Isolate.resolvePackageUri(description.uri)); + testUris.add((await Isolate.resolvePackageUri(description.uri))!); if (shouldRunSuite(suite)) { String path = description.file.uri.path; if (suite.exclude.any((RegExp r) => path.contains(r))) continue; @@ -254,19 +254,19 @@ Future main() async { } Stream listChainSuites() async* { - for (Chain suite in suites.where((Suite suite) => suite is Chain)) { - testUris.add(await Isolate.resolvePackageUri(suite.source)); + for (Chain suite in suites.whereType()) { + testUris.add((await Isolate.resolvePackageUri(suite.source))!); if (shouldRunSuite(suite)) { yield suite; } } } - Iterable listTestDartSuites() { - return suites.where((Suite suite) => suite is TestDart); + Iterable listTestDartSuites() { + return suites.whereType(); } - Iterable listAnalyzerSuites() { - return suites.where((Suite suite) => suite is Analyze); + Iterable listAnalyzerSuites() { + return suites.whereType(); } } diff --git a/pkg/testing/lib/src/run_tests.dart b/pkg/testing/lib/src/run_tests.dart index b4ccd3be64a..03d5d3de4fc 100644 --- a/pkg/testing/lib/src/run_tests.dart +++ b/pkg/testing/lib/src/run_tests.dart @@ -64,7 +64,7 @@ class CommandLine { Iterable get selectors => arguments; - Future get configuration async { + Future get configuration async { const String configPrefix = "--config="; List configurationPaths = options .where((String option) => option.startsWith(configPrefix)) @@ -111,7 +111,7 @@ class CommandLine { } const StdoutLogger() .logMessage("Reading configuration file '$configurationPath'."); - Uri configuration = + Uri? configuration = await Isolate.resolvePackageUri(Uri.base.resolve(configurationPath)); if (configuration == null || !await new File.fromUri(configuration).exists()) { @@ -147,7 +147,7 @@ main(List arguments) => withErrorHandling(() async { enableVerboseOutput(); } Map environment = cl.environment; - Uri configuration = await cl.configuration; + Uri? configuration = await cl.configuration; if (configuration == null) return; if (!isVerbose) { print("Use --verbose to display more details."); @@ -155,7 +155,7 @@ main(List arguments) => withErrorHandling(() async { TestRoot root = await TestRoot.fromUri(configuration); SuiteRunner runner = new SuiteRunner( root.suites, environment, cl.selectors, cl.selectedSuites, cl.skip); - String program = await runner.generateDartProgram(); + String? program = await runner.generateDartProgram(); bool hasAnalyzerSuites = await runner.analyze(root.packages); Stopwatch sw = new Stopwatch()..start(); if (program == null) { @@ -178,7 +178,7 @@ Future runTests(Map tests) => try { await runGuarded(() { print("Running test $name"); - return tests[name](); + return tests[name]!(); }, printLineOnStdout: sb.writeln); const StdoutLogger().logMessage(sb); } catch (e) { diff --git a/pkg/testing/lib/src/stdio_process.dart b/pkg/testing/lib/src/stdio_process.dart index 16bbfdfdfb0..587a07f570d 100644 --- a/pkg/testing/lib/src/stdio_process.dart +++ b/pkg/testing/lib/src/stdio_process.dart @@ -41,13 +41,13 @@ class StdioProcess { } static Future run(String executable, List arguments, - {String input, - Duration timeout: const Duration(seconds: 60), + {String? input, + Duration? timeout: const Duration(seconds: 60), bool suppressOutput: true, bool runInShell: false}) async { Process process = await Process.start(executable, arguments, runInShell: runInShell); - Timer timer; + Timer? timer; StringBuffer sb = new StringBuffer(); if (timeout != null) { timer = new Timer(timeout, () { @@ -75,8 +75,8 @@ class StdioProcess { stdoutStream = stdoutStream.transform(transformToStdio(io.stdout)); stderrStream = stderrStream.transform(transformToStdio(io.stderr)); } - Future> stdoutFuture = stdoutStream.toList(); - Future> stderrFuture = stderrStream.toList(); + Future> stdoutFuture = stdoutStream.toList() as Future>; + Future> stderrFuture = stderrStream.toList() as Future>; int exitCode = await process.exitCode; timer?.cancel(); sb.writeAll(await stdoutFuture); diff --git a/pkg/testing/lib/src/suite.dart b/pkg/testing/lib/src/suite.dart index 54aa7c8ca5f..b1597971452 100644 --- a/pkg/testing/lib/src/suite.dart +++ b/pkg/testing/lib/src/suite.dart @@ -14,7 +14,7 @@ abstract class Suite { final String kind; - final Uri statusFile; + final Uri? statusFile; Suite(this.name, this.kind, this.statusFile); diff --git a/pkg/testing/lib/src/test_dart/path.dart b/pkg/testing/lib/src/test_dart/path.dart index 3c5fbeaa065..f0b5b5105ac 100644 --- a/pkg/testing/lib/src/test_dart/path.dart +++ b/pkg/testing/lib/src/test_dart/path.dart @@ -192,7 +192,7 @@ class Path { Path makeCanonical() { bool isAbs = isAbsolute; List segs = segments(); - String drive; + String? drive; if (isAbs && !segs.isEmpty && segs[0].length == 2 && segs[0][1] == ':') { drive = segs[0]; segs.removeRange(0, 1); @@ -267,7 +267,7 @@ class Path { } List segments() { - List result = _path.split('/'); + List result = _path.split('/'); if (isAbsolute) result.removeRange(0, 1); if (hasTrailingSeparator) result.removeLast(); return result; diff --git a/pkg/testing/lib/src/test_dart/status_expression.dart b/pkg/testing/lib/src/test_dart/status_expression.dart index 200d241725b..395483a6644 100644 --- a/pkg/testing/lib/src/test_dart/status_expression.dart +++ b/pkg/testing/lib/src/test_dart/status_expression.dart @@ -64,7 +64,9 @@ class Tokenizer { if (!testRegexp.hasMatch(expression)) { throw new FormatException("Syntax error in '$expression'"); } - for (Match match in regexp.allMatches(expression)) tokens.add(match[0]); + for (Match match in regexp.allMatches(expression)) { + tokens.add(match[0]!); + } return tokens; } } @@ -179,8 +181,8 @@ class SetConstant implements SetExpression { // An iterator that allows peeking at the current token. class Scanner { List tokens; - Iterator tokenIterator; - String current; + late Iterator tokenIterator; + String? current; Scanner(this.tokens) { tokenIterator = tokens.iterator; @@ -241,11 +243,11 @@ class ExpressionParser { scanner.advance(); return value; } - if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { + if (!new RegExp(r"^\w+$").hasMatch(scanner.current!)) { throw new FormatException( "Expected identifier in expression, got ${scanner.current}"); } - SetExpression value = new SetConstant(scanner.current); + SetExpression value = new SetConstant(scanner.current!); scanner.advance(); return value; } @@ -290,21 +292,21 @@ class ExpressionParser { "Expected \$ in expression, got ${scanner.current}"); } scanner.advance(); - if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { + if (!new RegExp(r"^\w+$").hasMatch(scanner.current!)) { throw new FormatException( "Expected identifier in expression, got ${scanner.current}"); } - TermVariable left = new TermVariable(scanner.current); + TermVariable left = new TermVariable(scanner.current!); scanner.advance(); if (scanner.current == Token.EQUALS || scanner.current == Token.NOT_EQUALS) { bool negate = scanner.current == Token.NOT_EQUALS; scanner.advance(); - if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { + if (!new RegExp(r"^\w+$").hasMatch(scanner.current!)) { throw new FormatException( "Expected value in expression, got ${scanner.current}"); } - TermConstant right = new TermConstant(scanner.current); + TermConstant right = new TermConstant(scanner.current!); scanner.advance(); return new Comparison(left, right, negate); } else { diff --git a/pkg/testing/lib/src/test_dart/status_file_parser.dart b/pkg/testing/lib/src/test_dart/status_file_parser.dart index 1ce711fbd50..a3d2f5887fc 100644 --- a/pkg/testing/lib/src/test_dart/status_file_parser.dart +++ b/pkg/testing/lib/src/test_dart/status_file_parser.dart @@ -29,7 +29,7 @@ class StatusFile { class Section { final StatusFile statusFile; - final BooleanExpression condition; + final BooleanExpression? condition; final List testRules; final int lineNumber; @@ -40,7 +40,7 @@ class Section { : testRules = []; bool isEnabled(Map environment) => - condition == null || condition.evaluate(environment); + condition == null || condition!.evaluate(environment); String toString() { return "Section: $condition"; @@ -93,17 +93,17 @@ void ReadConfigurationInto(Path path, List
sections, void onDone()) { lines.listen((String line) { lineNumber++; - Match match = SplitComment.firstMatch(line); - line = (match == null) ? "" : match[1]; + Match? match = SplitComment.firstMatch(line); + line = (match == null) ? "" : match[1]!; line = line.trim(); if (line.isEmpty) return; // Extract the comment to get the issue number if needed. - String comment = (match == null || match[2] == null) ? "" : match[2]; + String comment = (match == null || match[2] == null) ? "" : match[2]!; match = HeaderPattern.firstMatch(line); if (match != null) { - String condition_string = match[1].trim(); + String condition_string = match[1]!.trim(); List tokens = new Tokenizer(condition_string).tokenize(); ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); currentSection = @@ -114,21 +114,21 @@ void ReadConfigurationInto(Path path, List
sections, void onDone()) { match = RulePattern.firstMatch(line); if (match != null) { - String name = match[1].trim(); + String name = match[1]!.trim(); // TODO(whesse): Handle test names ending in a wildcard (*). - String expression_string = match[2].trim(); + String expression_string = match[2]!.trim(); List tokens = new Tokenizer(expression_string).tokenize(); SetExpression expression = new ExpressionParser(new Scanner(tokens)).parseSetExpression(); // Look for issue number in comment. - String issueString = null; + String? issueString = null; match = IssueNumberPattern.firstMatch(comment); if (match != null) { issueString = match[1]; if (issueString == null) issueString = match[2]; } - int issue = issueString != null ? int.parse(issueString) : null; + int? issue = issueString != null ? int.parse(issueString) : null; currentSection.testRules .add(new TestRule(name, expression, issue, lineNumber)); return; @@ -141,7 +141,7 @@ void ReadConfigurationInto(Path path, List
sections, void onDone()) { class TestRule { String name; SetExpression expression; - int issue; + int? issue; int lineNumber; TestRule(this.name, this.expression, this.issue, this.lineNumber); @@ -161,8 +161,8 @@ class TestExpectations { Map> _map; bool _preprocessed = false; - Map _regExpCache; - Map> _keyToRegExps; + Map? _regExpCache; + Map>? _keyToRegExps; /** * Create a TestExpectations object. See the [expectations] method @@ -203,7 +203,7 @@ class TestExpectations { _preprocessForMatching(); _map.forEach((key, expectation) { - List regExps = _keyToRegExps[key]; + List regExps = _keyToRegExps![key]!; if (regExps.length > splitFilename.length) return; for (var i = 0; i < regExps.length; i++) { if (!regExps[i].hasMatch(splitFilename[i])) return; @@ -231,20 +231,19 @@ class TestExpectations { _regExpCache = {}; _map.forEach((key, expectations) { - if (_keyToRegExps[key] != null) return; + if (_keyToRegExps![key] != null) return; var splitKey = key.split('/'); - var regExps = new List.filled(splitKey.length, null); - for (var i = 0; i < splitKey.length; i++) { + var regExps = new List.generate(splitKey.length, (int i) { var component = splitKey[i]; - var regExp = _regExpCache[component]; + var regExp = _regExpCache![component]; if (regExp == null) { var pattern = "^${splitKey[i]}\$".replaceAll('*', '.*'); regExp = new RegExp(pattern); - _regExpCache[component] = regExp; + _regExpCache![component] = regExp; } - regExps[i] = regExp; - } - _keyToRegExps[key] = regExps; + return regExp; + }, growable: false); + _keyToRegExps![key] = regExps; }); _regExpCache = null; diff --git a/pkg/testing/lib/src/test_description.dart b/pkg/testing/lib/src/test_description.dart index 7480ee0118e..1fe0ac15c19 100644 --- a/pkg/testing/lib/src/test_description.dart +++ b/pkg/testing/lib/src/test_description.dart @@ -17,11 +17,11 @@ abstract class TestDescription implements Comparable { class FileBasedTestDescription extends TestDescription { final Uri root; final File file; - final Uri output; + final Uri? output; /// If non-null, this is a generated multitest, and the set contains the /// expected outcomes. - Set multitestExpectations; + Set? multitestExpectations; FileBasedTestDescription(this.root, this.file, {this.output}); @@ -52,8 +52,8 @@ class FileBasedTestDescription extends TestDescription { sink.writeln('.main,'); } - static FileBasedTestDescription from(Uri root, FileSystemEntity entity, - {Pattern pattern}) { + static FileBasedTestDescription? from(Uri root, FileSystemEntity entity, + {Pattern? pattern}) { if (entity is! File) return null; pattern ??= "_test.dart"; String path = entity.uri.path; diff --git a/pkg/testing/lib/src/test_root.dart b/pkg/testing/lib/src/test_root.dart index 9e3b65e7285..554abee9123 100644 --- a/pkg/testing/lib/src/test_root.dart +++ b/pkg/testing/lib/src/test_root.dart @@ -49,7 +49,7 @@ class TestRoot { TestRoot(this.packages, this.suites); - Analyze get analyze => suites.last; + Analyze get analyze => suites.last as Analyze; List get urisToAnalyze => analyze.uris; diff --git a/pkg/testing/lib/src/zone_helper.dart b/pkg/testing/lib/src/zone_helper.dart index d8d7d397010..a378d7a430a 100644 --- a/pkg/testing/lib/src/zone_helper.dart +++ b/pkg/testing/lib/src/zone_helper.dart @@ -14,8 +14,8 @@ import 'dart:isolate' show Capability, Isolate, ReceivePort; import 'log.dart' show StdoutLogger; Future runGuarded(Future f(), - {void printLineOnStdout(line), - void handleLateError(error, StackTrace stackTrace)}) { + {void Function(String)? printLineOnStdout, + void Function(dynamic, StackTrace)? handleLateError}) { var printWrapper; if (printLineOnStdout != null) { printWrapper = (_1, _2, _3, String line) { @@ -39,6 +39,7 @@ Future runGuarded(Future f(), // Ignored. } stderr + // ignore: unnecessary_null_comparison .write("$errorString\n" + (stackTrace == null ? "" : "$stackTrace")); stderr.flush(); exit(255); @@ -81,7 +82,7 @@ Future runGuarded(Future f(), /// Ping [isolate] to ensure control messages have been delivered. Control /// messages are things like [Isolate.addErrorListener] and /// [Isolate.addOnExitListener]. -Future acknowledgeControlMessages(Isolate isolate, {Capability resume}) { +Future acknowledgeControlMessages(Isolate isolate, {Capability? resume}) { ReceivePort ping = new ReceivePort(); Isolate.current.ping(ping.sendPort); if (resume == null) { diff --git a/pkg/testing/pubspec.yaml b/pkg/testing/pubspec.yaml index f012946a943..d85f43fb05b 100644 --- a/pkg/testing/pubspec.yaml +++ b/pkg/testing/pubspec.yaml @@ -4,4 +4,4 @@ name: testing # This package is not intended for consumption on pub.dev. DO NOT publish. publish_to: none environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0'