diff --git a/pkg/async_helper/lib/async_helper.dart b/pkg/async_helper/lib/async_helper.dart index 37496bcb76b..965385e4a3a 100644 --- a/pkg/async_helper/lib/async_helper.dart +++ b/pkg/async_helper/lib/async_helper.dart @@ -41,7 +41,7 @@ Exception _buildException(String msg) { void asyncStart() { if (_initialized && _asyncLevel == 0) { throw _buildException('asyncStart() was called even though we are done ' - 'with testing.'); + 'with testing.'); } if (!_initialized) { print('unittest-suite-wait-for-done'); @@ -58,7 +58,7 @@ void asyncEnd() { throw _buildException('asyncEnd() was called before asyncStart().'); } else { throw _buildException('asyncEnd() was called more often than ' - 'asyncStart().'); + 'asyncStart().'); } } _asyncLevel--; diff --git a/pkg/lookup_map/lib/lookup_map.dart b/pkg/lookup_map/lib/lookup_map.dart index 65ac7540aca..2e501cd16e6 100644 --- a/pkg/lookup_map/lib/lookup_map.dart +++ b/pkg/lookup_map/lib/lookup_map.dart @@ -60,14 +60,20 @@ class LookupMap { /// instead of a list of key-value pairs. // TODO(sigmund): make entries a map once we fix TypeImpl.== (issue #17207). const LookupMap(List entries, [List> nestedMaps = const []]) - : _key = null, _value = null, _entries = entries, _nestedMaps = nestedMaps; + : _key = null, + _value = null, + _entries = entries, + _nestedMaps = nestedMaps; /// Creates a lookup map with a single key-value pair. const LookupMap.pair(K key, V value) - : _key = key, _value = value, _entries = const [], _nestedMaps = const []; + : _key = key, + _value = value, + _entries = const [], + _nestedMaps = const []; /// Return the data corresponding to [key]. - V operator[](K key) { + V operator [](K key) { var map = _flatMap[this]; if (map == null) { map = {}; diff --git a/pkg/lookup_map/test/lookup_map_test.dart b/pkg/lookup_map/test/lookup_map_test.dart index 7695833c769..d35e0beb98b 100644 --- a/pkg/lookup_map/test/lookup_map_test.dart +++ b/pkg/lookup_map/test/lookup_map_test.dart @@ -11,16 +11,22 @@ class Key { const Key(this.id); } -class A{} +class A {} + const B = const Key(1); -class C{} + +class C {} main() { test('entries constructor', () { var m = const LookupMap(const [ - A, "the-text-for-A", - B, "the-text-for-B", - 1.2, "the-text-for-1.2"]); + A, + "the-text-for-A", + B, + "the-text-for-B", + 1.2, + "the-text-for-1.2" + ]); expect(m[A], 'the-text-for-A'); expect(m[B], 'the-text-for-B'); expect(m[1.2], 'the-text-for-1.2'); @@ -43,7 +49,8 @@ main() { test('entry shadows nested maps', () { var m = const LookupMap(const [ - A, "the-text-for-A2", + A, + "the-text-for-A2", ], const [ const LookupMap.pair(A, "the-text-for-A1"), ]); @@ -51,7 +58,7 @@ main() { }); test('nested maps shadow in order', () { - var m = const LookupMap(const [ ], const [ + var m = const LookupMap(const [], const [ const LookupMap.pair(A, "the-text-for-A1"), const LookupMap.pair(B, "the-text-for-B2"), const LookupMap.pair(A, "the-text-for-A2"), @@ -65,9 +72,12 @@ main() { // sanity. test('reachable lookups are not tree-shaken', () { var m = const LookupMap(const [ - A, B, - B, C, - C, 3.4, + A, + B, + B, + C, + C, + 3.4, ]); expect(m[m[m[A]]], 3.4); }); diff --git a/pkg/testing/lib/src/analyze.dart b/pkg/testing/lib/src/analyze.dart index c976020a096..781b408c708 100644 --- a/pkg/testing/lib/src/analyze.dart +++ b/pkg/testing/lib/src/analyze.dart @@ -4,26 +4,17 @@ library testing.analyze; -import 'dart:async' show - Stream, - Future; +import 'dart:async' show Stream, Future; -import 'dart:convert' show - LineSplitter, - UTF8; +import 'dart:convert' show LineSplitter, UTF8; -import 'dart:io' show - File, - Process; +import 'dart:io' show File, Process; -import '../testing.dart' show - dartSdk; +import '../testing.dart' show dartSdk; -import 'log.dart' show - isVerbose; +import 'log.dart' show isVerbose; -import 'suite.dart' show - Suite; +import 'suite.dart' show Suite; class Analyze extends Suite { final Uri analysisOptions; @@ -85,9 +76,14 @@ class AnalyzerDiagnostic { if (parts.length != 8) { throw "Malformed output: $line"; } - return new AnalyzerDiagnostic(parts[0], parts[1], parts[2], + return new AnalyzerDiagnostic( + parts[0], + parts[1], + parts[2], Uri.base.resolve(parts[3]), - int.parse(parts[4]), int.parse(parts[5]), int.parse(parts[6]), + int.parse(parts[4]), + int.parse(parts[5]), + int.parse(parts[6]), parts[7]); } @@ -108,8 +104,7 @@ Stream parseAnalyzerOutput( } /// Run dartanalyzer on all tests in [uris]. -Future analyzeUris( - Uri analysisOptions, Uri packages, List uris, +Future analyzeUris(Uri analysisOptions, Uri packages, List uris, List exclude) async { if (uris.isEmpty) return; const String analyzerPath = "bin/dartanalyzer"; @@ -118,9 +113,9 @@ Future analyzeUris( throw "Couldn't find '$analyzerPath' in '${dartSdk.toFilePath()}'"; } List arguments = [ - "--packages=${packages.toFilePath()}", - "--package-warnings", - "--format=machine", + "--packages=${packages.toFilePath()}", + "--package-warnings", + "--format=machine", ]; if (analysisOptions != null) { arguments.add("--options=${analysisOptions.toFilePath()}"); @@ -157,4 +152,3 @@ Future analyzeUris( sw.stop(); print("Running analyzer took: ${sw.elapsed}."); } - diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index 4f970c12bfd..351d89b70bd 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -4,52 +4,36 @@ library testing.chain; -import 'dart:async' show - Future, - Stream; +import 'dart:async' show Future, Stream; -import 'dart:convert' show - JSON, - JsonEncoder; +import 'dart:convert' show JSON, JsonEncoder; -import 'dart:io' show - Directory, - File, - FileSystemEntity, - exitCode; +import 'dart:io' show Directory, File, FileSystemEntity, exitCode; -import 'suite.dart' show - Suite; +import 'suite.dart' show Suite; -import '../testing.dart' show - TestDescription; +import '../testing.dart' show TestDescription; -import 'test_dart/status_file_parser.dart' show - ReadTestExpectations, - TestExpectations; +import 'test_dart/status_file_parser.dart' + show ReadTestExpectations, TestExpectations; -import 'zone_helper.dart' show - runGuarded; +import 'zone_helper.dart' show runGuarded; -import 'error_handling.dart' show - withErrorHandling; +import 'error_handling.dart' show withErrorHandling; -import 'log.dart' show - logMessage, - logStepComplete, - logStepStart, - logSuiteComplete, - logTestComplete, - logUnexpectedResult, - splitLines; +import 'log.dart' + show + logMessage, + logStepComplete, + logStepStart, + logSuiteComplete, + logTestComplete, + logUnexpectedResult, + splitLines; -import 'multitest.dart' show - MultitestTransformer, - isError; +import 'multitest.dart' show MultitestTransformer, isError; -import 'expectation.dart' show - Expectation, - ExpectationSet; +import 'expectation.dart' show Expectation, ExpectationSet; typedef Future CreateContext( Chain suite, Map environment); @@ -74,10 +58,10 @@ class Chain extends Suite { Uri source = base.resolve(json["source"]); Uri uri = base.resolve(json["path"]); Uri statusFile = base.resolve(json["status"]); - List pattern = new List.from( - json["pattern"].map((String p) => new RegExp(p))); - List exclude = new List.from( - json["exclude"].map((String p) => new RegExp(p))); + List pattern = + new List.from(json["pattern"].map((String p) => new RegExp(p))); + List exclude = + new List.from(json["exclude"].map((String p) => new RegExp(p))); bool processMultitests = json["process-multitests"] ?? false; return new Chain(name, kind, source, uri, statusFile, pattern, exclude, processMultitests); @@ -235,6 +219,7 @@ abstract class ChainContext { return future; } } + // The input of the first step is [description]. await doStep(description); } @@ -242,8 +227,8 @@ abstract class ChainContext { logSuiteComplete(); if (unexpectedResults.isNotEmpty) { unexpectedResults.forEach((TestDescription description, Result result) { - logUnexpectedResult(suite, description, result, - unexpectedOutcomes[description]); + logUnexpectedResult( + suite, description, result, unexpectedOutcomes[description]); }); print("${unexpectedResults.length} failed:"); unexpectedResults.forEach((TestDescription description, Result result) { @@ -329,8 +314,7 @@ class Result { Result(this.output, this.outcome, this.error, this.trace); - Result.pass(O output) - : this(output, Expectation.Pass, null, null); + Result.pass(O output) : this(output, Expectation.Pass, null, null); Result.crash(error, StackTrace trace) : this(null, Expectation.Crash, error, trace); @@ -345,15 +329,13 @@ class Result { } Result copyWithOutcome(Expectation outcome) { - return new Result(output, outcome, error, trace) - ..logs.addAll(logs); + return new Result(output, outcome, error, trace)..logs.addAll(logs); } } /// This is called from generated code. -Future runChain( - CreateContext f, Map environment, Set selectors, - String json) { +Future runChain(CreateContext f, Map environment, + Set selectors, String json) { return withErrorHandling(() async { Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); print("Running ${suite.name}"); diff --git a/pkg/testing/lib/src/discover.dart b/pkg/testing/lib/src/discover.dart index 219594771b2..14d8ead32fe 100644 --- a/pkg/testing/lib/src/discover.dart +++ b/pkg/testing/lib/src/discover.dart @@ -4,20 +4,11 @@ library testing.discover; -import 'dart:io' show - Directory, - FileSystemEntity, - Platform, - Process; +import 'dart:io' show Directory, FileSystemEntity, Platform, Process; -import 'dart:async' show - Future, - Stream, - StreamController, - StreamSubscription; +import 'dart:async' show Future, Stream, StreamController, StreamSubscription; -import '../testing.dart' show - TestDescription; +import '../testing.dart' show TestDescription; final Uri packageConfig = computePackageConfig(); @@ -72,8 +63,8 @@ Uri computePackageConfig() { } Uri computeDartSdk() { - String dartSdkPath = Platform.environment["DART_SDK"] - ?? const String.fromEnvironment("DART_SDK"); + String dartSdkPath = Platform.environment["DART_SDK"] ?? + const String.fromEnvironment("DART_SDK"); if (dartSdkPath != null) { return Uri.base.resolveUri(new Uri.file(dartSdkPath)); } else { @@ -81,10 +72,8 @@ Uri computeDartSdk() { } } -Future startDart( - Uri program, - [List arguments, - List vmArguments]) { +Future startDart(Uri program, + [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 325afed58ad..b0f2bac4dce 100644 --- a/pkg/testing/lib/src/error_handling.dart +++ b/pkg/testing/lib/src/error_handling.dart @@ -4,15 +4,11 @@ library testing.error_handling; -import 'dart:async' show - Future; +import 'dart:async' show Future; -import 'dart:io' show - exitCode, - stderr; +import 'dart:io' show exitCode, stderr; -import 'dart:isolate' show - ReceivePort; +import 'dart:isolate' show ReceivePort; Future withErrorHandling(Future f()) async { final ReceivePort port = new ReceivePort(); diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart index 0900c525a47..642ca220e21 100644 --- a/pkg/testing/lib/src/expectation.dart +++ b/pkg/testing/lib/src/expectation.dart @@ -38,26 +38,26 @@ class Expectation { } class ExpectationSet { - static const ExpectationSet Default = const ExpectationSet( - const { - "pass": Expectation.Pass, - "crash": Expectation.Crash, - "timeout": Expectation.Timeout, - "fail": Expectation.Fail, - "skip": Expectation.Skip, - "missingcompiletimeerror": - const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), - "missingruntimeerror": - const Expectation("MissingRuntimeError", ExpectationGroup.Fail), - }); + static const ExpectationSet Default = + const ExpectationSet(const { + "pass": Expectation.Pass, + "crash": Expectation.Crash, + "timeout": Expectation.Timeout, + "fail": Expectation.Fail, + "skip": Expectation.Skip, + "missingcompiletimeerror": + const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), + "missingruntimeerror": + const Expectation("MissingRuntimeError", ExpectationGroup.Fail), + }); final Map internalMap; const ExpectationSet(this.internalMap); - operator[] (String name) { - return internalMap[name.toLowerCase()] - ?? (throw "No expectation named: '$name'."); + operator [](String name) { + return internalMap[name.toLowerCase()] ?? + (throw "No expectation named: '$name'."); } factory ExpectationSet.fromJsonList(List data) { @@ -108,12 +108,18 @@ enum ExpectationGroup { ExpectationGroup groupFromString(String name) { switch (name) { - case "Crash": return ExpectationGroup.Crash; - case "Fail": return ExpectationGroup.Fail; - case "Meta": return ExpectationGroup.Meta; - case "Pass": return ExpectationGroup.Pass; - case "Skip": return ExpectationGroup.Skip; - case "Timeout": return ExpectationGroup.Timeout; + case "Crash": + return ExpectationGroup.Crash; + case "Fail": + return ExpectationGroup.Fail; + case "Meta": + return ExpectationGroup.Meta; + case "Pass": + return ExpectationGroup.Pass; + case "Skip": + return ExpectationGroup.Skip; + case "Timeout": + return ExpectationGroup.Timeout; default: throw "Unrecognized group: '$name'."; } diff --git a/pkg/testing/lib/src/log.dart b/pkg/testing/lib/src/log.dart index 5ff7cb85dc8..628d13976c1 100644 --- a/pkg/testing/lib/src/log.dart +++ b/pkg/testing/lib/src/log.dart @@ -4,18 +4,13 @@ library testing.log; -import 'chain.dart' show - Result, - Step; +import 'chain.dart' show Result, Step; -import 'suite.dart' show - Suite; +import 'suite.dart' show Suite; -import 'test_description.dart' show - TestDescription; +import 'test_description.dart' show TestDescription; -import 'expectation.dart' show - Expectation; +import 'expectation.dart' show Expectation; /// ANSI escape code for moving cursor one line up. /// See [CSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes). @@ -35,8 +30,8 @@ void enableVerboseOutput() { _isVerbose = true; } -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)}"; @@ -44,8 +39,8 @@ void logTestComplete(int completed, int failed, int total, logProgress(message); } -void logStepStart(int completed, int failed, int total, - Suite suite, TestDescription description, Step step) { +void logStepStart(int completed, int failed, int total, Suite suite, + TestDescription description, Step step) { String message = formatProgress(completed, failed, total); if (suite != null) { message += ": ${formatTestDescription(suite, description)} ${step.name}"; @@ -56,8 +51,8 @@ void logStepStart(int completed, int failed, int total, logProgress(message); } -void logStepComplete(int completed, int failed, int total, - Suite suite, TestDescription description, Step step) { +void logStepComplete(int completed, int failed, int total, Suite suite, + TestDescription description, Step step) { if (!step.isAsync) return; String message = formatProgress(completed, failed, total); if (suite != null) { diff --git a/pkg/testing/lib/src/run.dart b/pkg/testing/lib/src/run.dart index 2f9fedaf316..9979ea1870f 100644 --- a/pkg/testing/lib/src/run.dart +++ b/pkg/testing/lib/src/run.dart @@ -4,56 +4,33 @@ library testing.run; -import 'dart:async' show - Future, - Stream; +import 'dart:async' show Future, Stream; -import 'dart:convert' show - JSON; +import 'dart:convert' show JSON; -import 'dart:io' show - Platform; +import 'dart:io' show Platform; -import 'dart:isolate' show - Isolate, - ReceivePort; +import 'dart:isolate' show Isolate, ReceivePort; -import 'test_root.dart' show - TestRoot; +import 'test_root.dart' show TestRoot; -import 'test_description.dart' show - TestDescription; +import 'test_description.dart' show TestDescription; -import 'error_handling.dart' show - withErrorHandling; +import 'error_handling.dart' show withErrorHandling; -import 'chain.dart' show - CreateContext; +import 'chain.dart' show CreateContext; -import '../testing.dart' show - Chain, - ChainContext, - TestDescription, - listTests; +import '../testing.dart' show Chain, ChainContext, TestDescription, listTests; -import 'analyze.dart' show - Analyze; +import 'analyze.dart' show Analyze; -import 'log.dart' show - isVerbose, - logMessage, - logNumberedLines, - splitLines; +import 'log.dart' show isVerbose, logMessage, logNumberedLines, splitLines; -import 'suite.dart' show - Dart, - Suite; +import 'suite.dart' show Dart, Suite; -import 'test_dart.dart' show - TestDart; +import 'test_dart.dart' show TestDart; -import 'zone_helper.dart' show - acknowledgeControlMessages; +import 'zone_helper.dart' show acknowledgeControlMessages; Future computeTestRoot(String configurationPath, Uri base) { Uri configuration = configurationPath == null @@ -70,8 +47,8 @@ Future computeTestRoot(String configurationPath, Uri base) { /// The optional argument [configurationPath] should be used when /// `testing.json` isn't located in the current working directory and is a path /// relative to `Platform.script`. -Future runMe( - List arguments, CreateContext f, [String configurationPath]) { +Future runMe(List arguments, CreateContext f, + [String configurationPath]) { return withErrorHandling(() async { TestRoot testRoot = await computeTestRoot(configurationPath, Platform.script); @@ -112,15 +89,15 @@ Future runMe( /// The optional argument [configurationPath] should be used when /// `testing.json` isn't located in the current working directory and is a path /// relative to `Uri.base`. -Future run( - List arguments, List suiteNames, +Future run(List arguments, List suiteNames, [String configurationPath]) { return withErrorHandling(() async { TestRoot root = await computeTestRoot(configurationPath, Uri.base); - List suites = root.suites.where( - (Suite suite) => suiteNames.contains(suite.name)).toList(); - SuiteRunner runner = new SuiteRunner(suites, {}, null, - new Set(), new Set()); + List suites = root.suites + .where((Suite suite) => suiteNames.contains(suite.name)) + .toList(); + SuiteRunner runner = new SuiteRunner( + suites, {}, null, new Set(), new Set()); String program = await runner.generateDartProgram(); await runner.analyze(root.packages); if (program != null) { @@ -135,8 +112,11 @@ Future runProgram(String program, Uri packages) async { Uri dataUri = new Uri.dataFromString(program); ReceivePort exitPort = new ReceivePort(); Isolate isolate = await Isolate.spawnUri(dataUri, [], null, - paused: true, onExit: exitPort.sendPort, errorsAreFatal: false, - checked: true, packageConfig: packages); + paused: true, + onExit: exitPort.sendPort, + errorsAreFatal: false, + checked: true, + packageConfig: packages); List error; var subscription = isolate.errors.listen((data) { error = data; @@ -247,8 +227,8 @@ Future main() async { Stream listDescriptions() async* { for (Dart suite in suites.where((Suite suite) => suite is Dart)) { - await for (TestDescription description in - listTests([suite.uri], pattern: "")) { + await for (TestDescription description + in listTests([suite.uri], pattern: "")) { testUris.add(await Isolate.resolvePackageUri(description.uri)); if (shouldRunSuite(suite)) { String path = description.file.uri.path; diff --git a/pkg/testing/lib/src/run_tests.dart b/pkg/testing/lib/src/run_tests.dart index c4394687a84..9d8ade32276 100644 --- a/pkg/testing/lib/src/run_tests.dart +++ b/pkg/testing/lib/src/run_tests.dart @@ -4,39 +4,29 @@ library testing.run_tests; -import 'dart:async' show - Future; +import 'dart:async' show Future; -import 'dart:io' show - Directory, - File, - FileSystemEntity; +import 'dart:io' show Directory, File, FileSystemEntity; -import 'dart:io' as io show - exitCode; +import 'dart:io' as io show exitCode; -import 'dart:isolate' show - Isolate; +import 'dart:isolate' show Isolate; -import 'error_handling.dart' show - withErrorHandling; +import 'error_handling.dart' show withErrorHandling; -import 'test_root.dart' show - TestRoot; +import 'test_root.dart' show TestRoot; -import 'zone_helper.dart' show - runGuarded; +import 'zone_helper.dart' show runGuarded; -import 'log.dart' show - enableVerboseOutput, - isVerbose, - logMessage, - logSuiteComplete, - logTestComplete; +import 'log.dart' + show + enableVerboseOutput, + isVerbose, + logMessage, + logSuiteComplete, + logTestComplete; -import 'run.dart' show - SuiteRunner, - runProgram; +import 'run.dart' show SuiteRunner, runProgram; class CommandLine { final Set options; @@ -97,12 +87,11 @@ class CommandLine { if (!await new File(configurationPath).exists()) { Directory test = new Directory("test"); if (await test.exists()) { - List candiates = - await test.list(recursive: true, followLinks: false) + List candiates = await test + .list(recursive: true, followLinks: false) .where((FileSystemEntity entity) { - return entity is File && - entity.uri.path.endsWith("/testing.json"); - }).toList(); + return entity is File && entity.uri.path.endsWith("/testing.json"); + }).toList(); switch (candiates.length) { case 0: return fail("Couldn't locate: '$configurationPath'."); @@ -137,8 +126,7 @@ class CommandLine { options = new Set.from(arguments.getRange(0, index - 1)); arguments = arguments.sublist(index + 1); } else { - options = - arguments.where((argument) => argument.startsWith("-")).toSet(); + options = arguments.where((argument) => argument.startsWith("-")).toSet(); arguments = arguments.where((argument) => !argument.startsWith("-")).toList(); } @@ -153,48 +141,48 @@ fail(String message) { } main(List arguments) => withErrorHandling(() async { - CommandLine cl = CommandLine.parse(arguments); - if (cl.verbose) { - enableVerboseOutput(); - } - Map environment = cl.environment; - Uri configuration = await cl.configuration; - if (configuration == null) return; - if (!isVerbose) { - print("Use --verbose to display more details."); - } - TestRoot root = await TestRoot.fromUri(configuration); - SuiteRunner runner = new SuiteRunner(root.suites, environment, cl.selectors, - cl.selectedSuites, cl.skip); - String program = await runner.generateDartProgram(); - bool hasAnalyzerSuites = await runner.analyze(root.packages); - Stopwatch sw = new Stopwatch()..start(); - if (program == null) { - if (!hasAnalyzerSuites) { - fail("No tests configured."); - } - } else { - await runProgram(program, root.packages); - } - print("Running tests took: ${sw.elapsed}."); -}); + CommandLine cl = CommandLine.parse(arguments); + if (cl.verbose) { + enableVerboseOutput(); + } + Map environment = cl.environment; + Uri configuration = await cl.configuration; + if (configuration == null) return; + if (!isVerbose) { + print("Use --verbose to display more details."); + } + TestRoot root = await TestRoot.fromUri(configuration); + SuiteRunner runner = new SuiteRunner( + root.suites, environment, cl.selectors, cl.selectedSuites, cl.skip); + String program = await runner.generateDartProgram(); + bool hasAnalyzerSuites = await runner.analyze(root.packages); + Stopwatch sw = new Stopwatch()..start(); + if (program == null) { + if (!hasAnalyzerSuites) { + fail("No tests configured."); + } + } else { + await runProgram(program, root.packages); + } + print("Running tests took: ${sw.elapsed}."); + }); Future runTests(Map tests) => -withErrorHandling(() async { - int completed = 0; - for (String name in tests.keys) { - StringBuffer sb = new StringBuffer(); - try { - await runGuarded(() { - print("Running test $name"); - return tests[name](); - }, printLineOnStdout: sb.writeln); - logMessage(sb); - } catch (e) { - print(sb); - rethrow; - } - logTestComplete(++completed, 0, tests.length, null, null); - } - logSuiteComplete(); -}); + withErrorHandling(() async { + int completed = 0; + for (String name in tests.keys) { + StringBuffer sb = new StringBuffer(); + try { + await runGuarded(() { + print("Running test $name"); + return tests[name](); + }, printLineOnStdout: sb.writeln); + logMessage(sb); + } catch (e) { + print(sb); + rethrow; + } + logTestComplete(++completed, 0, tests.length, null, null); + } + logSuiteComplete(); + }); diff --git a/pkg/testing/lib/src/stdio_process.dart b/pkg/testing/lib/src/stdio_process.dart index 35aa4e7794b..8f0f747f85e 100644 --- a/pkg/testing/lib/src/stdio_process.dart +++ b/pkg/testing/lib/src/stdio_process.dart @@ -4,27 +4,15 @@ library testing.stdio_process; -import 'dart:async' show - EventSink, - Future, - Stream, - StreamTransformer, - Timer; +import 'dart:async' show EventSink, Future, Stream, StreamTransformer, Timer; -import 'dart:convert' show - UTF8; +import 'dart:convert' show UTF8; -import 'dart:io' show - Process, - ProcessSignal, - Stdout; +import 'dart:io' show Process, ProcessSignal, Stdout; -import 'dart:io' as io show - stderr, - stdout; +import 'dart:io' as io show stderr, stdout; -import 'chain.dart' show - Result; +import 'chain.dart' show Result; class StdioProcess { final int exitCode; @@ -44,15 +32,15 @@ class StdioProcess { static StreamTransformer transformToStdio(Stdout stdio) { return new StreamTransformer.fromHandlers( handleData: (String data, EventSink sink) { - sink.add(data); - stdio.write(data); - }); + sink.add(data); + stdio.write(data); + }); } - static Future run( - String executable, List arguments, - {String input, Duration timeout: const Duration(seconds: 60), - bool suppressOutput: true}) async { + static Future run(String executable, List arguments, + {String input, + Duration timeout: const Duration(seconds: 60), + bool suppressOutput: true}) async { Process process = await Process.start(executable, arguments); Timer timer; StringBuffer sb = new StringBuffer(); diff --git a/pkg/testing/lib/src/suite.dart b/pkg/testing/lib/src/suite.dart index e8007b2d889..54aa7c8ca5f 100644 --- a/pkg/testing/lib/src/suite.dart +++ b/pkg/testing/lib/src/suite.dart @@ -4,11 +4,9 @@ library testing.suite; -import 'chain.dart' show - Chain; +import 'chain.dart' show Chain; -import 'test_dart.dart' show - TestDart; +import 'test_dart.dart' show TestDart; /// Records the properties of a test suite. abstract class Suite { @@ -79,10 +77,10 @@ class Dart extends Suite { factory Dart.fromJsonMap(Uri base, Map json, String name) { Uri uri = base.resolve(json["path"]); - List pattern = new List.from( - json["pattern"].map((String p) => new RegExp(p))); - List exclude = new List.from( - json["exclude"].map((String p) => new RegExp(p))); + List pattern = + new List.from(json["pattern"].map((String p) => new RegExp(p))); + List exclude = + new List.from(json["exclude"].map((String p) => new RegExp(p))); return new Dart(name, uri, pattern, exclude); } diff --git a/pkg/testing/lib/src/test_dart.dart b/pkg/testing/lib/src/test_dart.dart index 9b6ce7eb54d..b65ac3a5abe 100644 --- a/pkg/testing/lib/src/test_dart.dart +++ b/pkg/testing/lib/src/test_dart.dart @@ -4,14 +4,11 @@ library testing.test_dart; -import 'dart:convert' show - JSON; +import 'dart:convert' show JSON; -import 'dart:io' show - Platform; +import 'dart:io' show Platform; -import 'suite.dart' show - Suite; +import 'suite.dart' show Suite; /// A suite that runs test.dart. class TestDart extends Suite { @@ -22,10 +19,12 @@ class TestDart extends Suite { final List commandLines; TestDart(String name, this.common, this.processes, this.commandLines) - : super(name, "test_dart", - // This suite doesn't know what it's status file is because test.dart - // doesn't know. - null); + : super( + name, + "test_dart", + // This suite doesn't know what it's status file is because + // test.dart doesn't know. + null); factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { String common = json["common"] ?? ""; @@ -52,8 +51,9 @@ class TestDart extends Suite { throw "Operating system not supported: ${Platform.operatingSystem}"; } List processedArguments = []; - processedArguments.add(Uri.base.resolve( - "tools/testing/dart/package_testing_support.dart").toFilePath()); + processedArguments.add(Uri.base + .resolve("tools/testing/dart/package_testing_support.dart") + .toFilePath()); for (String commandLine in commandLines) { String arguments = common; arguments += " $processes"; 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 a7c00deb297..b16bd4c1f16 100644 --- a/pkg/testing/lib/src/test_dart/status_file_parser.dart +++ b/pkg/testing/lib/src/test_dart/status_file_parser.dart @@ -11,9 +11,7 @@ import "dart:io"; import "path.dart"; import "status_expression.dart"; -import '../expectation.dart' show - Expectation, - ExpectationSet; +import '../expectation.dart' show Expectation, ExpectationSet; final RegExp SplitComment = new RegExp("^([^#]*)(#.*)?\$"); final RegExp HeaderPattern = new RegExp(r"^\[([^\]]+)\]"); @@ -49,9 +47,8 @@ class Section { } } -Future ReadTestExpectations( - List statusFilePaths, Map environment, - ExpectationSet expectationSet) { +Future ReadTestExpectations(List statusFilePaths, + Map environment, ExpectationSet expectationSet) { var testExpectations = new TestExpectations(expectationSet); return Future.wait(statusFilePaths.map((String statusFile) { return ReadTestExpectationsInto(testExpectations, statusFile, environment); diff --git a/pkg/testing/lib/src/test_description.dart b/pkg/testing/lib/src/test_description.dart index 9b1c5b3169b..12e0b03394b 100644 --- a/pkg/testing/lib/src/test_description.dart +++ b/pkg/testing/lib/src/test_description.dart @@ -4,9 +4,7 @@ library testing.test_description; -import 'dart:io' show - File, - FileSystemEntity; +import 'dart:io' show File, FileSystemEntity; class TestDescription implements Comparable { final Uri root; @@ -44,8 +42,8 @@ class TestDescription implements Comparable { sink.writeln('.main,'); } - static TestDescription from( - Uri root, FileSystemEntity entity, {Pattern pattern}) { + static TestDescription 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 4729de526d5..795d285fd44 100644 --- a/pkg/testing/lib/src/test_root.dart +++ b/pkg/testing/lib/src/test_root.dart @@ -4,24 +4,17 @@ library testing.test_root; -import 'dart:async' show - Future; +import 'dart:async' show Future; -import 'dart:convert' show - JSON; +import 'dart:convert' show JSON; -import 'dart:io' show - File; +import 'dart:io' show File; -import '../testing.dart' show - Chain; +import '../testing.dart' show Chain; -import 'analyze.dart' show - Analyze; +import 'analyze.dart' show Analyze; -import 'suite.dart' show - Dart, - Suite; +import 'suite.dart' show Dart, Suite; /// Records properties of a test root. The information is read from a JSON file. /// @@ -63,13 +56,11 @@ class TestRoot { List get excludedFromAnalysis => analyze.exclude; Iterable get dartSuites { - return new List.from( - suites.where((Suite suite) => suite is Dart)); + return new List.from(suites.where((Suite suite) => suite is Dart)); } Iterable get toolChains { - return new List.from( - suites.where((Suite suite) => suite is Chain)); + return new List.from(suites.where((Suite suite) => suite is Chain)); } String toString() { diff --git a/pkg/testing/lib/src/zone_helper.dart b/pkg/testing/lib/src/zone_helper.dart index 0429260ed66..e679e63b1f5 100644 --- a/pkg/testing/lib/src/zone_helper.dart +++ b/pkg/testing/lib/src/zone_helper.dart @@ -5,29 +5,17 @@ /// Helper functions for running code in a Zone. library testing.zone_helper; -import 'dart:async' show - Completer, - Future, - ZoneSpecification, - runZoned; +import 'dart:async' show Completer, Future, ZoneSpecification, runZoned; -import 'dart:io' show - exit, - stderr; +import 'dart:io' show exit, stderr; -import 'dart:isolate' show - Capability, - Isolate, - ReceivePort; +import 'dart:isolate' show Capability, Isolate, ReceivePort; -import 'log.dart' show - logUncaughtError; +import 'log.dart' show logUncaughtError; -Future runGuarded( - Future f(), +Future runGuarded(Future f(), {void printLineOnStdout(line), - void handleLateError(error, StackTrace stackTrace)}) { - + void handleLateError(error, StackTrace stackTrace)}) { var printWrapper; if (printLineOnStdout != null) { printWrapper = (_1, _2, _3, String line) { @@ -50,8 +38,8 @@ Future runGuarded( } catch (_) { // Ignored. } - stderr.write("$errorString\n" + - (stackTrace == null ? "" : "$stackTrace")); + stderr + .write("$errorString\n" + (stackTrace == null ? "" : "$stackTrace")); stderr.flush(); exit(255); } @@ -74,10 +62,8 @@ Future runGuarded( Isolate.current.setErrorsFatal(false); Isolate.current.addErrorListener(errorPort.sendPort); return acknowledgeControlMessages(Isolate.current).then((_) { - runZoned( - () => new Future(f).then(completer.complete), - zoneSpecification: specification, - onError: handleUncaughtError); + runZoned(() => new Future(f).then(completer.complete), + zoneSpecification: specification, onError: handleUncaughtError); return completer.future.whenComplete(() { errorPort.close(); diff --git a/pkg/testing/lib/testing.dart b/pkg/testing/lib/testing.dart index 6145d6b0268..3934ef105bf 100644 --- a/pkg/testing/lib/testing.dart +++ b/pkg/testing/lib/testing.dart @@ -4,26 +4,16 @@ library testing; -export 'dart:async' show - Future; +export 'dart:async' show Future; export 'src/discover.dart'; export 'src/test_description.dart'; -export 'src/chain.dart' show - Chain, - ChainContext, - Result, - Step; +export 'src/chain.dart' show Chain, ChainContext, Result, Step; -export 'src/stdio_process.dart' show - StdioProcess; +export 'src/stdio_process.dart' show StdioProcess; -export 'src/run.dart' show - run, - runMe; +export 'src/run.dart' show run, runMe; -export 'src/expectation.dart' show - Expectation, - ExpectationSet; +export 'src/expectation.dart' show Expectation, ExpectationSet; diff --git a/pkg/typed_mock/lib/typed_mock.dart b/pkg/typed_mock/lib/typed_mock.dart index 180ff2773ed..c91854c43a5 100644 --- a/pkg/typed_mock/lib/typed_mock.dart +++ b/pkg/typed_mock/lib/typed_mock.dart @@ -1,6 +1,5 @@ library typed_mock; - _InvocationMatcher _lastMatcher; /// Enables stubbing methods. @@ -39,14 +38,12 @@ Behavior when(_ignored) { } } - /// Clears all interactions remembered so far. resetInteractions(TypedMock mock) { mock._invocations.clear(); mock._verifiedInvocations.clear(); } - /// Verifies certain behavior happened a specified number of times. Verifier verify(_ignored) { try { @@ -60,7 +57,6 @@ Verifier verify(_ignored) { } } - /// Verifies that the given mock doesn't have any unverified interaction. void verifyNoMoreInteractions(TypedMock mock) { var notVerified = mock._computeNotVerifiedInvocations(); @@ -73,7 +69,6 @@ void verifyNoMoreInteractions(TypedMock mock) { throw new VerifyError('Unexpected interactions:\n$invocationsString'); } - /// Verifies that no interactions happened on the given mock. void verifyZeroInteractions(TypedMock mock) { var invocations = mock._invocations; @@ -86,7 +81,6 @@ void verifyZeroInteractions(TypedMock mock) { throw new VerifyError('Unexpected interactions:\n$invocationsString'); } - /// [VerifyError] is thrown when one of the [verify] checks fails. class VerifyError { final String message; @@ -94,7 +88,6 @@ class VerifyError { String toString() => 'VerifyError: $message'; } - String _getInvocationsString(Iterable invocations) { var buffer = new StringBuffer(); invocations.forEach((invocation) { @@ -109,7 +102,6 @@ String _getInvocationsString(Iterable invocations) { return buffer.toString(); } - class _InvocationMatcher { final Symbol _member; final TypedMock _mock; @@ -145,7 +137,6 @@ class _InvocationMatcher { } } - class Behavior { final _InvocationMatcher _matcher; @@ -232,7 +223,6 @@ class Behavior { } } - class Verifier { final TypedMock _mock; final _InvocationMatcher _matcher; @@ -313,7 +303,6 @@ class Verifier { } } - /// A class to extend mocks from. /// It supports specifying behavior using [when] and validation of interactions /// using [verify]. @@ -368,7 +357,6 @@ class TypedMock { } } - /// [ArgumentMatcher] checks whether the given argument satisfies some /// condition. abstract class ArgumentMatcher { @@ -378,7 +366,6 @@ abstract class ArgumentMatcher { bool matches(val); } - class _ArgumentMatcher_equals extends ArgumentMatcher { final expected; @@ -390,7 +377,6 @@ class _ArgumentMatcher_equals extends ArgumentMatcher { } } - class _ArgumentMatcher_anyBool extends ArgumentMatcher { const _ArgumentMatcher_anyBool(); @@ -403,7 +389,6 @@ class _ArgumentMatcher_anyBool extends ArgumentMatcher { /// Matches any [bool] value. final anyBool = const _ArgumentMatcher_anyBool() as dynamic; - class _ArgumentMatcher_anyInt extends ArgumentMatcher { const _ArgumentMatcher_anyInt(); @@ -416,7 +401,6 @@ class _ArgumentMatcher_anyInt extends ArgumentMatcher { /// Matches any [int] value. final anyInt = const _ArgumentMatcher_anyInt() as dynamic; - class _ArgumentMatcher_anyObject extends ArgumentMatcher { const _ArgumentMatcher_anyObject(); @@ -429,7 +413,6 @@ class _ArgumentMatcher_anyObject extends ArgumentMatcher { /// Matches any [Object] (or subclass) value. final anyObject = const _ArgumentMatcher_anyObject() as dynamic; - class _ArgumentMatcher_anyString extends ArgumentMatcher { const _ArgumentMatcher_anyString(); diff --git a/pkg/typed_mock/test/typed_mock_test.dart b/pkg/typed_mock/test/typed_mock_test.dart index 9585673bc62..22bddd998ff 100644 --- a/pkg/typed_mock/test/typed_mock_test.dart +++ b/pkg/typed_mock/test/typed_mock_test.dart @@ -4,7 +4,6 @@ import 'package:unittest/unittest.dart'; import 'package:typed_mock/typed_mock.dart'; - abstract class TestInterface { int get testProperty; set testProperty(x); @@ -16,12 +15,10 @@ abstract class TestInterface { int operator [](index); } - class TestInterfaceMock extends TypedMock implements TestInterface { noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } - main() { // lets make it redable groupSep = ' | '; @@ -231,11 +228,11 @@ main() { verify(obj.testProperty).times(2); }); - test('OK, void method', () { - obj.testMethodVoid(10); - obj.testMethodVoid(20); - verify(obj.testMethodVoid(anyInt)).times(2); - }); + test('OK, void method', () { + obj.testMethodVoid(10); + obj.testMethodVoid(20); + verify(obj.testMethodVoid(anyInt)).times(2); + }); test('mismatch, getter', () { obj.testProperty;