From 1bf06fbc3736f07faba59e04bf243ad6d2797c35 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 21 Feb 2018 14:11:49 -0800 Subject: [PATCH 1/4] Fix PlatformPlugin's documentation --- lib/src/runner/plugin/platform.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/runner/plugin/platform.dart b/lib/src/runner/plugin/platform.dart index 465511a7c..475b6a885 100644 --- a/lib/src/runner/plugin/platform.dart +++ b/lib/src/runner/plugin/platform.dart @@ -15,10 +15,9 @@ import 'platform_helpers.dart'; /// A class that defines a platform for which test suites can be loaded. /// -/// A minimal plugin must define [platforms], which indicates the platforms it -/// supports, and [loadChannel], which connects to a client in which the tests -/// are defined. This is enough to support most of the test runner's -/// functionality. +/// A minimal plugin must define [loadChannel], which connects to a client in +/// which the tests are defined. This is enough to support most of the test +/// runner's functionality. /// /// In order to support interactive debugging, a plugin must override [load] as /// well, which returns a [RunnerSuite] that can contain a custom [Environment] @@ -26,7 +25,8 @@ import 'platform_helpers.dart'; /// [RunnerSuite.onDebugging]. The plugin must create this suite by calling the /// [deserializeSuite] helper function. /// -/// A platform plugin can be registered with [Loader.registerPlatformPlugin]. +/// A platform plugin can be registered by passing it to [new Loader]'s +/// `plugins` parameter. abstract class PlatformPlugin { /// Loads and establishes a connection with the test file at [path] using /// [platform]. @@ -41,7 +41,8 @@ abstract class PlatformPlugin { /// indicates that the suite is no longer needed and its resources may be /// released. /// - /// The [platform] is guaranteed to be a member of [platforms]. + /// The [platform] is guaranteed to be one of the platforms associated with + /// this plugin in [new Loader]'s `plugins` parameter. StreamChannel loadChannel(String path, TestPlatform platform); /// Loads the runner suite for the test file at [path] using [platform], with From decc01db94c0128995a74db1cbd11bc8c14dc1be Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 21 Feb 2018 16:51:40 -0800 Subject: [PATCH 2/4] Add a SuitePlatform class This encapsulates all the information about the platform on which a suite runs, and which platform selectors can select for. Currently it just includes the runtime and the operating system, but eventually it could include whether we're running internally to Google, or which compiler is in use. --- lib/src/backend/group.dart | 11 +++--- lib/src/backend/group_entry.dart | 8 ++-- lib/src/backend/invoker.dart | 11 +++--- lib/src/backend/metadata.dart | 7 ++-- lib/src/backend/platform_selector.dart | 21 +++++----- lib/src/backend/suite.dart | 33 ++++------------ lib/src/backend/suite_platform.dart | 43 +++++++++++++++++++++ lib/src/backend/test.dart | 5 +-- lib/src/runner.dart | 11 ++++-- lib/src/runner/browser/browser_manager.dart | 5 ++- lib/src/runner/browser/platform.dart | 10 +++-- lib/src/runner/configuration/suite.dart | 6 +-- lib/src/runner/debugger.dart | 13 ++++--- lib/src/runner/load_suite.dart | 35 +++++++++-------- lib/src/runner/loader.dart | 28 ++++++++------ lib/src/runner/node/platform.dart | 9 +++-- lib/src/runner/plugin/platform.dart | 10 ++--- lib/src/runner/plugin/platform_helpers.dart | 12 ++---- lib/src/runner/remote_listener.dart | 8 +--- lib/src/runner/reporter/compact.dart | 2 +- lib/src/runner/reporter/expanded.dart | 2 +- lib/src/runner/reporter/json.dart | 6 +-- lib/src/runner/runner_suite.dart | 31 ++++++--------- lib/src/runner/runner_test.dart | 9 ++--- lib/src/runner/vm/platform.dart | 5 ++- lib/test.dart | 12 +++--- test/backend/declarer_test.dart | 2 +- test/backend/invoker_test.dart | 2 +- test/backend/metadata_test.dart | 9 +++-- test/runner/browser/loader_test.dart | 6 +-- test/runner/load_suite_test.dart | 33 ++++++++-------- test/runner/loader_test.dart | 2 +- test/runner/parse_metadata_test.dart | 21 ++++++---- test/utils.dart | 18 ++++++--- 34 files changed, 240 insertions(+), 206 deletions(-) create mode 100644 lib/src/backend/suite_platform.dart diff --git a/lib/src/backend/group.dart b/lib/src/backend/group.dart index a8d7f71f4..b563260a6 100644 --- a/lib/src/backend/group.dart +++ b/lib/src/backend/group.dart @@ -6,9 +6,8 @@ import 'package:stack_trace/stack_trace.dart'; import 'group_entry.dart'; import 'metadata.dart'; -import 'operating_system.dart'; +import 'suite_platform.dart'; import 'test.dart'; -import 'test_platform.dart'; /// A group contains one or more tests and subgroups. /// @@ -52,10 +51,10 @@ class Group implements GroupEntry { : entries = new List.unmodifiable(entries), metadata = metadata == null ? new Metadata() : metadata; - Group forPlatform(TestPlatform platform, {OperatingSystem os}) { - if (!metadata.testOn.evaluate(platform, os: os)) return null; - var newMetadata = metadata.forPlatform(platform, os: os); - var filtered = _map((entry) => entry.forPlatform(platform, os: os)); + Group forPlatform(SuitePlatform platform) { + if (!metadata.testOn.evaluate(platform)) return null; + var newMetadata = metadata.forPlatform(platform); + var filtered = _map((entry) => entry.forPlatform(platform)); if (filtered.isEmpty && entries.isNotEmpty) return null; return new Group(name, filtered, metadata: newMetadata, diff --git a/lib/src/backend/group_entry.dart b/lib/src/backend/group_entry.dart index bde401eea..2d2a341c3 100644 --- a/lib/src/backend/group_entry.dart +++ b/lib/src/backend/group_entry.dart @@ -5,9 +5,8 @@ import 'package:stack_trace/stack_trace.dart'; import 'metadata.dart'; -import 'operating_system.dart'; +import 'suite_platform.dart'; import 'test.dart'; -import 'test_platform.dart'; /// A [Test] or [Group]. abstract class GroupEntry { @@ -28,9 +27,8 @@ abstract class GroupEntry { /// Returns a copy of [this] with all platform-specific metadata resolved. /// /// Removes any tests and groups with [Metadata.testOn] selectors that don't - /// match [platform] and [selector]. Returns `null` if this entry's selector - /// doesn't match. - GroupEntry forPlatform(TestPlatform platform, {OperatingSystem os}); + /// match [platform]. Returns `null` if this entry's selector doesn't match. + GroupEntry forPlatform(SuitePlatform platform); /// Returns a copy of [this] with all tests that don't match [callback] /// removed. diff --git a/lib/src/backend/invoker.dart b/lib/src/backend/invoker.dart index 02838865a..ff114e57f 100644 --- a/lib/src/backend/invoker.dart +++ b/lib/src/backend/invoker.dart @@ -16,12 +16,11 @@ import 'live_test.dart'; import 'live_test_controller.dart'; import 'message.dart'; import 'metadata.dart'; -import 'operating_system.dart'; import 'outstanding_callback_counter.dart'; import 'state.dart'; import 'suite.dart'; +import 'suite_platform.dart'; import 'test.dart'; -import 'test_platform.dart'; /// A test in this isolate. class LocalTest extends Test { @@ -57,10 +56,10 @@ class LocalTest extends Test { return invoker.liveTest; } - Test forPlatform(TestPlatform platform, {OperatingSystem os}) { - if (!metadata.testOn.evaluate(platform, os: os)) return null; - return new LocalTest._(name, metadata.forPlatform(platform, os: os), _body, - trace, _guarded, isScaffoldAll); + Test forPlatform(SuitePlatform platform) { + if (!metadata.testOn.evaluate(platform)) return null; + return new LocalTest._(name, metadata.forPlatform(platform), _body, trace, + _guarded, isScaffoldAll); } } diff --git a/lib/src/backend/metadata.dart b/lib/src/backend/metadata.dart index 7ff1a8624..83929b653 100644 --- a/lib/src/backend/metadata.dart +++ b/lib/src/backend/metadata.dart @@ -10,9 +10,8 @@ import 'package:collection/collection.dart'; import '../frontend/skip.dart'; import '../frontend/timeout.dart'; import '../utils.dart'; -import 'operating_system.dart'; import 'platform_selector.dart'; -import 'test_platform.dart'; +import 'suite_platform.dart'; /// Metadata for a test or test suite. /// @@ -353,12 +352,12 @@ class Metadata { /// Returns a copy of [this] with all platform-specific metadata from /// [onPlatform] resolved. - Metadata forPlatform(TestPlatform platform, {OperatingSystem os}) { + Metadata forPlatform(SuitePlatform platform) { if (onPlatform.isEmpty) return this; var metadata = this; onPlatform.forEach((platformSelector, platformMetadata) { - if (!platformSelector.evaluate(platform, os: os)) return; + if (!platformSelector.evaluate(platform)) return; metadata = metadata.merge(platformMetadata); }); return metadata.change(onPlatform: {}); diff --git a/lib/src/backend/platform_selector.dart b/lib/src/backend/platform_selector.dart index d6da9f424..3ea9b4aa0 100644 --- a/lib/src/backend/platform_selector.dart +++ b/lib/src/backend/platform_selector.dart @@ -6,6 +6,7 @@ import 'package:boolean_selector/boolean_selector.dart'; import 'package:source_span/source_span.dart'; import 'operating_system.dart'; +import 'suite_platform.dart'; import 'test_platform.dart'; /// The set of variable names that are valid for all platform selectors. @@ -71,24 +72,22 @@ class PlatformSelector { /// Returns whether the selector matches the given [platform] and [os]. /// /// [os] defaults to [OperatingSystem.none]. - bool evaluate(TestPlatform platform, {OperatingSystem os}) { - os ??= OperatingSystem.none; - + bool evaluate(SuitePlatform platform) { return _inner.evaluate((variable) { - if (variable == platform.identifier) return true; - if (variable == platform.parent?.identifier) return true; - if (variable == os.identifier) return true; + if (variable == platform.platform.identifier) return true; + if (variable == platform.platform.parent?.identifier) return true; + if (variable == platform.os.identifier) return true; switch (variable) { case "dart-vm": - return platform.isDartVM; + return platform.platform.isDartVM; case "browser": - return platform.isBrowser; + return platform.platform.isBrowser; case "js": - return platform.isJS; + return platform.platform.isJS; case "blink": - return platform.isBlink; + return platform.platform.isBlink; case "posix": - return os.isPosix; + return platform.os.isPosix; default: return false; } diff --git a/lib/src/backend/suite.dart b/lib/src/backend/suite.dart index 28469935c..c5ad12607 100644 --- a/lib/src/backend/suite.dart +++ b/lib/src/backend/suite.dart @@ -4,24 +4,16 @@ import 'group.dart'; import 'metadata.dart'; -import 'operating_system.dart'; +import 'suite_platform.dart'; import 'test.dart'; -import 'test_platform.dart'; /// A test suite. /// /// A test suite is a set of tests that are intended to be run together and that /// share default configuration. class Suite { - /// The platform on which the suite is running, or `null` if that platform is - /// unknown. - final TestPlatform platform; - - /// The operating system on which the suite is running, or `null` if that - /// operating system is unknown. - /// - /// This will always be `null` if [platform] is `null`. - final OperatingSystem os; + /// The platform on which the suite is running. + final SuitePlatform platform; /// The path to the Dart test suite, or `null` if that path is unknown. final String path; @@ -40,23 +32,14 @@ class Suite { /// platform information. /// /// If [os] is passed without [platform], throws an [ArgumentError]. - Suite(Group group, {this.path, TestPlatform platform, OperatingSystem os}) - : platform = platform, - os = os, - group = _filterGroup(group, platform, os); + Suite(Group group, this.platform, {this.path}) + : group = _filterGroup(group, platform); /// Returns [entries] filtered according to [platform] and [os]. /// /// Gracefully handles [platform] being null. - static Group _filterGroup( - Group group, TestPlatform platform, OperatingSystem os) { - if (platform == null && os != null) { - throw new ArgumentError.value( - null, "os", "If os is passed, platform must be passed as well"); - } - - if (platform == null) return group; - var filtered = group.forPlatform(platform, os: os); + static Group _filterGroup(Group group, SuitePlatform platform) { + var filtered = group.forPlatform(platform); if (filtered != null) return filtered; return new Group.root([], metadata: group.metadata); } @@ -68,6 +51,6 @@ class Suite { Suite filter(bool callback(Test test)) { var filtered = group.filter(callback); if (filtered == null) filtered = new Group.root([], metadata: metadata); - return new Suite(filtered, platform: platform, os: os, path: path); + return new Suite(filtered, platform, path: path); } } diff --git a/lib/src/backend/suite_platform.dart b/lib/src/backend/suite_platform.dart new file mode 100644 index 000000000..9449ade77 --- /dev/null +++ b/lib/src/backend/suite_platform.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'operating_system.dart'; +import 'test_platform.dart'; + +/// The platform on which a test suite is loaded. +class SuitePlatform { + /// The platform on which the suite is running. + final TestPlatform platform; + + /// The operating system on which the suite is running. + /// + /// This will always be [OperatingSystem.none] if `platform.isBrowser` is + /// true. + final OperatingSystem os; + + /// Creates a new platform with the given [platform] and [os], which defaults + /// to [OperatingSystem.none]. + /// + /// Throws an [ArgumentError] if [platform] is a browser and [os] is not + /// `null` or [OperatingSystem.none]. + SuitePlatform(this.platform, {OperatingSystem os}) + : os = os ?? OperatingSystem.none { + if (platform.isBrowser && this.os != OperatingSystem.none) { + throw new ArgumentError( + 'No OS should be passed for platform "$platform".'); + } + } + + /// Converts a JSON-safe representation generated by [serialize] back into a + /// [SuitePlatform]. + factory SuitePlatform.deserialize(Object serialized) { + var map = serialized as Map; + return new SuitePlatform(new TestPlatform.deserialize(map['platform']), + os: OperatingSystem.find(map['os'])); + } + + /// Converts [this] into a JSON-safe object that can be converted back to a + /// [SuitePlatform] using [new SuitePlatform.deserialize]. + Object serialize() => {'platform': platform.serialize(), 'os': os.identifier}; +} diff --git a/lib/src/backend/test.dart b/lib/src/backend/test.dart index 62b12aea9..07df8c385 100644 --- a/lib/src/backend/test.dart +++ b/lib/src/backend/test.dart @@ -8,9 +8,8 @@ import 'group.dart'; import 'group_entry.dart'; import 'live_test.dart'; import 'metadata.dart'; -import 'operating_system.dart'; import 'suite.dart'; -import 'test_platform.dart'; +import 'suite_platform.dart'; /// A single test. /// @@ -32,7 +31,7 @@ abstract class Test implements GroupEntry { /// defaults to just containing `suite.group`. LiveTest load(Suite suite, {Iterable groups}); - Test forPlatform(TestPlatform platform, {OperatingSystem os}); + Test forPlatform(SuitePlatform platform); Test filter(bool callback(Test test)) => callback(this) ? this : null; } diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 91a444e97..2910c5917 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -12,6 +12,7 @@ import 'backend/group_entry.dart'; import 'backend/operating_system.dart'; import 'backend/platform_selector.dart'; import 'backend/suite.dart'; +import 'backend/suite_platform.dart'; import 'backend/test.dart'; import 'backend/test_platform.dart'; import 'runner/application_exception.dart'; @@ -130,7 +131,9 @@ class Runner { var unsupportedPlatforms = _config.suiteDefaults.platforms .map(_loader.findTestPlatform) .where((platform) => - platform != null && !testOn.evaluate(platform, os: currentOS)) + platform != null && + !testOn.evaluate(new SuitePlatform(platform, + os: platform.isBrowser ? null : currentOS))) .toList(); if (unsupportedPlatforms.isEmpty) return; @@ -145,7 +148,7 @@ class Runner { if (unsupportedBrowsers.isNotEmpty) { var supportsAnyBrowser = _loader.allPlatforms .where((platform) => platform.isBrowser) - .any((platform) => testOn.evaluate(platform)); + .any((platform) => testOn.evaluate(new SuitePlatform(platform))); if (supportsAnyBrowser) { unsupportedNames @@ -158,8 +161,8 @@ class Runner { // If the user tried to run on the VM and it's not supported, figure out if // that's because of the current OS or whether the VM is unsupported. if (unsupportedPlatforms.contains(TestPlatform.vm)) { - var supportsAnyOS = OperatingSystem.all - .any((os) => testOn.evaluate(TestPlatform.vm, os: os)); + var supportsAnyOS = OperatingSystem.all.any( + (os) => testOn.evaluate(new SuitePlatform(TestPlatform.vm, os: os))); if (supportsAnyOS) { unsupportedNames.add(currentOS.name); diff --git a/lib/src/runner/browser/browser_manager.dart b/lib/src/runner/browser/browser_manager.dart index cee1fd9a4..bd282655d 100644 --- a/lib/src/runner/browser/browser_manager.dart +++ b/lib/src/runner/browser/browser_manager.dart @@ -10,6 +10,7 @@ import 'package:pool/pool.dart'; import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test_platform.dart'; import '../../util/stack_trace_mapper.dart'; import '../application_exception.dart'; @@ -241,8 +242,8 @@ class BrowserManager { }); try { - controller = deserializeSuite(path, _platform, suiteConfig, - await _environment, suiteChannel, message); + controller = deserializeSuite(path, new SuitePlatform(_platform), + suiteConfig, await _environment, suiteChannel, message); controller.channel("test.browser.mapper").sink.add(mapper?.serialize()); diff --git a/lib/src/runner/browser/platform.dart b/lib/src/runner/browser/platform.dart index 4b040c48e..59ab1e8e8 100644 --- a/lib/src/runner/browser/platform.dart +++ b/lib/src/runner/browser/platform.dart @@ -21,6 +21,7 @@ import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:yaml/yaml.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test_platform.dart'; import '../../util/io.dart'; import '../../util/one_off_handler.dart'; @@ -223,12 +224,13 @@ class BrowserPlatform extends PlatformPlugin _browserSettings[platform] = settings; } - /// Loads the test suite at [path] on the browser [browser]. + /// Loads the test suite at [path] on the platform [platform]. /// /// This will start a browser to load the suite if one isn't already running. - /// Throws an [ArgumentError] if [browser] isn't a browser platform. - Future load(String path, TestPlatform browser, + /// Throws an [ArgumentError] if `platform.platform` isn't a browser. + Future load(String path, SuitePlatform platform, SuiteConfiguration suiteConfig, Object message) async { + var browser = platform.platform; assert(suiteConfig.platforms.contains(browser.identifier)); if (!browser.isBrowser) { @@ -321,7 +323,7 @@ class BrowserPlatform extends PlatformPlugin return new File(htmlPath).existsSync(); } - StreamChannel loadChannel(String path, TestPlatform platform) => + StreamChannel loadChannel(String path, SuitePlatform platform) => throw new UnimplementedError(); /// Loads a test suite at [path] from the `pub serve` URL [dartUrl]. diff --git a/lib/src/runner/configuration/suite.dart b/lib/src/runner/configuration/suite.dart index 6ed34586c..bae435829 100644 --- a/lib/src/runner/configuration/suite.dart +++ b/lib/src/runner/configuration/suite.dart @@ -7,8 +7,8 @@ import 'package:collection/collection.dart'; import 'package:source_span/source_span.dart'; import '../../backend/metadata.dart'; -import '../../backend/operating_system.dart'; import '../../backend/platform_selector.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test_platform.dart'; import '../../frontend/timeout.dart'; import 'platform_selection.dart'; @@ -319,12 +319,12 @@ class SuiteConfiguration { /// Returns a copy of [this] with all platform-specific configuration from /// [onPlatform] resolved. - SuiteConfiguration forPlatform(TestPlatform platform, {OperatingSystem os}) { + SuiteConfiguration forPlatform(SuitePlatform platform) { if (onPlatform.isEmpty) return this; var config = this; onPlatform.forEach((platformSelector, platformConfig) { - if (!platformSelector.evaluate(platform, os: os)) return; + if (!platformSelector.evaluate(platform)) return; config = config.merge(platformConfig); }); return config.change(onPlatform: {}); diff --git a/lib/src/runner/debugger.dart b/lib/src/runner/debugger.dart index 9a7a1c709..21cfc25f5 100644 --- a/lib/src/runner/debugger.dart +++ b/lib/src/runner/debugger.dart @@ -132,17 +132,18 @@ class _Debugger { var noColor = _config.color ? '\u001b[0m' : ''; print(''); - if (_suite.platform.isDartVM) { + var platform = _suite.platform.platform; + if (platform.isDartVM) { var url = _suite.environment.observatoryUrl; if (url == null) { print("${yellow}Observatory URL not found. Make sure you're using " - "${_suite.platform.name} 1.11 or later.$noColor"); + "${platform.name} 1.11 or later.$noColor"); } else { print("Observatory URL: $bold$url$noColor"); } } - if (_suite.platform.isHeadless) { + if (platform.isHeadless) { var url = _suite.environment.remoteDebuggerUrl; if (url == null) { print("${yellow}Remote debugger URL not found.$noColor"); @@ -153,12 +154,12 @@ class _Debugger { var buffer = new StringBuffer("${bold}The test runner is paused.${noColor} "); - if (!_suite.platform.isHeadless) { - buffer.write("Open the dev console in ${_suite.platform} "); + if (!platform.isHeadless) { + buffer.write("Open the dev console in $platform "); } else { buffer.write("Open the remote debugger "); } - if (_suite.platform.isDartVM) buffer.write("or the Observatory "); + if (platform.isDartVM) buffer.write("or the Observatory "); buffer.write("and set breakpoints. Once you're finished, return to " "this terminal and press Enter."); diff --git a/lib/src/runner/load_suite.dart b/lib/src/runner/load_suite.dart index 6f4b48a02..85d28dd98 100644 --- a/lib/src/runner/load_suite.dart +++ b/lib/src/runner/load_suite.dart @@ -12,8 +12,10 @@ import '../backend/group.dart'; import '../backend/invoker.dart'; import '../backend/metadata.dart'; import '../backend/suite.dart'; +import '../backend/suite_platform.dart'; import '../backend/test.dart'; import '../backend/test_platform.dart'; +import '../util/io.dart'; import '../utils.dart'; import 'configuration/suite.dart'; import 'load_exception.dart'; @@ -75,11 +77,11 @@ class LoadSuite extends Suite implements RunnerSuite { /// /// If the the load test is closed before [body] is complete, it will close /// the suite returned by [body] once it completes. - factory LoadSuite( - String name, SuiteConfiguration config, FutureOr body(), - {String path, TestPlatform platform}) { + factory LoadSuite(String name, SuiteConfiguration config, + SuitePlatform platform, FutureOr body(), + {String path}) { var completer = new Completer>.sync(); - return new LoadSuite._(name, config, () { + return new LoadSuite._(name, config, platform, () { var invoker = Invoker.current; invoker.addOutstandingCallback(); @@ -107,7 +109,7 @@ class LoadSuite extends Suite implements RunnerSuite { // If the test is forcibly closed, let it complete, since load tests don't // have timeouts. invoker.onClose.then((_) => invoker.removeOutstandingCallback()); - }, completer.future, path: path, platform: platform); + }, completer.future, path: path); } /// A utility constructor for a load suite that just throws [exception]. @@ -115,43 +117,44 @@ class LoadSuite extends Suite implements RunnerSuite { /// The suite's name will be based on [exception]'s path. factory LoadSuite.forLoadException( LoadException exception, SuiteConfiguration config, - {StackTrace stackTrace, TestPlatform platform}) { + {SuitePlatform platform, StackTrace stackTrace}) { if (stackTrace == null) stackTrace = new Trace.current(); return new LoadSuite( "loading ${exception.path}", config ?? SuiteConfiguration.empty, + platform ?? new SuitePlatform(TestPlatform.vm, os: currentOS), () => new Future.error(exception, stackTrace), - path: exception.path, - platform: platform); + path: exception.path); } /// A utility constructor for a load suite that just emits [suite]. factory LoadSuite.forSuite(RunnerSuite suite) { - return new LoadSuite("loading ${suite.path}", suite.config, () => suite, - path: suite.path, platform: suite.platform); + return new LoadSuite( + "loading ${suite.path}", suite.config, suite.platform, () => suite, + path: suite.path); } - LoadSuite._(String name, this.config, void body(), this._suiteAndZone, - {String path, TestPlatform platform}) + LoadSuite._(String name, this.config, SuitePlatform platform, void body(), + this._suiteAndZone, {String path}) : super( new Group.root([ new LocalTest( name, new Metadata(timeout: new Timeout(_timeout)), body) ]), - path: path, - platform: platform); + platform, + path: path); /// A constructor used by [changeSuite]. LoadSuite._changeSuite(LoadSuite old, this._suiteAndZone) : config = old.config, - super(old.group, path: old.path, platform: old.platform); + super(old.group, old.platform, path: old.path); /// A constructor used by [filter]. LoadSuite._filtered(LoadSuite old, Group filtered) : config = old.config, _suiteAndZone = old._suiteAndZone, - super(old.group, path: old.path, platform: old.platform); + super(old.group, old.platform, path: old.path); /// Creates a new [LoadSuite] that's identical to this one, but that /// transforms [suite] once it's loaded. diff --git a/lib/src/runner/loader.dart b/lib/src/runner/loader.dart index fd9929e1a..a9b97178c 100644 --- a/lib/src/runner/loader.dart +++ b/lib/src/runner/loader.dart @@ -13,6 +13,7 @@ import 'package:yaml/yaml.dart'; import '../backend/group.dart'; import '../backend/invoker.dart'; +import '../backend/suite_platform.dart'; import '../backend/test_platform.dart'; import '../util/io.dart'; import 'browser/platform.dart'; @@ -224,14 +225,16 @@ class Loader { } for (var platformName in suiteConfig.platforms) { - var platform = findTestPlatform(platformName); - assert(platform != null, 'Unknown platform "$platformName".'); + var runtime = findTestPlatform(platformName); + assert(runtime != null, 'Unknown platform "$platformName".'); - if (!suiteConfig.metadata.testOn.evaluate(platform, os: currentOS)) { + var platform = + new SuitePlatform(runtime, os: runtime.isBrowser ? null : currentOS); + if (!suiteConfig.metadata.testOn.evaluate(platform)) { continue; } - var platformConfig = suiteConfig.forPlatform(platform, os: currentOS); + var platformConfig = suiteConfig.forPlatform(platform); // Don't load a skipped suite. if (platformConfig.metadata.skip && !platformConfig.runSkipped) { @@ -241,18 +244,19 @@ class Loader { new Group.root( [new LocalTest("(suite)", platformConfig.metadata, () {})], metadata: platformConfig.metadata), - path: path, - platform: platform)); + platform, + path: path)); continue; } - var name = (platform.isJS ? "compiling " : "loading ") + path; - yield new LoadSuite(name, platformConfig, () async { - var memo = _platformPlugins[platform]; + var name = (platform.platform.isJS ? "compiling " : "loading ") + path; + yield new LoadSuite(name, platformConfig, platform, () async { + var memo = _platformPlugins[platform.platform]; try { - var plugin = await memo.runOnce(_platformCallbacks[platform]); - _customizePlatform(plugin, platform); + var plugin = + await memo.runOnce(_platformCallbacks[platform.platform]); + _customizePlatform(plugin, platform.platform); var suite = await plugin.load(path, platform, platformConfig, {"platformVariables": _platformVariables.toList()}); if (suite != null) _suites.add(suite); @@ -262,7 +266,7 @@ class Loader { await new Future.error(new LoadException(path, error), stackTrace); return null; } - }, path: path, platform: platform); + }, path: path); } } diff --git a/lib/src/runner/node/platform.dart b/lib/src/runner/node/platform.dart index f4912992d..92c0ca513 100644 --- a/lib/src/runner/node/platform.dart +++ b/lib/src/runner/node/platform.dart @@ -14,6 +14,7 @@ import 'package:path/path.dart' as p; import 'package:stream_channel/stream_channel.dart'; import 'package:yaml/yaml.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test_platform.dart'; import '../../util/io.dart'; import '../../util/stack_trace_mapper.dart'; @@ -72,14 +73,14 @@ class NodePlatform extends PlatformPlugin _settings[platform] = settings; } - StreamChannel loadChannel(String path, TestPlatform platform) => + StreamChannel loadChannel(String path, SuitePlatform platform) => throw new UnimplementedError(); - Future load(String path, TestPlatform platform, + Future load(String path, SuitePlatform platform, SuiteConfiguration suiteConfig, Object message) async { - assert(platform == TestPlatform.nodeJS); + assert(platform.platform == TestPlatform.nodeJS); - var pair = await _loadChannel(path, platform, suiteConfig); + var pair = await _loadChannel(path, platform.platform, suiteConfig); var controller = deserializeSuite(path, platform, suiteConfig, new PluginEnvironment(), pair.first, message); diff --git a/lib/src/runner/plugin/platform.dart b/lib/src/runner/plugin/platform.dart index 475b6a885..d0a6db74e 100644 --- a/lib/src/runner/plugin/platform.dart +++ b/lib/src/runner/plugin/platform.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:stream_channel/stream_channel.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/suite_platform.dart'; import '../configuration/suite.dart'; import '../environment.dart'; import '../runner_suite.dart'; @@ -41,9 +41,9 @@ abstract class PlatformPlugin { /// indicates that the suite is no longer needed and its resources may be /// released. /// - /// The [platform] is guaranteed to be one of the platforms associated with - /// this plugin in [new Loader]'s `plugins` parameter. - StreamChannel loadChannel(String path, TestPlatform platform); + /// The `platform.platform` is guaranteed to be one of the platforms + /// associated with this plugin in [new Loader]'s `plugins` parameter. + StreamChannel loadChannel(String path, SuitePlatform platform); /// Loads the runner suite for the test file at [path] using [platform], with /// [suiteConfig] encoding the suite-specific configuration. @@ -56,7 +56,7 @@ abstract class PlatformPlugin { /// Subclasses overriding this method must call [deserializeSuite] in /// `platform_helpers.dart` to obtain a [RunnerSuiteController]. They must /// pass the opaque [message] parameter to the [deserializeSuite] call. - Future load(String path, TestPlatform platform, + Future load(String path, SuitePlatform platform, SuiteConfiguration suiteConfig, Object message) async { // loadChannel may throw an exception. That's fine; it will cause the // LoadSuite to emit an error, which will be presented to the user. diff --git a/lib/src/runner/plugin/platform_helpers.dart b/lib/src/runner/plugin/platform_helpers.dart index bdeea3184..1fc9c6f30 100644 --- a/lib/src/runner/plugin/platform_helpers.dart +++ b/lib/src/runner/plugin/platform_helpers.dart @@ -10,9 +10,8 @@ import 'package:stream_channel/stream_channel.dart'; import '../../backend/group.dart'; import '../../backend/metadata.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test.dart'; -import '../../backend/test_platform.dart'; -import '../../util/io.dart'; import '../../util/remote_exception.dart'; import '../configuration.dart'; import '../configuration/suite.dart'; @@ -37,7 +36,7 @@ import '../runner_test.dart'; /// emitted by tests. RunnerSuiteController deserializeSuite( String path, - TestPlatform platform, + SuitePlatform platform, SuiteConfiguration suiteConfig, Environment environment, StreamChannel channel, @@ -49,9 +48,6 @@ RunnerSuiteController deserializeSuite( 'type': 'initial', 'platform': platform.serialize(), 'metadata': suiteConfig.metadata.serialize(), - 'os': (platform == TestPlatform.vm || platform == TestPlatform.nodeJS) - ? currentOS.identifier - : null, 'asciiGlyphs': Platform.isWindows, 'path': path, 'collectTraces': Configuration.current.reporter == 'json', @@ -110,10 +106,8 @@ RunnerSuiteController deserializeSuite( }); return new RunnerSuiteController( - environment, suiteConfig, suiteChannel, completer.future, + environment, suiteConfig, suiteChannel, completer.future, platform, path: path, - platform: platform, - os: currentOS, onClose: () => disconnector.disconnect().catchError(handleError)); } diff --git a/lib/src/runner/remote_listener.dart b/lib/src/runner/remote_listener.dart index 11435235e..67b4d123a 100644 --- a/lib/src/runner/remote_listener.dart +++ b/lib/src/runner/remote_listener.dart @@ -13,11 +13,10 @@ import '../backend/group.dart'; import '../backend/invoker.dart'; import '../backend/live_test.dart'; import '../backend/metadata.dart'; -import '../backend/operating_system.dart'; import '../backend/stack_trace_formatter.dart'; import '../backend/suite.dart'; +import '../backend/suite_platform.dart'; import '../backend/test.dart'; -import '../backend/test_platform.dart'; import '../util/remote_exception.dart'; import '../utils.dart'; import 'suite_channel_manager.dart'; @@ -115,10 +114,7 @@ class RemoteListener { await declarer.declare(main); var suite = new Suite(declarer.build(), - platform: new TestPlatform.deserialize(message['platform']), - os: message['os'] == null - ? null - : OperatingSystem.find(message['os']), + new SuitePlatform.deserialize(message['platform']), path: message['path']); runZoned(() { diff --git a/lib/src/runner/reporter/compact.dart b/lib/src/runner/reporter/compact.dart index 2a1899623..e7ce3c33e 100644 --- a/lib/src/runner/reporter/compact.dart +++ b/lib/src/runner/reporter/compact.dart @@ -362,7 +362,7 @@ class CompactReporter implements Reporter { if (_config.suiteDefaults.platforms.length > 1 && liveTest.suite.platform != null) { - name = "[${liveTest.suite.platform.name}] $name"; + name = "[${liveTest.suite.platform.platform.name}] $name"; } if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; diff --git a/lib/src/runner/reporter/expanded.dart b/lib/src/runner/reporter/expanded.dart index eb0b99adb..9e714ceb6 100644 --- a/lib/src/runner/reporter/expanded.dart +++ b/lib/src/runner/reporter/expanded.dart @@ -307,7 +307,7 @@ class ExpandedReporter implements Reporter { } if (_printPlatform && liveTest.suite.platform != null) { - name = "[${liveTest.suite.platform.name}] $name"; + name = "[${liveTest.suite.platform.platform.name}] $name"; } if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; diff --git a/lib/src/runner/reporter/json.dart b/lib/src/runner/reporter/json.dart index d8c23359c..6f251dc5d 100644 --- a/lib/src/runner/reporter/json.dart +++ b/lib/src/runner/reporter/json.dart @@ -131,7 +131,7 @@ class JsonReporter implements Reporter { "metadata": _serializeMetadata(suiteConfig, liveTest.test.metadata) }, liveTest.test, - liveTest.suite.platform) + liveTest.suite.platform.platform) }); /// Convert the future to a stream so that the subscription can be paused or @@ -182,7 +182,7 @@ class JsonReporter implements Reporter { _emit("suite", { "suite": { "id": id, - "platform": suite.platform?.identifier, + "platform": suite.platform.platform.identifier, "path": suite.path } }); @@ -218,7 +218,7 @@ class JsonReporter implements Reporter { "testCount": group.testCount }, group, - suite.platform) + suite.platform.platform) }); parentID = id; return id; diff --git a/lib/src/runner/runner_suite.dart b/lib/src/runner/runner_suite.dart index c63369fcb..5ff14c900 100644 --- a/lib/src/runner/runner_suite.dart +++ b/lib/src/runner/runner_suite.dart @@ -8,10 +8,9 @@ import 'package:async/async.dart'; import 'package:stream_channel/stream_channel.dart'; import '../backend/group.dart'; -import '../backend/operating_system.dart'; import '../backend/suite.dart'; +import '../backend/suite_platform.dart'; import '../backend/test.dart'; -import '../backend/test_platform.dart'; import '../utils.dart'; import 'configuration/suite.dart'; import 'environment.dart'; @@ -55,27 +54,24 @@ class RunnerSuite extends Suite { /// A shortcut constructor for creating a [RunnerSuite] that never goes into /// debugging mode and doesn't support suite channels. - factory RunnerSuite( - Environment environment, SuiteConfiguration config, Group group, - {String path, - TestPlatform platform, - OperatingSystem os, - AsyncFunction onClose}) { + factory RunnerSuite(Environment environment, SuiteConfiguration config, + Group group, SuitePlatform platform, + {String path, AsyncFunction onClose}) { var controller = new RunnerSuiteController._local(environment, config, onClose: onClose); - var suite = new RunnerSuite._(controller, group, path, platform, os); + var suite = new RunnerSuite._(controller, group, path, platform); controller._suite = new Future.value(suite); return suite; } - RunnerSuite._(this._controller, Group group, String path, - TestPlatform platform, OperatingSystem os) - : super(group, path: path, platform: platform, os: os); + RunnerSuite._( + this._controller, Group group, String path, SuitePlatform platform) + : super(group, platform, path: path); RunnerSuite filter(bool callback(Test test)) { var filtered = group.filter(callback); filtered ??= new Group.root([], metadata: metadata); - return new RunnerSuite._(_controller, filtered, path, platform, os); + return new RunnerSuite._(_controller, filtered, path, platform); } /// Closes the suite and releases any resources associated with it. @@ -110,14 +106,11 @@ class RunnerSuiteController { final _channelNames = new Set(); RunnerSuiteController(this._environment, this._config, this._suiteChannel, - Future groupFuture, - {String path, - TestPlatform platform, - OperatingSystem os, - AsyncFunction onClose}) + Future groupFuture, SuitePlatform platform, + {String path, AsyncFunction onClose}) : _onClose = onClose { _suite = groupFuture - .then((group) => new RunnerSuite._(this, group, path, platform, os)); + .then((group) => new RunnerSuite._(this, group, path, platform)); } /// Used by [new RunnerSuite] to create a runner suite that's not loaded from diff --git a/lib/src/runner/runner_test.dart b/lib/src/runner/runner_test.dart index d3b4eddb2..0dad8b781 100644 --- a/lib/src/runner/runner_test.dart +++ b/lib/src/runner/runner_test.dart @@ -10,11 +10,10 @@ import '../backend/live_test.dart'; import '../backend/live_test_controller.dart'; import '../backend/message.dart'; import '../backend/metadata.dart'; -import '../backend/operating_system.dart'; import '../backend/state.dart'; import '../backend/suite.dart'; +import '../backend/suite_platform.dart'; import '../backend/test.dart'; -import '../backend/test_platform.dart'; import '../util/remote_exception.dart'; import '../utils.dart'; import 'spawn_hybrid.dart'; @@ -97,9 +96,9 @@ class RunnerTest extends Test { return controller.liveTest; } - Test forPlatform(TestPlatform platform, {OperatingSystem os}) { - if (!metadata.testOn.evaluate(platform, os: os)) return null; + Test forPlatform(SuitePlatform platform) { + if (!metadata.testOn.evaluate(platform)) return null; return new RunnerTest._( - name, metadata.forPlatform(platform, os: os), trace, _channel); + name, metadata.forPlatform(platform), trace, _channel); } } diff --git a/lib/src/runner/vm/platform.dart b/lib/src/runner/vm/platform.dart index d0120c62f..d3842ac9e 100644 --- a/lib/src/runner/vm/platform.dart +++ b/lib/src/runner/vm/platform.dart @@ -8,6 +8,7 @@ import 'dart:isolate'; import 'package:path/path.dart' as p; import 'package:stream_channel/stream_channel.dart'; +import '../../backend/suite_platform.dart'; import '../../backend/test_platform.dart'; import '../../util/dart.dart' as dart; import '../configuration.dart'; @@ -21,8 +22,8 @@ class VMPlatform extends PlatformPlugin { VMPlatform(); - StreamChannel loadChannel(String path, TestPlatform platform) { - assert(platform == TestPlatform.vm); + StreamChannel loadChannel(String path, SuitePlatform platform) { + assert(platform.platform == TestPlatform.vm); var isolate; var channel = StreamChannelCompleter.fromFuture(() async { diff --git a/lib/test.dart b/lib/test.dart index 39e4cbcc0..2d9a7ab9a 100644 --- a/lib/test.dart +++ b/lib/test.dart @@ -8,6 +8,7 @@ import 'package:path/path.dart' as p; import 'src/backend/declarer.dart'; import 'src/backend/invoker.dart'; +import 'src/backend/suite_platform.dart'; import 'src/backend/test_platform.dart'; import 'src/frontend/timeout.dart'; import 'src/runner/configuration/suite.dart'; @@ -57,11 +58,12 @@ Declarer get _declarer { // finished being defined. _globalDeclarer = new Declarer(); scheduleMicrotask(() async { - var suite = new RunnerSuite(const PluginEnvironment(), - SuiteConfiguration.empty, _globalDeclarer.build(), - path: p.prettyUri(Uri.base), - platform: TestPlatform.vm, - os: currentOSGuess); + var suite = new RunnerSuite( + const PluginEnvironment(), + SuiteConfiguration.empty, + _globalDeclarer.build(), + new SuitePlatform(TestPlatform.vm, os: currentOSGuess), + path: p.prettyUri(Uri.base)); var engine = new Engine(); engine.suiteSink.add(suite); diff --git a/test/backend/declarer_test.dart b/test/backend/declarer_test.dart index 659d00bf5..6131e2428 100644 --- a/test/backend/declarer_test.dart +++ b/test/backend/declarer_test.dart @@ -17,7 +17,7 @@ Suite _suite; void main() { setUp(() { - _suite = new Suite(new Group.root([])); + _suite = new Suite(new Group.root([]), suitePlatform); }); group(".test()", () { diff --git a/test/backend/invoker_test.dart b/test/backend/invoker_test.dart index c0c49a911..61d12f6eb 100644 --- a/test/backend/invoker_test.dart +++ b/test/backend/invoker_test.dart @@ -19,7 +19,7 @@ void main() { var suite; setUp(() { lastState = null; - suite = new Suite(new Group.root([])); + suite = new Suite(new Group.root([]), suitePlatform); }); group("Invoker.current", () { diff --git a/test/backend/metadata_test.dart b/test/backend/metadata_test.dart index 35fc9ef18..a02a0baf0 100644 --- a/test/backend/metadata_test.dart +++ b/test/backend/metadata_test.dart @@ -6,6 +6,7 @@ import 'package:boolean_selector/boolean_selector.dart'; import 'package:test/src/backend/metadata.dart'; import 'package:test/src/backend/platform_selector.dart'; +import 'package:test/src/backend/suite_platform.dart'; import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/frontend/skip.dart'; import 'package:test/src/frontend/timeout.dart'; @@ -144,14 +145,14 @@ void main() { }); var key = metadata.onPlatform.keys.first; - expect(key.evaluate(TestPlatform.chrome), isTrue); - expect(key.evaluate(TestPlatform.vm), isFalse); + expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isTrue); + expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isFalse); var value = metadata.onPlatform.values.first; expect(value.timeout.scaleFactor, equals(2)); key = metadata.onPlatform.keys.last; - expect(key.evaluate(TestPlatform.vm), isTrue); - expect(key.evaluate(TestPlatform.chrome), isFalse); + expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); + expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isFalse); value = metadata.onPlatform.values.last; expect(value.skip, isTrue); expect(value.timeout.scaleFactor, equals(3)); diff --git a/test/runner/browser/loader_test.dart b/test/runner/browser/loader_test.dart index a2739c83d..60c4b67e2 100644 --- a/test/runner/browser/loader_test.dart +++ b/test/runner/browser/loader_test.dart @@ -58,7 +58,7 @@ void main() { test("returns a suite with the file path and platform", () { expect(suite.path, equals(p.join(d.sandbox, 'a_test.dart'))); - expect(suite.platform, equals(TestPlatform.chrome)); + expect(suite.platform.platform, equals(TestPlatform.chrome)); }); test("returns tests with the correct names", () { @@ -132,9 +132,9 @@ Future main() { ])) .asyncMap((loadSuite) => loadSuite.getSuite()) .toList(); - expect(suites[0].platform, equals(TestPlatform.vm)); + expect(suites[0].platform.platform, equals(TestPlatform.vm)); expect(suites[0].path, equals(path)); - expect(suites[1].platform, equals(TestPlatform.chrome)); + expect(suites[1].platform.platform, equals(TestPlatform.chrome)); expect(suites[1].path, equals(path)); for (var suite in suites) { diff --git a/test/runner/load_suite_test.dart b/test/runner/load_suite_test.dart index ecf40116d..8003cd53a 100644 --- a/test/runner/load_suite_test.dart +++ b/test/runner/load_suite_test.dart @@ -24,8 +24,8 @@ void main() { }); test("running a load test causes LoadSuite.suite to emit a suite", () async { - var suite = new LoadSuite( - "name", SuiteConfiguration.empty, () => new Future.value(innerSuite)); + var suite = new LoadSuite("name", SuiteConfiguration.empty, suitePlatform, + () => new Future.value(innerSuite)); expect(suite.group.entries, hasLength(1)); expect(suite.suite, completion(equals(innerSuite))); @@ -35,8 +35,8 @@ void main() { }); test("running a load suite's body may be synchronous", () async { - var suite = - new LoadSuite("name", SuiteConfiguration.empty, () => innerSuite); + var suite = new LoadSuite( + "name", SuiteConfiguration.empty, suitePlatform, () => innerSuite); expect(suite.group.entries, hasLength(1)); expect(suite.suite, completion(equals(innerSuite))); @@ -47,8 +47,8 @@ void main() { test("a load test doesn't complete until the body returns", () async { var completer = new Completer(); - var suite = - new LoadSuite("name", SuiteConfiguration.empty, () => completer.future); + var suite = new LoadSuite("name", SuiteConfiguration.empty, suitePlatform, + () => completer.future); expect(suite.group.entries, hasLength(1)); var liveTest = (suite.group.entries.single as Test).load(suite); @@ -63,7 +63,8 @@ void main() { test("a load test forwards errors and completes LoadSuite.suite to null", () async { - var suite = new LoadSuite("name", SuiteConfiguration.empty, () { + var suite = + new LoadSuite("name", SuiteConfiguration.empty, suitePlatform, () { fail("error"); }); expect(suite.group.entries, hasLength(1)); @@ -76,7 +77,7 @@ void main() { }); test("a load test completes early if it's closed", () async { - var suite = new LoadSuite("name", SuiteConfiguration.empty, + var suite = new LoadSuite("name", SuiteConfiguration.empty, suitePlatform, () => new Completer().future); expect(suite.group.entries, hasLength(1)); @@ -119,19 +120,18 @@ void main() { group("changeSuite()", () { test("returns a new load suite with the same properties", () { var suite = new LoadSuite( - "name", SuiteConfiguration.empty, () => innerSuite, - platform: TestPlatform.vm); + "name", SuiteConfiguration.empty, suitePlatform, () => innerSuite); expect(suite.group.entries, hasLength(1)); var newSuite = suite.changeSuite((suite) => suite); - expect(newSuite.platform, equals(TestPlatform.vm)); + expect(newSuite.platform.platform, equals(TestPlatform.vm)); expect(newSuite.group.entries.single.name, equals(suite.group.entries.single.name)); }); test("changes the inner suite", () async { - var suite = - new LoadSuite("name", SuiteConfiguration.empty, () => innerSuite); + var suite = new LoadSuite( + "name", SuiteConfiguration.empty, suitePlatform, () => innerSuite); expect(suite.group.entries, hasLength(1)); var newInnerSuite = runnerSuite(new Group.root([])); @@ -144,7 +144,8 @@ void main() { }); test("doesn't run change() if the suite is null", () async { - var suite = new LoadSuite("name", SuiteConfiguration.empty, () => null); + var suite = new LoadSuite( + "name", SuiteConfiguration.empty, suitePlatform, () => null); expect(suite.group.entries, hasLength(1)); var newSuite = suite.changeSuite(expectAsync1((_) {}, count: 0)); @@ -165,8 +166,8 @@ void main() { }); test("forwards errors to the future", () { - var suite = - new LoadSuite("name", SuiteConfiguration.empty, () => throw "error"); + var suite = new LoadSuite( + "name", SuiteConfiguration.empty, suitePlatform, () => throw "error"); expect(suite.group.entries, hasLength(1)); expect(suite.getSuite(), throwsA("error")); diff --git a/test/runner/loader_test.dart b/test/runner/loader_test.dart index faccd8bd6..16ac88fa6 100644 --- a/test/runner/loader_test.dart +++ b/test/runner/loader_test.dart @@ -51,7 +51,7 @@ void main() { test("returns a suite with the file path and platform", () { expect(suite.path, equals(p.join(d.sandbox, 'a_test.dart'))); - expect(suite.platform, equals(TestPlatform.vm)); + expect(suite.platform.platform, equals(TestPlatform.vm)); }); test("returns entries with the correct names and platforms", () { diff --git a/test/runner/parse_metadata_test.dart b/test/runner/parse_metadata_test.dart index 343307ec9..ce1904705 100644 --- a/test/runner/parse_metadata_test.dart +++ b/test/runner/parse_metadata_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test/src/backend/platform_selector.dart'; +import 'package:test/src/backend/suite_platform.dart'; import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/runner/parse_metadata.dart'; import 'package:test/src/util/io.dart'; @@ -42,16 +43,20 @@ void main() { new File(_path).writeAsStringSync("@foo.TestOn('vm')\n" "import 'package:test/test.dart' as foo;"); var metadata = parseMetadata(_path, new Set()); - expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue); - expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse); + expect( + metadata.testOn.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); + expect(metadata.testOn.evaluate(new SuitePlatform(TestPlatform.chrome)), + isFalse); }); group("@TestOn:", () { test("parses a valid annotation", () { new File(_path).writeAsStringSync("@TestOn('vm')\nlibrary foo;"); var metadata = parseMetadata(_path, new Set()); - expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue); - expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse); + expect( + metadata.testOn.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); + expect(metadata.testOn.evaluate(new SuitePlatform(TestPlatform.chrome)), + isFalse); }); test("ignores a constructor named TestOn", () { @@ -359,14 +364,14 @@ library foo;"""); var metadata = parseMetadata(_path, new Set()); var key = metadata.onPlatform.keys.first; - expect(key.evaluate(TestPlatform.chrome), isTrue); - expect(key.evaluate(TestPlatform.vm), isFalse); + expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isTrue); + expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isFalse); var value = metadata.onPlatform.values.first; expect(value.timeout.scaleFactor, equals(2)); key = metadata.onPlatform.keys.last; - expect(key.evaluate(TestPlatform.vm), isTrue); - expect(key.evaluate(TestPlatform.chrome), isFalse); + expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); + expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isFalse); value = metadata.onPlatform.values.last; expect(value.skip, isTrue); expect(value.timeout.scaleFactor, equals(3)); diff --git a/test/utils.dart b/test/utils.dart index ccc5c1354..4810623d1 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -13,6 +13,8 @@ import 'package:test/src/backend/live_test.dart'; import 'package:test/src/backend/metadata.dart'; import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/suite.dart'; +import 'package:test/src/backend/suite_platform.dart'; +import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/runner/application_exception.dart'; import 'package:test/src/runner/configuration/suite.dart'; import 'package:test/src/runner/engine.dart'; @@ -27,6 +29,9 @@ import 'package:test/test.dart'; /// This differs between dart2js and the VM. final String closureString = (() {}).toString(); +/// A dummy suite platform to use for testing suites. +final suitePlatform = new SuitePlatform(TestPlatform.vm); + // The last state change detected via [expectStates]. State lastState; @@ -226,7 +231,7 @@ class _IsApplicationException extends Matcher { /// Returns a local [LiveTest] that runs [body]. LiveTest createTest(body()) { var test = new LocalTest("test", new Metadata(), body); - var suite = new Suite(new Group.root([test])); + var suite = new Suite(new Group.root([test]), suitePlatform); return test.load(suite); } @@ -313,11 +318,14 @@ List declare(void body()) { Engine declareEngine(void body(), {bool runSkipped: false}) { var declarer = new Declarer()..declare(body); return new Engine.withSuites([ - new RunnerSuite(const PluginEnvironment(), - new SuiteConfiguration(runSkipped: runSkipped), declarer.build()) + new RunnerSuite( + const PluginEnvironment(), + new SuiteConfiguration(runSkipped: runSkipped), + declarer.build(), + suitePlatform) ]); } /// Returns a [RunnerSuite] with a default environment and configuration. -RunnerSuite runnerSuite(Group root) => - new RunnerSuite(const PluginEnvironment(), SuiteConfiguration.empty, root); +RunnerSuite runnerSuite(Group root) => new RunnerSuite( + const PluginEnvironment(), SuiteConfiguration.empty, root, suitePlatform); From cc0c96e49ece0053c8aef6b3c3759304a22c8285 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 21 Feb 2018 18:37:06 -0800 Subject: [PATCH 3/4] Rename TestPlatform to Runtime This clarifies the distinction between TestPlatform and SuitePlatform, and uses a more specific word rather than a more general one. Unfortunately, it does mean that we have some user-facing interfaces (the --platform flag, the override_platforms and define_platforms configuration fields) that now use different terminology than the test runner. It would be possible to migrate those to refer to "runtime" as well, but seeing as --platform in particular is very widely-used *and* matches up nicely with --preset (-p vs -P) I'm inclined to think it's not worth the effort. --- lib/src/backend/platform_selector.dart | 18 +- .../{test_platform.dart => runtime.dart} | 78 ++++---- lib/src/backend/suite_platform.dart | 23 ++- lib/src/runner.dart | 38 ++-- lib/src/runner/browser/browser_manager.dart | 40 ++--- lib/src/runner/browser/chrome.dart | 4 +- lib/src/runner/browser/content_shell.dart | 4 +- lib/src/runner/browser/dartium.dart | 4 +- lib/src/runner/browser/default_settings.dart | 16 +- lib/src/runner/browser/firefox.dart | 4 +- lib/src/runner/browser/internet_explorer.dart | 4 +- lib/src/runner/browser/phantom_js.dart | 4 +- lib/src/runner/browser/platform.dart | 28 +-- lib/src/runner/browser/safari.dart | 4 +- lib/src/runner/configuration.dart | 76 ++++---- lib/src/runner/configuration/args.dart | 16 +- ...stom_platform.dart => custom_runtime.dart} | 14 +- lib/src/runner/configuration/load.dart | 60 +++---- lib/src/runner/configuration/reporters.dart | 2 +- ..._selection.dart => runtime_selection.dart} | 12 +- ...rm_settings.dart => runtime_settings.dart} | 10 +- lib/src/runner/configuration/suite.dart | 44 ++--- lib/src/runner/debugger.dart | 14 +- lib/src/runner/load_suite.dart | 4 +- lib/src/runner/loader.dart | 168 +++++++++--------- lib/src/runner/node/platform.dart | 42 ++--- .../runner/plugin/customizable_platform.dart | 25 ++- .../runner/plugin/hack_register_platform.dart | 20 +-- lib/src/runner/reporter/compact.dart | 4 +- lib/src/runner/reporter/expanded.dart | 4 +- lib/src/runner/reporter/json.dart | 12 +- lib/src/runner/vm/platform.dart | 4 +- lib/test.dart | 4 +- test/backend/metadata_test.dart | 10 +- test/runner/browser/loader_test.dart | 18 +- .../configuration/custom_platform_test.dart | 6 +- test/runner/configuration/suite_test.dart | 33 ++-- test/runner/load_suite_test.dart | 4 +- test/runner/loader_test.dart | 4 +- test/runner/parse_metadata_test.dart | 20 +-- test/utils.dart | 4 +- 41 files changed, 436 insertions(+), 467 deletions(-) rename lib/src/backend/{test_platform.dart => runtime.dart} (65%) rename lib/src/runner/configuration/{custom_platform.dart => custom_runtime.dart} (67%) rename lib/src/runner/configuration/{platform_selection.dart => runtime_selection.dart} (58%) rename lib/src/runner/configuration/{platform_settings.dart => runtime_settings.dart} (72%) diff --git a/lib/src/backend/platform_selector.dart b/lib/src/backend/platform_selector.dart index 3ea9b4aa0..7cc21b31a 100644 --- a/lib/src/backend/platform_selector.dart +++ b/lib/src/backend/platform_selector.dart @@ -6,13 +6,13 @@ import 'package:boolean_selector/boolean_selector.dart'; import 'package:source_span/source_span.dart'; import 'operating_system.dart'; +import 'runtime.dart'; import 'suite_platform.dart'; -import 'test_platform.dart'; /// The set of variable names that are valid for all platform selectors. final _universalValidVariables = new Set.from(["posix", "dart-vm", "browser", "js", "blink"]) - ..addAll(TestPlatform.builtIn.map((platform) => platform.identifier)) + ..addAll(Runtime.builtIn.map((runtime) => runtime.identifier)) ..addAll(OperatingSystem.all.map((os) => os.identifier)); /// An expression for selecting certain platforms, including operating systems @@ -69,23 +69,23 @@ class PlatformSelector { _span); } - /// Returns whether the selector matches the given [platform] and [os]. + /// Returns whether the selector matches the given [platform]. /// /// [os] defaults to [OperatingSystem.none]. bool evaluate(SuitePlatform platform) { return _inner.evaluate((variable) { - if (variable == platform.platform.identifier) return true; - if (variable == platform.platform.parent?.identifier) return true; + if (variable == platform.runtime.identifier) return true; + if (variable == platform.runtime.parent?.identifier) return true; if (variable == platform.os.identifier) return true; switch (variable) { case "dart-vm": - return platform.platform.isDartVM; + return platform.runtime.isDartVM; case "browser": - return platform.platform.isBrowser; + return platform.runtime.isBrowser; case "js": - return platform.platform.isJS; + return platform.runtime.isJS; case "blink": - return platform.platform.isBlink; + return platform.runtime.isBlink; case "posix": return platform.os.isPosix; default: diff --git a/lib/src/backend/test_platform.dart b/lib/src/backend/runtime.dart similarity index 65% rename from lib/src/backend/test_platform.dart rename to lib/src/backend/runtime.dart index e8ead6773..47943ee8c 100644 --- a/lib/src/backend/test_platform.dart +++ b/lib/src/backend/runtime.dart @@ -2,61 +2,57 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(nweiz): support pluggable platforms. -/// An enum of all platforms on which tests can run. -class TestPlatform { - // When adding new platforms, be sure to update the baseline and derived +/// An enum of all Dart runtimes supported by the test runner. +class Runtime { + // When adding new runtimes, be sure to update the baseline and derived // variable tests in test/backend/platform_selector/evaluate_test. /// The command-line Dart VM. - static const TestPlatform vm = const TestPlatform("VM", "vm", isDartVM: true); + static const Runtime vm = const Runtime("VM", "vm", isDartVM: true); /// Dartium. - static const TestPlatform dartium = const TestPlatform("Dartium", "dartium", + static const Runtime dartium = const Runtime("Dartium", "dartium", isBrowser: true, isBlink: true, isDartVM: true); /// Dartium content shell. - static const TestPlatform contentShell = const TestPlatform( + static const Runtime contentShell = const Runtime( "Dartium Content Shell", "content-shell", isBrowser: true, isBlink: true, isDartVM: true, isHeadless: true); /// Google Chrome. - static const TestPlatform chrome = const TestPlatform("Chrome", "chrome", + static const Runtime chrome = const Runtime("Chrome", "chrome", isBrowser: true, isJS: true, isBlink: true); /// PhantomJS. - static const TestPlatform phantomJS = const TestPlatform( - "PhantomJS", "phantomjs", + static const Runtime phantomJS = const Runtime("PhantomJS", "phantomjs", isBrowser: true, isJS: true, isBlink: true, isHeadless: true); /// Mozilla Firefox. - static const TestPlatform firefox = - const TestPlatform("Firefox", "firefox", isBrowser: true, isJS: true); + static const Runtime firefox = + const Runtime("Firefox", "firefox", isBrowser: true, isJS: true); /// Apple Safari. - static const TestPlatform safari = - const TestPlatform("Safari", "safari", isBrowser: true, isJS: true); + static const Runtime safari = + const Runtime("Safari", "safari", isBrowser: true, isJS: true); /// Microsoft Internet Explorer. - static const TestPlatform internetExplorer = const TestPlatform( - "Internet Explorer", "ie", - isBrowser: true, isJS: true); + static const Runtime internetExplorer = + const Runtime("Internet Explorer", "ie", isBrowser: true, isJS: true); /// The command-line Node.js VM. - static const TestPlatform nodeJS = - const TestPlatform("Node.js", "node", isJS: true); + static const Runtime nodeJS = const Runtime("Node.js", "node", isJS: true); /// The platforms that are supported by the test runner by default. - static const List builtIn = const [ - TestPlatform.vm, - TestPlatform.dartium, - TestPlatform.contentShell, - TestPlatform.chrome, - TestPlatform.phantomJS, - TestPlatform.firefox, - TestPlatform.safari, - TestPlatform.internetExplorer, - TestPlatform.nodeJS + static const List builtIn = const [ + Runtime.vm, + Runtime.dartium, + Runtime.contentShell, + Runtime.chrome, + Runtime.phantomJS, + Runtime.firefox, + Runtime.safari, + Runtime.internetExplorer, + Runtime.nodeJS ]; /// The human-friendly name of the platform. @@ -67,7 +63,7 @@ class TestPlatform { /// The parent platform that this is based on, or `null` if there is no /// parent. - final TestPlatform parent; + final Runtime parent; /// Returns whether this is a child of another platform. bool get isChild => parent != null; @@ -91,9 +87,9 @@ class TestPlatform { /// anything. /// /// That is, returns [parent] if it's non-`null` or [this] if it's `null`. - TestPlatform get root => parent ?? this; + Runtime get root => parent ?? this; - const TestPlatform(this.name, this.identifier, + const Runtime(this.name, this.identifier, {this.isDartVM: false, this.isBrowser: false, this.isJS: false, @@ -101,7 +97,7 @@ class TestPlatform { this.isHeadless: false}) : parent = null; - TestPlatform._child(this.name, this.identifier, this.parent) + Runtime._child(this.name, this.identifier, this.parent) : isDartVM = parent.isDartVM, isBrowser = parent.isBrowser, isJS = parent.isJS, @@ -109,8 +105,8 @@ class TestPlatform { isHeadless = parent.isHeadless; /// Converts a JSON-safe representation generated by [serialize] back into a - /// [TestPlatform]. - factory TestPlatform.deserialize(Object serialized) { + /// [Runtime]. + factory Runtime.deserialize(Object serialized) { if (serialized is String) { return builtIn .firstWhere((platform) => platform.identifier == serialized); @@ -123,11 +119,11 @@ class TestPlatform { // a separately-deserialized parent platform. This should be fine, though, // since we only deserialize platforms in the remote execution context // where they're only used to evaluate platform selectors. - return new TestPlatform._child( - map["name"], map["identifier"], new TestPlatform.deserialize(parent)); + return new Runtime._child( + map["name"], map["identifier"], new Runtime.deserialize(parent)); } - return new TestPlatform(map["name"], map["identifier"], + return new Runtime(map["name"], map["identifier"], isDartVM: map["isDartVM"], isBrowser: map["isBrowser"], isJS: map["isJS"], @@ -136,7 +132,7 @@ class TestPlatform { } /// Converts [this] into a JSON-safe object that can be converted back to a - /// [TestPlatform] using [new TestPlatform.deserialize]. + /// [Runtime] using [new Runtime.deserialize]. Object serialize() { if (builtIn.contains(this)) return identifier; @@ -163,8 +159,8 @@ class TestPlatform { /// and the new [identifier]. /// /// This may not be called on a platform that's already a child. - TestPlatform extend(String name, String identifier) { - if (parent == null) return new TestPlatform._child(name, identifier, this); + Runtime extend(String name, String identifier) { + if (parent == null) return new Runtime._child(name, identifier, this); throw new StateError("A child platform may not be extended."); } diff --git a/lib/src/backend/suite_platform.dart b/lib/src/backend/suite_platform.dart index 9449ade77..0f4a5b1b1 100644 --- a/lib/src/backend/suite_platform.dart +++ b/lib/src/backend/suite_platform.dart @@ -3,29 +3,28 @@ // BSD-style license that can be found in the LICENSE file. import 'operating_system.dart'; -import 'test_platform.dart'; +import 'runtime.dart'; /// The platform on which a test suite is loaded. class SuitePlatform { - /// The platform on which the suite is running. - final TestPlatform platform; + /// The runtime that hosts the suite. + final Runtime runtime; /// The operating system on which the suite is running. /// - /// This will always be [OperatingSystem.none] if `platform.isBrowser` is + /// This will always be [OperatingSystem.none] if `runtime.isBrowser` is /// true. final OperatingSystem os; - /// Creates a new platform with the given [platform] and [os], which defaults + /// Creates a new platform with the given [runtime] and [os], which defaults /// to [OperatingSystem.none]. /// - /// Throws an [ArgumentError] if [platform] is a browser and [os] is not + /// Throws an [ArgumentError] if [runtime] is a browser and [os] is not /// `null` or [OperatingSystem.none]. - SuitePlatform(this.platform, {OperatingSystem os}) + SuitePlatform(this.runtime, {OperatingSystem os}) : os = os ?? OperatingSystem.none { - if (platform.isBrowser && this.os != OperatingSystem.none) { - throw new ArgumentError( - 'No OS should be passed for platform "$platform".'); + if (runtime.isBrowser && this.os != OperatingSystem.none) { + throw new ArgumentError('No OS should be passed for runtime "$runtime".'); } } @@ -33,11 +32,11 @@ class SuitePlatform { /// [SuitePlatform]. factory SuitePlatform.deserialize(Object serialized) { var map = serialized as Map; - return new SuitePlatform(new TestPlatform.deserialize(map['platform']), + return new SuitePlatform(new Runtime.deserialize(map['runtime']), os: OperatingSystem.find(map['os'])); } /// Converts [this] into a JSON-safe object that can be converted back to a /// [SuitePlatform] using [new SuitePlatform.deserialize]. - Object serialize() => {'platform': platform.serialize(), 'os': os.identifier}; + Object serialize() => {'runtime': runtime.serialize(), 'os': os.identifier}; } diff --git a/lib/src/runner.dart b/lib/src/runner.dart index 2910c5917..202ea0ed0 100644 --- a/lib/src/runner.dart +++ b/lib/src/runner.dart @@ -11,10 +11,10 @@ import 'backend/group.dart'; import 'backend/group_entry.dart'; import 'backend/operating_system.dart'; import 'backend/platform_selector.dart'; +import 'backend/runtime.dart'; import 'backend/suite.dart'; import 'backend/suite_platform.dart'; import 'backend/test.dart'; -import 'backend/test_platform.dart'; import 'runner/application_exception.dart'; import 'runner/configuration.dart'; import 'runner/configuration/reporters.dart'; @@ -128,31 +128,31 @@ class Runner { var testOn = _config.suiteDefaults.metadata.testOn; if (testOn == PlatformSelector.all) return; - var unsupportedPlatforms = _config.suiteDefaults.platforms - .map(_loader.findTestPlatform) - .where((platform) => - platform != null && - !testOn.evaluate(new SuitePlatform(platform, - os: platform.isBrowser ? null : currentOS))) + var unsupportedRuntimes = _config.suiteDefaults.runtimes + .map(_loader.findRuntime) + .where((runtime) => + runtime != null && + !testOn.evaluate(new SuitePlatform(runtime, + os: runtime.isBrowser ? null : currentOS))) .toList(); - if (unsupportedPlatforms.isEmpty) return; + if (unsupportedRuntimes.isEmpty) return; - // Human-readable names for all unsupported platforms. + // Human-readable names for all unsupported runtimes. var unsupportedNames = []; // If the user tried to run on one or moe unsupported browsers, figure out // whether we should warn about the individual browsers or whether all // browsers are unsupported. var unsupportedBrowsers = - unsupportedPlatforms.where((platform) => platform.isBrowser); + unsupportedRuntimes.where((platform) => platform.isBrowser); if (unsupportedBrowsers.isNotEmpty) { - var supportsAnyBrowser = _loader.allPlatforms - .where((platform) => platform.isBrowser) - .any((platform) => testOn.evaluate(new SuitePlatform(platform))); + var supportsAnyBrowser = _loader.allRuntimes + .where((runtime) => runtime.isBrowser) + .any((runtime) => testOn.evaluate(new SuitePlatform(runtime))); if (supportsAnyBrowser) { unsupportedNames - .addAll(unsupportedBrowsers.map((platform) => platform.name)); + .addAll(unsupportedBrowsers.map((runtime) => runtime.name)); } else { unsupportedNames.add("browsers"); } @@ -160,9 +160,9 @@ class Runner { // If the user tried to run on the VM and it's not supported, figure out if // that's because of the current OS or whether the VM is unsupported. - if (unsupportedPlatforms.contains(TestPlatform.vm)) { - var supportsAnyOS = OperatingSystem.all.any( - (os) => testOn.evaluate(new SuitePlatform(TestPlatform.vm, os: os))); + if (unsupportedRuntimes.contains(Runtime.vm)) { + var supportsAnyOS = OperatingSystem.all + .any((os) => testOn.evaluate(new SuitePlatform(Runtime.vm, os: os))); if (supportsAnyOS) { unsupportedNames.add(currentOS.name); @@ -353,10 +353,10 @@ class Runner { return filtered; } - /// Loads each suite in [suites] in order, pausing after load for platforms + /// Loads each suite in [suites] in order, pausing after load for runtimes /// that support debugging. Future _loadThenPause(Stream suites) async { - if (_config.suiteDefaults.platforms.contains(TestPlatform.vm.identifier)) { + if (_config.suiteDefaults.runtimes.contains(Runtime.vm.identifier)) { warn("Debugging is currently unsupported on the Dart VM.", color: _config.color); } diff --git a/lib/src/runner/browser/browser_manager.dart b/lib/src/runner/browser/browser_manager.dart index bd282655d..8743378d8 100644 --- a/lib/src/runner/browser/browser_manager.dart +++ b/lib/src/runner/browser/browser_manager.dart @@ -10,8 +10,8 @@ import 'package:pool/pool.dart'; import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; +import '../../backend/runtime.dart'; import '../../backend/suite_platform.dart'; -import '../../backend/test_platform.dart'; import '../../util/stack_trace_mapper.dart'; import '../application_exception.dart'; import '../configuration/suite.dart'; @@ -38,8 +38,8 @@ class BrowserManager { // TODO(nweiz): Consider removing the duplication between this and // [_browser.name]. - /// The [TestPlatform] for [_browser]. - final TestPlatform _platform; + /// The [Runtime] for [_browser]. + final Runtime _runtime; /// The channel used to communicate with the browser. /// @@ -88,7 +88,7 @@ class BrowserManager { // this lets us detect whether they're debugging reasonably accurately. RestartableTimer _timer; - /// Starts the browser identified by [platform] and has it connect to [url]. + /// Starts the browser identified by [runtime] and has it connect to [url]. /// /// [url] should serve a page that establishes a WebSocket connection with /// this process. That connection, once established, should be emitted via @@ -99,10 +99,10 @@ class BrowserManager { /// /// Returns the browser manager, or throws an [ApplicationException] if a /// connection fails to be established. - static Future start(TestPlatform platform, Uri url, + static Future start(Runtime runtime, Uri url, Future future, ExecutableSettings settings, {bool debug: false}) { - var browser = _newBrowser(url, platform, settings, debug: debug); + var browser = _newBrowser(url, runtime, settings, debug: debug); var completer = new Completer(); @@ -110,7 +110,7 @@ class BrowserManager { // tests complete. browser.onExit.then((_) { throw new ApplicationException( - "${platform.name} exited before connecting."); + "${runtime.name} exited before connecting."); }).catchError((error, stackTrace) { if (completer.isCompleted) return; completer.completeError(error, stackTrace); @@ -118,7 +118,7 @@ class BrowserManager { future.then((webSocket) { if (completer.isCompleted) return; - completer.complete(new BrowserManager._(browser, platform, webSocket)); + completer.complete(new BrowserManager._(browser, runtime, webSocket)); }).catchError((error, stackTrace) { browser.close(); if (completer.isCompleted) return; @@ -128,7 +128,7 @@ class BrowserManager { return completer.future.timeout(new Duration(seconds: 30), onTimeout: () { browser.close(); throw new ApplicationException( - "Timed out waiting for ${platform.name} to connect."); + "Timed out waiting for ${runtime.name} to connect."); }); } @@ -136,22 +136,22 @@ class BrowserManager { /// /// If [debug] is true, starts the browser in debug mode. static Browser _newBrowser( - Uri url, TestPlatform browser, ExecutableSettings settings, + Uri url, Runtime browser, ExecutableSettings settings, {bool debug: false}) { switch (browser.root) { - case TestPlatform.dartium: + case Runtime.dartium: return new Dartium(url, settings: settings, debug: debug); - case TestPlatform.contentShell: + case Runtime.contentShell: return new ContentShell(url, settings: settings, debug: debug); - case TestPlatform.chrome: + case Runtime.chrome: return new Chrome(url, settings: settings, debug: debug); - case TestPlatform.phantomJS: + case Runtime.phantomJS: return new PhantomJS(url, settings: settings, debug: debug); - case TestPlatform.firefox: + case Runtime.firefox: return new Firefox(url, settings: settings); - case TestPlatform.safari: + case Runtime.safari: return new Safari(url, settings: settings); - case TestPlatform.internetExplorer: + case Runtime.internetExplorer: return new InternetExplorer(url, settings: settings); default: throw new ArgumentError("$browser is not a browser."); @@ -160,7 +160,7 @@ class BrowserManager { /// Creates a new BrowserManager that communicates with [browser] over /// [webSocket]. - BrowserManager._(this._browser, this._platform, WebSocketChannel webSocket) { + BrowserManager._(this._browser, this._runtime, WebSocketChannel webSocket) { // The duration should be short enough that the debugging console is open as // soon as the user is done setting breakpoints, but long enough that a test // doing a lot of synchronous work doesn't trigger a false positive. @@ -212,7 +212,7 @@ class BrowserManager { url = url.replace( fragment: Uri.encodeFull(JSON.encode({ "metadata": suiteConfig.metadata.serialize(), - "browser": _platform.identifier + "browser": _runtime.identifier }))); var suiteID = _suiteID++; @@ -242,7 +242,7 @@ class BrowserManager { }); try { - controller = deserializeSuite(path, new SuitePlatform(_platform), + controller = deserializeSuite(path, new SuitePlatform(_runtime), suiteConfig, await _environment, suiteChannel, message); controller.channel("test.browser.mapper").sink.add(mapper?.serialize()); diff --git a/lib/src/runner/browser/chrome.dart b/lib/src/runner/browser/chrome.dart index 64b8fca16..cedc53616 100644 --- a/lib/src/runner/browser/chrome.dart +++ b/lib/src/runner/browser/chrome.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:io'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/io.dart'; import '../executable_settings.dart'; import 'browser.dart'; @@ -27,7 +27,7 @@ class Chrome extends Browser { /// Starts a new instance of Chrome open to the given [url], which may be a /// [Uri] or a [String]. factory Chrome(url, {ExecutableSettings settings, bool debug: false}) { - settings ??= defaultSettings[TestPlatform.chrome]; + settings ??= defaultSettings[Runtime.chrome]; var remoteDebuggerCompleter = new Completer.sync(); return new Chrome._(() async { var tryPort = ([int port]) async { diff --git a/lib/src/runner/browser/content_shell.dart b/lib/src/runner/browser/content_shell.dart index 682f6ea8e..2159357a5 100644 --- a/lib/src/runner/browser/content_shell.dart +++ b/lib/src/runner/browser/content_shell.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:io'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/io.dart'; import '../../utils.dart'; import '../application_exception.dart'; @@ -31,7 +31,7 @@ class ContentShell extends Browser { final Future remoteDebuggerUrl; factory ContentShell(url, {ExecutableSettings settings, bool debug: false}) { - settings ??= defaultSettings[TestPlatform.contentShell]; + settings ??= defaultSettings[Runtime.contentShell]; var observatoryCompleter = new Completer.sync(); var remoteDebuggerCompleter = new Completer.sync(); return new ContentShell._(() { diff --git a/lib/src/runner/browser/dartium.dart b/lib/src/runner/browser/dartium.dart index 8cd8d1e40..b17861fd9 100644 --- a/lib/src/runner/browser/dartium.dart +++ b/lib/src/runner/browser/dartium.dart @@ -8,7 +8,7 @@ import 'dart:io'; import 'package:async/async.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/io.dart'; import '../../utils.dart'; import '../executable_settings.dart'; @@ -33,7 +33,7 @@ class Dartium extends Browser { final Future remoteDebuggerUrl; factory Dartium(url, {ExecutableSettings settings, bool debug: false}) { - settings ??= defaultSettings[TestPlatform.dartium]; + settings ??= defaultSettings[Runtime.dartium]; var observatoryCompleter = new Completer.sync(); var remoteDebuggerCompleter = new Completer.sync(); return new Dartium._(() async { diff --git a/lib/src/runner/browser/default_settings.dart b/lib/src/runner/browser/default_settings.dart index 600092694..5c3bf5ba8 100644 --- a/lib/src/runner/browser/default_settings.dart +++ b/lib/src/runner/browser/default_settings.dart @@ -4,34 +4,34 @@ import 'dart:collection'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../executable_settings.dart'; /// Default settings for starting browser executables. final defaultSettings = new UnmodifiableMapView({ - TestPlatform.chrome: new ExecutableSettings( + Runtime.chrome: new ExecutableSettings( linuxExecutable: 'google-chrome', macOSExecutable: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', windowsExecutable: r'Google\Chrome\Application\chrome.exe'), - TestPlatform.contentShell: new ExecutableSettings( + Runtime.contentShell: new ExecutableSettings( linuxExecutable: 'content_shell', macOSExecutable: 'content_shell', windowsExecutable: 'content_shell.exe'), - TestPlatform.dartium: new ExecutableSettings( + Runtime.dartium: new ExecutableSettings( linuxExecutable: 'dartium', macOSExecutable: 'dartium', windowsExecutable: 'dartium.exe'), - TestPlatform.firefox: new ExecutableSettings( + Runtime.firefox: new ExecutableSettings( linuxExecutable: 'firefox', macOSExecutable: '/Applications/Firefox.app/Contents/MacOS/firefox-bin', windowsExecutable: r'Mozilla Firefox\firefox.exe'), - TestPlatform.internetExplorer: new ExecutableSettings( + Runtime.internetExplorer: new ExecutableSettings( windowsExecutable: r'Internet Explorer\iexplore.exe'), - TestPlatform.phantomJS: new ExecutableSettings( + Runtime.phantomJS: new ExecutableSettings( linuxExecutable: 'phantomjs', macOSExecutable: 'phantomjs', windowsExecutable: 'phantomjs.exe'), - TestPlatform.safari: new ExecutableSettings( + Runtime.safari: new ExecutableSettings( macOSExecutable: '/Applications/Safari.app/Contents/MacOS/Safari') }); diff --git a/lib/src/runner/browser/firefox.dart b/lib/src/runner/browser/firefox.dart index ba00de799..0f5299ebd 100644 --- a/lib/src/runner/browser/firefox.dart +++ b/lib/src/runner/browser/firefox.dart @@ -7,7 +7,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/io.dart'; import '../executable_settings.dart'; import 'browser.dart'; @@ -35,7 +35,7 @@ class Firefox extends Browser { /// Starts a new instance of Firefox open to the given [url], which may be a /// [Uri] or a [String]. static Future _startBrowser(url, ExecutableSettings settings) async { - settings ??= defaultSettings[TestPlatform.firefox]; + settings ??= defaultSettings[Runtime.firefox]; var dir = createTempDir(); new File(p.join(dir, 'prefs.js')).writeAsStringSync(_preferences); diff --git a/lib/src/runner/browser/internet_explorer.dart b/lib/src/runner/browser/internet_explorer.dart index a2731bbce..029186db7 100644 --- a/lib/src/runner/browser/internet_explorer.dart +++ b/lib/src/runner/browser/internet_explorer.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:io'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../executable_settings.dart'; import 'browser.dart'; import 'default_settings.dart'; @@ -22,7 +22,7 @@ class InternetExplorer extends Browser { /// Starts a new instance of Internet Explorer open to the given [url], which /// may be a [Uri] or a [String]. static Future _startBrowser(url, ExecutableSettings settings) { - settings ??= defaultSettings[TestPlatform.internetExplorer]; + settings ??= defaultSettings[Runtime.internetExplorer]; return Process.start(settings.executable, ['-extoff', url.toString()]..addAll(settings.arguments)); diff --git a/lib/src/runner/browser/phantom_js.dart b/lib/src/runner/browser/phantom_js.dart index 25e9b99ed..50aa628d5 100644 --- a/lib/src/runner/browser/phantom_js.dart +++ b/lib/src/runner/browser/phantom_js.dart @@ -7,7 +7,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/exit_codes.dart' as exit_codes; import '../../util/io.dart'; import '../application_exception.dart'; @@ -43,7 +43,7 @@ class PhantomJS extends Browser { final Future remoteDebuggerUrl; factory PhantomJS(url, {ExecutableSettings settings, bool debug: false}) { - settings ??= defaultSettings[TestPlatform.phantomJS]; + settings ??= defaultSettings[Runtime.phantomJS]; var remoteDebuggerCompleter = new Completer.sync(); return new PhantomJS._(() async { var dir = createTempDir(); diff --git a/lib/src/runner/browser/platform.dart b/lib/src/runner/browser/platform.dart index 59ab1e8e8..63991f8ef 100644 --- a/lib/src/runner/browser/platform.dart +++ b/lib/src/runner/browser/platform.dart @@ -21,8 +21,8 @@ import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:yaml/yaml.dart'; +import '../../backend/runtime.dart'; import '../../backend/suite_platform.dart'; -import '../../backend/test_platform.dart'; import '../../util/io.dart'; import '../../util/one_off_handler.dart'; import '../../util/path_handler.dart'; @@ -106,13 +106,13 @@ class BrowserPlatform extends PlatformPlugin /// [BrowserManager]s for those browsers, or `null` if they failed to load. /// /// This should only be accessed through [_browserManagerFor]. - final _browserManagers = >{}; + final _browserManagers = >{}; /// Settings for invoking each browser. /// /// This starts out with the default settings, which may be overridden by user settings. final _browserSettings = - new Map.from(defaultSettings); + new Map.from(defaultSettings); /// A cascade of handlers for suites' precompiled paths. /// @@ -217,11 +217,11 @@ class BrowserPlatform extends PlatformPlugin ExecutableSettings settings1, ExecutableSettings settings2) => settings1.merge(settings2); - void customizePlatform(TestPlatform platform, ExecutableSettings settings) { + void customizePlatform(Runtime runtime, ExecutableSettings settings) { var oldSettings = - _browserSettings[platform] ?? _browserSettings[platform.root]; + _browserSettings[runtime] ?? _browserSettings[runtime.root]; if (oldSettings != null) settings = oldSettings.merge(settings); - _browserSettings[platform] = settings; + _browserSettings[runtime] = settings; } /// Loads the test suite at [path] on the platform [platform]. @@ -230,8 +230,8 @@ class BrowserPlatform extends PlatformPlugin /// Throws an [ArgumentError] if `platform.platform` isn't a browser. Future load(String path, SuitePlatform platform, SuiteConfiguration suiteConfig, Object message) async { - var browser = platform.platform; - assert(suiteConfig.platforms.contains(browser.identifier)); + var browser = platform.runtime; + assert(suiteConfig.runtimes.contains(browser.identifier)); if (!browser.isBrowser) { throw new ArgumentError("$browser is not a browser."); @@ -330,7 +330,7 @@ class BrowserPlatform extends PlatformPlugin /// /// This ensures that only one suite is loaded at a time, and that any errors /// are exposed as [LoadException]s. - Future _pubServeSuite(String path, Uri dartUrl, TestPlatform browser, + Future _pubServeSuite(String path, Uri dartUrl, Runtime browser, SuiteConfiguration suiteConfig) { return _pubServePool.withResource(() async { var timer = new Timer(new Duration(seconds: 1), () { @@ -437,11 +437,11 @@ class BrowserPlatform extends PlatformPlugin }); } - /// Returns the [BrowserManager] for [platform], which should be a browser. + /// Returns the [BrowserManager] for [runtime], which should be a browser. /// /// If no browser manager is running yet, starts one. - Future _browserManagerFor(TestPlatform platform) { - var managerFuture = _browserManagers[platform]; + Future _browserManagerFor(Runtime browser) { + var managerFuture = _browserManagers[browser]; if (managerFuture != null) return managerFuture; var completer = new Completer.sync(); @@ -455,12 +455,12 @@ class BrowserPlatform extends PlatformPlugin }); var future = BrowserManager.start( - platform, hostUrl, completer.future, _browserSettings[platform], + browser, hostUrl, completer.future, _browserSettings[browser], debug: _config.pauseAfterLoad); // Store null values for browsers that error out so we know not to load them // again. - _browserManagers[platform] = future.catchError((_) => null); + _browserManagers[browser] = future.catchError((_) => null); return future; } diff --git a/lib/src/runner/browser/safari.dart b/lib/src/runner/browser/safari.dart index 2b35749c0..24879f210 100644 --- a/lib/src/runner/browser/safari.dart +++ b/lib/src/runner/browser/safari.dart @@ -8,7 +8,7 @@ import 'dart:io'; import 'package:path/path.dart' as p; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../util/io.dart'; import '../executable_settings.dart'; import 'browser.dart'; @@ -26,7 +26,7 @@ class Safari extends Browser { /// Starts a new instance of Safari open to the given [url], which may be a /// [Uri] or a [String]. static Future _startBrowser(url, ExecutableSettings settings) async { - settings ??= defaultSettings[TestPlatform.safari]; + settings ??= defaultSettings[Runtime.safari]; var dir = createTempDir(); // Safari will only open files (not general URLs) via the command-line diff --git a/lib/src/runner/configuration.dart b/lib/src/runner/configuration.dart index 873ef6a61..aa0cb8ad8 100644 --- a/lib/src/runner/configuration.dart +++ b/lib/src/runner/configuration.dart @@ -11,16 +11,16 @@ import 'package:path/path.dart' as p; import 'package:source_span/source_span.dart'; import '../backend/platform_selector.dart'; -import '../backend/test_platform.dart'; +import '../backend/runtime.dart'; import '../frontend/timeout.dart'; import '../util/io.dart'; import '../utils.dart'; import 'configuration/args.dart' as args; -import 'configuration/custom_platform.dart'; +import 'configuration/custom_runtime.dart'; import 'configuration/load.dart'; -import 'configuration/platform_selection.dart'; -import 'configuration/platform_settings.dart'; import 'configuration/reporters.dart'; +import 'configuration/runtime_selection.dart'; +import 'configuration/runtime_settings.dart'; import 'configuration/suite.dart'; import 'configuration/values.dart'; @@ -174,11 +174,11 @@ class Configuration { Set _knownPresets; - /// Built-in platforms whose settings are overridden by the user. - final Map overridePlatforms; + /// Built-in runtimes whose settings are overridden by the user. + final Map overrideRuntimes; - /// Platforms defined by the user in terms of existing platforms. - final Map definePlatforms; + /// Runtimes defined by the user in terms of existing runtimes. + final Map defineRuntimes; /// The default suite-level configuration. final SuiteConfiguration suiteDefaults; @@ -223,8 +223,8 @@ class Configuration { Glob filename, Iterable chosenPresets, Map presets, - Map overridePlatforms, - Map definePlatforms, + Map overrideRuntimes, + Map defineRuntimes, bool noRetry, // Suite-level configuration @@ -233,7 +233,7 @@ class Configuration { Iterable dart2jsArgs, String precompiledPath, Iterable patterns, - Iterable platforms, + Iterable runtimes, BooleanSelector includeTags, BooleanSelector excludeTags, Map tags, @@ -267,8 +267,8 @@ class Configuration { filename: filename, chosenPresets: chosenPresetSet, presets: _withChosenPresets(presets, chosenPresetSet), - overridePlatforms: overridePlatforms, - definePlatforms: definePlatforms, + overrideRuntimes: overrideRuntimes, + defineRuntimes: defineRuntimes, noRetry: noRetry, suiteDefaults: new SuiteConfiguration( jsTrace: jsTrace, @@ -276,7 +276,7 @@ class Configuration { dart2jsArgs: dart2jsArgs, precompiledPath: precompiledPath, patterns: patterns, - platforms: platforms, + runtimes: runtimes, includeTags: includeTags, excludeTags: excludeTags, tags: tags, @@ -323,8 +323,8 @@ class Configuration { Glob filename, Iterable chosenPresets, Map presets, - Map overridePlatforms, - Map definePlatforms, + Map overrideRuntimes, + Map defineRuntimes, bool noRetry, SuiteConfiguration suiteDefaults}) : _help = help, @@ -345,8 +345,8 @@ class Configuration { chosenPresets = new UnmodifiableSetView(chosenPresets?.toSet() ?? new Set()), presets = _map(presets), - overridePlatforms = _map(overridePlatforms), - definePlatforms = _map(definePlatforms), + overrideRuntimes = _map(overrideRuntimes), + defineRuntimes = _map(defineRuntimes), _noRetry = noRetry, suiteDefaults = pauseAfterLoad == true ? suiteDefaults?.change(timeout: Timeout.none) ?? @@ -403,23 +403,23 @@ class Configuration { /// asynchronous callbacks transitively created by [body]. T asCurrent(T body()) => runZoned(body, zoneValues: {_currentKey: this}); - /// Throws a [FormatException] if [this] refers to any undefined platforms. - void validatePlatforms(List allPlatforms) { - // We don't need to verify [customPlatforms] here because those platforms - // already need to be verified and resolved to create [allPlatforms]. + /// Throws a [FormatException] if [this] refers to any undefined runtimes. + void validateRuntimes(List allRuntimes) { + // We don't need to verify [customRuntimes] here because those runtimes + // already need to be verified and resolved to create [allRuntimes]. - for (var settings in overridePlatforms.values) { - if (!allPlatforms - .any((platform) => platform.identifier == settings.identifier)) { + for (var settings in overrideRuntimes.values) { + if (!allRuntimes + .any((runtime) => runtime.identifier == settings.identifier)) { throw new SourceSpanFormatException( 'Unknown platform "${settings.identifier}".', settings.identifierSpan); } } - suiteDefaults.validatePlatforms(allPlatforms); + suiteDefaults.validateRuntimes(allRuntimes); for (var config in presets.values) { - config.validatePlatforms(allPlatforms); + config.validateRuntimes(allRuntimes); } } @@ -466,14 +466,14 @@ class Configuration { filename: other._filename ?? _filename, chosenPresets: chosenPresets.union(other.chosenPresets), presets: _mergeConfigMaps(presets, other.presets), - overridePlatforms: mergeUnmodifiableMaps( - overridePlatforms, other.overridePlatforms, - value: (settings1, settings2) => new PlatformSettings( + overrideRuntimes: mergeUnmodifiableMaps( + overrideRuntimes, other.overrideRuntimes, + value: (settings1, settings2) => new RuntimeSettings( settings1.identifier, settings1.identifierSpan, settings1.settings.toList()..addAll(settings2.settings))), - definePlatforms: - mergeUnmodifiableMaps(definePlatforms, other.definePlatforms), + defineRuntimes: + mergeUnmodifiableMaps(defineRuntimes, other.defineRuntimes), noRetry: other._noRetry ?? _noRetry, suiteDefaults: suiteDefaults.merge(other.suiteDefaults)); result = result._resolvePresets(); @@ -506,8 +506,8 @@ class Configuration { Glob filename, Iterable chosenPresets, Map presets, - Map overridePlatforms, - Map definePlatforms, + Map overrideRuntimes, + Map defineRuntimes, bool noRetry, // Suite-level configuration @@ -516,7 +516,7 @@ class Configuration { Iterable dart2jsArgs, String precompiledPath, Iterable patterns, - Iterable platforms, + Iterable runtimes, BooleanSelector includeTags, BooleanSelector excludeTags, Map tags, @@ -548,8 +548,8 @@ class Configuration { filename: filename ?? _filename, chosenPresets: chosenPresets ?? this.chosenPresets, presets: presets ?? this.presets, - overridePlatforms: overridePlatforms ?? this.overridePlatforms, - definePlatforms: definePlatforms ?? this.definePlatforms, + overrideRuntimes: overrideRuntimes ?? this.overrideRuntimes, + defineRuntimes: defineRuntimes ?? this.defineRuntimes, noRetry: noRetry ?? _noRetry, suiteDefaults: suiteDefaults.change( jsTrace: jsTrace, @@ -557,7 +557,7 @@ class Configuration { dart2jsArgs: dart2jsArgs, precompiledPath: precompiledPath, patterns: patterns, - platforms: platforms, + runtimes: runtimes, includeTags: includeTags, excludeTags: excludeTags, tags: tags, diff --git a/lib/src/runner/configuration/args.dart b/lib/src/runner/configuration/args.dart index a3a84e7f8..a4c372f91 100644 --- a/lib/src/runner/configuration/args.dart +++ b/lib/src/runner/configuration/args.dart @@ -7,10 +7,10 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:boolean_selector/boolean_selector.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../frontend/timeout.dart'; import '../configuration.dart'; -import 'platform_selection.dart'; +import 'runtime_selection.dart'; import 'reporters.dart'; import 'values.dart'; @@ -18,9 +18,9 @@ import 'values.dart'; final ArgParser _parser = (() { var parser = new ArgParser(allowTrailingOptions: true); - var allPlatforms = TestPlatform.builtIn.toList()..remove(TestPlatform.vm); - if (!Platform.isMacOS) allPlatforms.remove(TestPlatform.safari); - if (!Platform.isWindows) allPlatforms.remove(TestPlatform.internetExplorer); + var allRuntimes = Runtime.builtIn.toList()..remove(Runtime.vm); + if (!Platform.isMacOS) allRuntimes.remove(Runtime.safari); + if (!Platform.isWindows) allRuntimes.remove(Runtime.internetExplorer); parser.addFlag("help", abbr: "h", negatable: false, help: "Shows this usage information."); @@ -65,7 +65,7 @@ final ArgParser _parser = (() { abbr: 'p', help: 'The platform(s) on which to run the tests.\n' '[vm (default), ' - '${allPlatforms.map((platform) => platform.identifier).join(", ")}]', + '${allRuntimes.map((runtime) => runtime.identifier).join(", ")}]', allowMultiple: true); parser.addOption("preset", abbr: 'P', @@ -221,8 +221,8 @@ class _Parser { totalShards: totalShards, timeout: _parseOption('timeout', (value) => new Timeout.parse(value)), patterns: patterns, - platforms: (_ifParsed('platform') as List) - ?.map((platform) => new PlatformSelection(platform)) + runtimes: (_ifParsed('platform') as List) + ?.map((runtime) => new RuntimeSelection(runtime)) ?.toList(), runSkipped: _ifParsed('run-skipped'), chosenPresets: _ifParsed('preset') as List, diff --git a/lib/src/runner/configuration/custom_platform.dart b/lib/src/runner/configuration/custom_runtime.dart similarity index 67% rename from lib/src/runner/configuration/custom_platform.dart rename to lib/src/runner/configuration/custom_runtime.dart index c4372de14..0c9919122 100644 --- a/lib/src/runner/configuration/custom_platform.dart +++ b/lib/src/runner/configuration/custom_runtime.dart @@ -5,30 +5,30 @@ import 'package:source_span/source_span.dart'; import 'package:yaml/yaml.dart'; -/// A user-defined test platform, based on an existing platform but with +/// A user-defined test runtime, based on an existing runtime but with /// different configuration. -class CustomPlatform { - /// The human-friendly name of the platform. +class CustomRuntime { + /// The human-friendly name of the runtime. final String name; /// The location that [name] was defined in the configuration file. final SourceSpan nameSpan; - /// The identifier used to look up the platform. + /// The identifier used to look up the runtime. final String identifier; /// The location that [identifier] was defined in the configuration file. final SourceSpan identifierSpan; - /// The identifier of the platform that this extends. + /// The identifier of the runtime that this extends. final String parent; /// The location that [parent] was defined in the configuration file. final SourceSpan parentSpan; - /// The user's settings for this platform. + /// The user's settings for this runtime. final YamlMap settings; - CustomPlatform(this.name, this.nameSpan, this.identifier, this.identifierSpan, + CustomRuntime(this.name, this.nameSpan, this.identifier, this.identifierSpan, this.parent, this.parentSpan, this.settings); } diff --git a/lib/src/runner/configuration/load.dart b/lib/src/runner/configuration/load.dart index eee575ff1..b9a57f8bf 100644 --- a/lib/src/runner/configuration/load.dart +++ b/lib/src/runner/configuration/load.dart @@ -18,10 +18,10 @@ import '../../util/io.dart'; import '../../utils.dart'; import '../configuration.dart'; import '../configuration/suite.dart'; -import 'custom_platform.dart'; -import 'platform_selection.dart'; -import 'platform_settings.dart'; +import 'custom_runtime.dart'; import 'reporters.dart'; +import 'runtime_selection.dart'; +import 'runtime_settings.dart'; /// A regular expression matching a Dart identifier. /// @@ -208,36 +208,36 @@ class _ConfigurationLoader { var concurrency = _getInt("concurrency"); - var platforms = _getList( + var runtimes = _getList( "platforms", - (platformNode) => new PlatformSelection( - _parseIdentifierLike(platformNode, "Platform name"), - platformNode.span)); + (runtimeNode) => new RuntimeSelection( + _parseIdentifierLike(runtimeNode, "Platform name"), + runtimeNode.span)); var chosenPresets = _getList("add_presets", (presetNode) => _parseIdentifierLike(presetNode, "Preset name")); - var overridePlatforms = _loadOverridePlatforms(); + var overrideRuntimes = _loadOverrideRuntimes(); return new Configuration( pauseAfterLoad: pauseAfterLoad, runSkipped: runSkipped, reporter: reporter, concurrency: concurrency, - platforms: platforms, + runtimes: runtimes, chosenPresets: chosenPresets, - overridePlatforms: overridePlatforms); + overrideRuntimes: overrideRuntimes); } /// Loads the `override_platforms` field. - Map _loadOverridePlatforms() { - var platformsNode = + Map _loadOverrideRuntimes() { + var runtimesNode = _getNode("override_platforms", "map", (value) => value is Map) as YamlMap; - if (platformsNode == null) return const {}; + if (runtimesNode == null) return const {}; - var platforms = {}; - platformsNode.nodes.forEach((identifierNode, valueNode) { + var runtimes = {}; + runtimesNode.nodes.forEach((identifierNode, valueNode) { var identifier = _parseIdentifierLike(identifierNode, "Platform identifier"); @@ -248,10 +248,10 @@ class _ConfigurationLoader { var settings = _expect(map, "settings"); _validate(settings, "Must be a map.", (value) => value is Map); - platforms[identifier] = new PlatformSettings( + runtimes[identifier] = new RuntimeSettings( identifier, identifierNode.span, [settings as YamlMap]); }); - return platforms; + return runtimes; } /// Loads runner configuration that's not allowed in the global configuration @@ -297,7 +297,7 @@ class _ConfigurationLoader { var includeTags = _parseBooleanSelector("include_tags"); var excludeTags = _parseBooleanSelector("exclude_tags"); - var definePlatforms = _loadDefinePlatforms(); + var defineRuntimes = _loadDefineRuntimes(); return new Configuration( pubServePort: pubServePort, @@ -306,7 +306,7 @@ class _ConfigurationLoader { filename: filename, includeTags: includeTags, excludeTags: excludeTags, - definePlatforms: definePlatforms); + defineRuntimes: defineRuntimes); } /// Returns a map representation of the `fold_stack_frames` configuration. @@ -348,13 +348,13 @@ class _ConfigurationLoader { } /// Loads the `define_platforms` field. - Map _loadDefinePlatforms() { - var platformsNode = + Map _loadDefineRuntimes() { + var runtimesNode = _getNode("define_platforms", "map", (value) => value is Map) as YamlMap; - if (platformsNode == null) return const {}; + if (runtimesNode == null) return const {}; - var platforms = {}; - platformsNode.nodes.forEach((identifierNode, valueNode) { + var runtimes = {}; + runtimesNode.nodes.forEach((identifierNode, valueNode) { var identifier = _parseIdentifierLike(identifierNode, "Platform identifier"); @@ -372,16 +372,10 @@ class _ConfigurationLoader { var settings = _expect(map, "settings"); _validate(settings, "Must be a map.", (value) => value is Map); - platforms[identifier] = new CustomPlatform( - name, - nameNode.span, - identifier, - identifierNode.span, - parent, - parentNode.span, - settings as YamlMap); + runtimes[identifier] = new CustomRuntime(name, nameNode.span, identifier, + identifierNode.span, parent, parentNode.span, settings as YamlMap); }); - return platforms; + return runtimes; } /// Throws an exception with [message] if [test] returns `false` when passed diff --git a/lib/src/runner/configuration/reporters.dart b/lib/src/runner/configuration/reporters.dart index 50b711236..fd4f762b8 100644 --- a/lib/src/runner/configuration/reporters.dart +++ b/lib/src/runner/configuration/reporters.dart @@ -35,7 +35,7 @@ final _allReporters = { color: config.color, printPath: config.paths.length > 1 || new Directory(config.paths.single).existsSync(), - printPlatform: config.suiteDefaults.platforms.length > 1)), + printPlatform: config.suiteDefaults.runtimes.length > 1)), "compact": new ReporterDetails("A single line, updated continuously.", (_, engine) => CompactReporter.watch(engine)), "json": new ReporterDetails( diff --git a/lib/src/runner/configuration/platform_selection.dart b/lib/src/runner/configuration/runtime_selection.dart similarity index 58% rename from lib/src/runner/configuration/platform_selection.dart rename to lib/src/runner/configuration/runtime_selection.dart index 386ecfdd9..0585a0ff7 100644 --- a/lib/src/runner/configuration/platform_selection.dart +++ b/lib/src/runner/configuration/runtime_selection.dart @@ -4,19 +4,19 @@ import 'package:source_span/source_span.dart'; -/// A platform on which the user has chosen to run tests. -class PlatformSelection { - /// The name of the platform. +/// A runtime on which the user has chosen to run tests. +class RuntimeSelection { + /// The name of the runtime. final String name; - /// The location in the configuration file of this platform string, or `null` + /// The location in the configuration file of this runtime string, or `null` /// if it was defined outside a configuration file (for example, on the /// command line). final SourceSpan span; - PlatformSelection(this.name, [this.span]); + RuntimeSelection(this.name, [this.span]); - bool operator ==(other) => other is PlatformSelection && other.name == name; + bool operator ==(other) => other is RuntimeSelection && other.name == name; int get hashCode => name.hashCode; } diff --git a/lib/src/runner/configuration/platform_settings.dart b/lib/src/runner/configuration/runtime_settings.dart similarity index 72% rename from lib/src/runner/configuration/platform_settings.dart rename to lib/src/runner/configuration/runtime_settings.dart index 203901564..48900fde3 100644 --- a/lib/src/runner/configuration/platform_settings.dart +++ b/lib/src/runner/configuration/runtime_settings.dart @@ -7,20 +7,20 @@ import 'package:yaml/yaml.dart'; import '../plugin/customizable_platform.dart'; -/// User-defined settings for a built-in test platform. -class PlatformSettings { - /// The identifier used to look up the platform being overridden. +/// User-defined settings for a built-in test runtime. +class RuntimeSettings { + /// The identifier used to look up the runtime being overridden. final String identifier; /// The location that [identifier] was defined in the configuration file. final SourceSpan identifierSpan; - /// The user's settings for this platform. + /// The user's settings for this runtime. /// /// This is a list of settings, from most global to most specific, that will /// eventually be merged using [CustomizablePlatform.mergePlatformSettings]. final List settings; - PlatformSettings(this.identifier, this.identifierSpan, List settings) + RuntimeSettings(this.identifier, this.identifierSpan, List settings) : settings = new List.unmodifiable(settings); } diff --git a/lib/src/runner/configuration/suite.dart b/lib/src/runner/configuration/suite.dart index bae435829..3da73529d 100644 --- a/lib/src/runner/configuration/suite.dart +++ b/lib/src/runner/configuration/suite.dart @@ -9,9 +9,9 @@ import 'package:source_span/source_span.dart'; import '../../backend/metadata.dart'; import '../../backend/platform_selector.dart'; import '../../backend/suite_platform.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../frontend/timeout.dart'; -import 'platform_selection.dart'; +import 'runtime_selection.dart'; /// Suite-level configuration. /// @@ -42,7 +42,7 @@ class SuiteConfiguration { /// Additional arguments to pass to dart2js. /// /// Note that this if multiple suites run the same JavaScript on different - /// platforms, and they have different [dart2jsArgs], only one (undefined) + /// runtimes, and they have different [dart2jsArgs], only one (undefined) /// suite's arguments will be used. final List dart2jsArgs; @@ -52,11 +52,11 @@ class SuiteConfiguration { /// All patterns must match in order for a test to be run. final Set patterns; - /// The set of platforms on which to run tests. - List get platforms => _platforms == null + /// The set of runtimes on which to run tests. + List get runtimes => _runtimes == null ? const ["vm"] - : new List.unmodifiable(_platforms.map((platform) => platform.name)); - final List _platforms; + : new List.unmodifiable(_runtimes.map((runtime) => runtime.name)); + final List _runtimes; /// Only run tests whose tags match this selector. /// @@ -128,7 +128,7 @@ class SuiteConfiguration { Iterable dart2jsArgs, String precompiledPath, Iterable patterns, - Iterable platforms, + Iterable runtimes, BooleanSelector includeTags, BooleanSelector excludeTags, Map tags, @@ -149,7 +149,7 @@ class SuiteConfiguration { dart2jsArgs: dart2jsArgs, precompiledPath: precompiledPath, patterns: patterns, - platforms: platforms, + runtimes: runtimes, includeTags: includeTags, excludeTags: excludeTags, tags: tags, @@ -176,7 +176,7 @@ class SuiteConfiguration { Iterable dart2jsArgs, this.precompiledPath, Iterable patterns, - Iterable platforms, + Iterable runtimes, BooleanSelector includeTags, BooleanSelector excludeTags, Map tags, @@ -186,7 +186,7 @@ class SuiteConfiguration { _runSkipped = runSkipped, dart2jsArgs = _list(dart2jsArgs) ?? const [], patterns = new UnmodifiableSetView(patterns?.toSet() ?? new Set()), - _platforms = _list(platforms), + _runtimes = _list(runtimes), includeTags = includeTags ?? BooleanSelector.all, excludeTags = excludeTags ?? BooleanSelector.none, tags = _map(tags), @@ -234,7 +234,7 @@ class SuiteConfiguration { dart2jsArgs: dart2jsArgs.toList()..addAll(other.dart2jsArgs), precompiledPath: other.precompiledPath ?? precompiledPath, patterns: patterns.union(other.patterns), - platforms: other._platforms ?? _platforms, + runtimes: other._runtimes ?? _runtimes, includeTags: includeTags.intersection(other.includeTags), excludeTags: excludeTags.union(other.excludeTags), tags: _mergeConfigMaps(tags, other.tags), @@ -253,7 +253,7 @@ class SuiteConfiguration { Iterable dart2jsArgs, String precompiledPath, Iterable patterns, - Iterable platforms, + Iterable runtimes, BooleanSelector includeTags, BooleanSelector excludeTags, Map tags, @@ -274,7 +274,7 @@ class SuiteConfiguration { dart2jsArgs: dart2jsArgs?.toList() ?? this.dart2jsArgs, precompiledPath: precompiledPath ?? this.precompiledPath, patterns: patterns ?? this.patterns, - platforms: platforms ?? _platforms, + runtimes: runtimes ?? _runtimes, includeTags: includeTags ?? this.includeTags, excludeTags: excludeTags ?? this.excludeTags, tags: tags ?? this.tags, @@ -291,16 +291,16 @@ class SuiteConfiguration { return config._resolveTags(); } - /// Throws a [FormatException] if [this] refers to any undefined platforms. - void validatePlatforms(List allPlatforms) { + /// Throws a [FormatException] if [this] refers to any undefined runtimes. + void validateRuntimes(List allRuntimes) { var validVariables = - allPlatforms.map((platform) => platform.identifier).toSet(); + allRuntimes.map((runtime) => runtime.identifier).toSet(); _metadata.validatePlatformSelectors(validVariables); - if (_platforms != null) { - for (var selection in _platforms) { - if (!allPlatforms - .any((platform) => platform.identifier == selection.name)) { + if (_runtimes != null) { + for (var selection in _runtimes) { + if (!allRuntimes + .any((runtime) => runtime.identifier == selection.name)) { if (selection.span != null) { throw new SourceSpanFormatException( 'Unknown platform "${selection.name}".', selection.span); @@ -313,7 +313,7 @@ class SuiteConfiguration { onPlatform.forEach((selector, config) { selector.validate(validVariables); - config.validatePlatforms(allPlatforms); + config.validateRuntimes(allRuntimes); }); } diff --git a/lib/src/runner/debugger.dart b/lib/src/runner/debugger.dart index 21cfc25f5..d49d197bc 100644 --- a/lib/src/runner/debugger.dart +++ b/lib/src/runner/debugger.dart @@ -132,18 +132,18 @@ class _Debugger { var noColor = _config.color ? '\u001b[0m' : ''; print(''); - var platform = _suite.platform.platform; - if (platform.isDartVM) { + var runtime = _suite.platform.runtime; + if (runtime.isDartVM) { var url = _suite.environment.observatoryUrl; if (url == null) { print("${yellow}Observatory URL not found. Make sure you're using " - "${platform.name} 1.11 or later.$noColor"); + "${runtime.name} 1.11 or later.$noColor"); } else { print("Observatory URL: $bold$url$noColor"); } } - if (platform.isHeadless) { + if (runtime.isHeadless) { var url = _suite.environment.remoteDebuggerUrl; if (url == null) { print("${yellow}Remote debugger URL not found.$noColor"); @@ -154,12 +154,12 @@ class _Debugger { var buffer = new StringBuffer("${bold}The test runner is paused.${noColor} "); - if (!platform.isHeadless) { - buffer.write("Open the dev console in $platform "); + if (!runtime.isHeadless) { + buffer.write("Open the dev console in $runtime "); } else { buffer.write("Open the remote debugger "); } - if (platform.isDartVM) buffer.write("or the Observatory "); + if (runtime.isDartVM) buffer.write("or the Observatory "); buffer.write("and set breakpoints. Once you're finished, return to " "this terminal and press Enter."); diff --git a/lib/src/runner/load_suite.dart b/lib/src/runner/load_suite.dart index 85d28dd98..2d19f56dd 100644 --- a/lib/src/runner/load_suite.dart +++ b/lib/src/runner/load_suite.dart @@ -14,7 +14,7 @@ import '../backend/metadata.dart'; import '../backend/suite.dart'; import '../backend/suite_platform.dart'; import '../backend/test.dart'; -import '../backend/test_platform.dart'; +import '../backend/runtime.dart'; import '../util/io.dart'; import '../utils.dart'; import 'configuration/suite.dart'; @@ -123,7 +123,7 @@ class LoadSuite extends Suite implements RunnerSuite { return new LoadSuite( "loading ${exception.path}", config ?? SuiteConfiguration.empty, - platform ?? new SuitePlatform(TestPlatform.vm, os: currentOS), + platform ?? new SuitePlatform(Runtime.vm, os: currentOS), () => new Future.error(exception, stackTrace), path: exception.path); } diff --git a/lib/src/runner/loader.dart b/lib/src/runner/loader.dart index a9b97178c..5f1d79809 100644 --- a/lib/src/runner/loader.dart +++ b/lib/src/runner/loader.dart @@ -13,8 +13,8 @@ import 'package:yaml/yaml.dart'; import '../backend/group.dart'; import '../backend/invoker.dart'; +import '../backend/runtime.dart'; import '../backend/suite_platform.dart'; -import '../backend/test_platform.dart'; import '../util/io.dart'; import 'browser/platform.dart'; import 'configuration.dart'; @@ -41,33 +41,33 @@ class Loader { /// All suites that have been created by the loader. final _suites = new Set(); - /// Memoizers for platform plugins, indexed by the platforms they support. - final _platformPlugins = >{}; + /// Memoizers for platform plugins, indexed by the runtimes they support. + final _platformPlugins = >{}; /// The functions to use to load [_platformPlugins]. /// /// These are passed to the plugins' async memoizers when a plugin is needed. - final _platformCallbacks = {}; + final _platformCallbacks = {}; - /// A map of all platforms registered in [_platformCallbacks], indexed by + /// A map of all runtimes registered in [_platformCallbacks], indexed by /// their string identifiers. - final _platformsByIdentifier = {}; + final _runtimesByIdentifier = {}; - /// The user-provided settings for platforms, as a list of settings that will + /// The user-provided settings for runtimes, as a list of settings that will /// be merged together using [CustomizablePlatform.mergePlatformSettings]. - final _platformSettings = >{}; + final _runtimeSettings = >{}; - /// The user-provided settings for platforms. - final _parsedPlatformSettings = {}; + /// The user-provided settings for runtimes. + final _parsedRuntimeSettings = {}; /// All plaforms supported by this [Loader]. - List get allPlatforms => + List get allRuntimes => new List.unmodifiable(_platformCallbacks.keys); - /// The platform variables supported by this loader, in addition the default + /// The runtime variables supported by this loader, in addition the default /// variables that are always supported. - Iterable get _platformVariables => - _platformCallbacks.keys.map((platform) => platform.identifier); + Iterable get _runtimeVariables => + _platformCallbacks.keys.map((runtime) => runtime.identifier); /// Creates a new loader that loads tests on platforms defined in /// [Configuration.current]. @@ -76,95 +76,90 @@ class Loader { /// defaults to the working directory. /// /// The [plugins] register [PlatformPlugin]s that are associated with the - /// provided platforms. When the runner first requests that a suite be loaded - /// for one of the given platforms, the lodaer will call the associated + /// provided runtimes. When the runner first requests that a suite be loaded + /// for one of the given runtimes, the lodaer will call the associated /// callback to load the platform plugin. That plugin is then preserved and - /// used to load all suites for all matching platforms. Platform plugins may - /// override built-in platforms. + /// used to load all suites for all matching runtimes. Platform plugins may + /// override built-in runtimes. Loader( - {String root, - Map, _PlatformPluginFunction> plugins}) { - _registerPlatformPlugin([TestPlatform.vm], () => new VMPlatform()); - _registerPlatformPlugin([TestPlatform.nodeJS], () => new NodePlatform()); + {String root, Map, _PlatformPluginFunction> plugins}) { + _registerPlatformPlugin([Runtime.vm], () => new VMPlatform()); + _registerPlatformPlugin([Runtime.nodeJS], () => new NodePlatform()); _registerPlatformPlugin([ - TestPlatform.dartium, - TestPlatform.contentShell, - TestPlatform.chrome, - TestPlatform.phantomJS, - TestPlatform.firefox, - TestPlatform.safari, - TestPlatform.internetExplorer + Runtime.dartium, + Runtime.contentShell, + Runtime.chrome, + Runtime.phantomJS, + Runtime.firefox, + Runtime.safari, + Runtime.internetExplorer ], () => BrowserPlatform.start(root: root)); - platformCallbacks.forEach((platform, plugin) { - _registerPlatformPlugin([platform], plugin); + platformCallbacks.forEach((runtime, plugin) { + _registerPlatformPlugin([runtime], plugin); }); plugins?.forEach(_registerPlatformPlugin); - _registerCustomPlatforms(); + _registerCustomRuntimes(); - _config.validatePlatforms(allPlatforms); + _config.validateRuntimes(allRuntimes); - _registerPlatformOverrides(); + _registerRuntimeOverrides(); } - /// Registers a [PlatformPlugin] for [platforms]. + /// Registers a [PlatformPlugin] for [runtimes]. void _registerPlatformPlugin( - Iterable platforms, FutureOr getPlugin()) { + Iterable runtimes, FutureOr getPlugin()) { var memoizer = new AsyncMemoizer(); - for (var platform in platforms) { - _platformPlugins[platform] = memoizer; - _platformCallbacks[platform] = getPlugin; - _platformsByIdentifier[platform.identifier] = platform; + for (var runtime in runtimes) { + _platformPlugins[runtime] = memoizer; + _platformCallbacks[runtime] = getPlugin; + _runtimesByIdentifier[runtime.identifier] = runtime; } } - /// Registers user-defined platforms from [Configuration.definePlatforms]. - void _registerCustomPlatforms() { - for (var customPlatform in _config.definePlatforms.values) { - if (_platformsByIdentifier.containsKey(customPlatform.identifier)) { + /// Registers user-defined runtimes from [Configuration.defineRuntimes]. + void _registerCustomRuntimes() { + for (var customRuntime in _config.defineRuntimes.values) { + if (_runtimesByIdentifier.containsKey(customRuntime.identifier)) { throw new SourceSpanFormatException( wordWrap( - 'The platform "${customPlatform.identifier}" already exists. ' + 'The platform "${customRuntime.identifier}" already exists. ' 'Use override_platforms to override it.'), - customPlatform.identifierSpan); + customRuntime.identifierSpan); } - var parent = _platformsByIdentifier[customPlatform.parent]; + var parent = _runtimesByIdentifier[customRuntime.parent]; if (parent == null) { throw new SourceSpanFormatException( - 'Unknown platform.', customPlatform.parentSpan); + 'Unknown platform.', customRuntime.parentSpan); } - var platform = - parent.extend(customPlatform.name, customPlatform.identifier); - _platformPlugins[platform] = _platformPlugins[parent]; - _platformCallbacks[platform] = _platformCallbacks[parent]; - _platformsByIdentifier[platform.identifier] = platform; + var runtime = parent.extend(customRuntime.name, customRuntime.identifier); + _platformPlugins[runtime] = _platformPlugins[parent]; + _platformCallbacks[runtime] = _platformCallbacks[parent]; + _runtimesByIdentifier[runtime.identifier] = runtime; - _platformSettings[platform] = [customPlatform.settings]; + _runtimeSettings[runtime] = [customRuntime.settings]; } } - /// Registers users' platform settings from [Configuration.overridePlatforms]. - void _registerPlatformOverrides() { - for (var settings in _config.overridePlatforms.values) { - var platform = _platformsByIdentifier[settings.identifier]; + /// Registers users' runtime settings from [Configuration.overrideRuntimes]. + void _registerRuntimeOverrides() { + for (var settings in _config.overrideRuntimes.values) { + var runtime = _runtimesByIdentifier[settings.identifier]; - // This is officially validated in [Configuration.validatePlatforms]. - assert(platform != null); + // This is officially validated in [Configuration.validateRuntimes]. + assert(runtime != null); - _platformSettings - .putIfAbsent(platform, () => []) - .addAll(settings.settings); + _runtimeSettings.putIfAbsent(runtime, () => []).addAll(settings.settings); } } - /// Returns the [TestPlatform] registered with this loader that's identified + /// Returns the [Runtime] registered with this loader that's identified /// by [identifier], or `null` if none can be found. - TestPlatform findTestPlatform(String identifier) => - _platformsByIdentifier[identifier]; + Runtime findRuntime(String identifier) => _runtimesByIdentifier[identifier]; /// Loads all test suites in [dir] according to [suiteConfig]. /// @@ -201,7 +196,7 @@ class Loader { String path, SuiteConfiguration suiteConfig) async* { try { suiteConfig = suiteConfig.merge(new SuiteConfiguration.fromMetadata( - parseMetadata(path, _platformVariables.toSet()))); + parseMetadata(path, _runtimeVariables.toSet()))); } on AnalyzerErrorGroup catch (_) { // Ignore the analyzer's error, since its formatting is much worse than // the VM's or dart2js's. @@ -224,9 +219,9 @@ class Loader { return; } - for (var platformName in suiteConfig.platforms) { - var runtime = findTestPlatform(platformName); - assert(runtime != null, 'Unknown platform "$platformName".'); + for (var runtimeName in suiteConfig.runtimes) { + var runtime = findRuntime(runtimeName); + assert(runtime != null, 'Unknown platform "$runtimeName".'); var platform = new SuitePlatform(runtime, os: runtime.isBrowser ? null : currentOS); @@ -249,16 +244,15 @@ class Loader { continue; } - var name = (platform.platform.isJS ? "compiling " : "loading ") + path; + var name = (platform.runtime.isJS ? "compiling " : "loading ") + path; yield new LoadSuite(name, platformConfig, platform, () async { - var memo = _platformPlugins[platform.platform]; + var memo = _platformPlugins[platform.runtime]; try { - var plugin = - await memo.runOnce(_platformCallbacks[platform.platform]); - _customizePlatform(plugin, platform.platform); + var plugin = await memo.runOnce(_platformCallbacks[platform.runtime]); + _customizePlatform(plugin, platform.runtime); var suite = await plugin.load(path, platform, platformConfig, - {"platformVariables": _platformVariables.toList()}); + {"platformVariables": _runtimeVariables.toList()}); if (suite != null) _suites.add(suite); return suite; } catch (error, stackTrace) { @@ -271,31 +265,31 @@ class Loader { } /// Passes user-defined settings to [plugin] if necessary. - void _customizePlatform(PlatformPlugin plugin, TestPlatform platform) { - var parsed = _parsedPlatformSettings[platform]; + void _customizePlatform(PlatformPlugin plugin, Runtime runtime) { + var parsed = _parsedRuntimeSettings[runtime]; if (parsed != null) { - (plugin as CustomizablePlatform).customizePlatform(platform, parsed); + (plugin as CustomizablePlatform).customizePlatform(runtime, parsed); return; } - var settings = _platformSettings[platform]; + var settings = _runtimeSettings[runtime]; if (settings == null) return; if (plugin is CustomizablePlatform) { parsed = settings .map(plugin.parsePlatformSettings) .reduce(plugin.mergePlatformSettings); - plugin.customizePlatform(platform, parsed); - _parsedPlatformSettings[platform] = parsed; + plugin.customizePlatform(runtime, parsed); + _parsedRuntimeSettings[runtime] = parsed; } else { String identifier; SourceSpan span; - if (platform.isChild) { - identifier = platform.parent.identifier; - span = _config.definePlatforms[platform.identifier].parentSpan; + if (runtime.isChild) { + identifier = runtime.parent.identifier; + span = _config.defineRuntimes[runtime.identifier].parentSpan; } else { - identifier = platform.identifier; - span = _config.overridePlatforms[platform.identifier].identifierSpan; + identifier = runtime.identifier; + span = _config.overrideRuntimes[runtime.identifier].identifierSpan; } throw new SourceSpanFormatException( diff --git a/lib/src/runner/node/platform.dart b/lib/src/runner/node/platform.dart index 92c0ca513..f832b5839 100644 --- a/lib/src/runner/node/platform.dart +++ b/lib/src/runner/node/platform.dart @@ -14,8 +14,8 @@ import 'package:path/path.dart' as p; import 'package:stream_channel/stream_channel.dart'; import 'package:yaml/yaml.dart'; +import '../../backend/runtime.dart'; import '../../backend/suite_platform.dart'; -import '../../backend/test_platform.dart'; import '../../util/io.dart'; import '../../util/stack_trace_mapper.dart'; import '../../utils.dart'; @@ -46,10 +46,10 @@ class NodePlatform extends PlatformPlugin /// The HTTP client to use when fetching JS files for `pub serve`. final HttpClient _http; - /// Executable settings for [TestPlatform.nodeJS] and platforms that extend + /// Executable settings for [Runtime.nodeJS] and runtimes that extend /// it. final _settings = { - TestPlatform.nodeJS: new ExecutableSettings( + Runtime.nodeJS: new ExecutableSettings( linuxExecutable: "node", macOSExecutable: "node", windowsExecutable: "node.exe") @@ -67,10 +67,10 @@ class NodePlatform extends PlatformPlugin ExecutableSettings settings1, ExecutableSettings settings2) => settings1.merge(settings2); - void customizePlatform(TestPlatform platform, ExecutableSettings settings) { - var oldSettings = _settings[platform] ?? _settings[platform.root]; + void customizePlatform(Runtime runtime, ExecutableSettings settings) { + var oldSettings = _settings[runtime] ?? _settings[runtime.root]; if (oldSettings != null) settings = oldSettings.merge(settings); - _settings[platform] = settings; + _settings[runtime] = settings; } StreamChannel loadChannel(String path, SuitePlatform platform) => @@ -78,9 +78,7 @@ class NodePlatform extends PlatformPlugin Future load(String path, SuitePlatform platform, SuiteConfiguration suiteConfig, Object message) async { - assert(platform.platform == TestPlatform.nodeJS); - - var pair = await _loadChannel(path, platform.platform, suiteConfig); + var pair = await _loadChannel(path, platform.runtime, suiteConfig); var controller = deserializeSuite(path, platform, suiteConfig, new PluginEnvironment(), pair.first, message); @@ -93,12 +91,12 @@ class NodePlatform extends PlatformPlugin /// /// Returns that channel along with a [StackTraceMapper] representing the /// source map for the compiled suite. - Future> _loadChannel(String path, - TestPlatform platform, SuiteConfiguration suiteConfig) async { + Future> _loadChannel( + String path, Runtime runtime, SuiteConfiguration suiteConfig) async { var server = await MultiServerSocket.loopback(0); try { - var pair = await _spawnProcess(path, platform, suiteConfig, server.port); + var pair = await _spawnProcess(path, runtime, suiteConfig, server.port); var process = pair.first; // Forward Node's standard IO to the print handler so it's associated with @@ -132,11 +130,8 @@ class NodePlatform extends PlatformPlugin /// /// Returns that channel along with a [StackTraceMapper] representing the /// source map for the compiled suite. - Future> _spawnProcess( - String path, - TestPlatform platform, - SuiteConfiguration suiteConfig, - int socketPort) async { + Future> _spawnProcess(String path, + Runtime runtime, SuiteConfiguration suiteConfig, int socketPort) async { var dir = new Directory(_compiledDir).createTempSync('test_').path; var jsPath = p.join(dir, p.basename(path) + ".node_test.dart.js"); @@ -166,8 +161,7 @@ class NodePlatform extends PlatformPlugin sdkRoot: p.toUri(sdkDir)); } - return new Pair( - await _startProcess(platform, jsPath, socketPort), mapper); + return new Pair(await _startProcess(runtime, jsPath, socketPort), mapper); } var url = _config.pubServeUrl.resolveUri( @@ -186,13 +180,13 @@ class NodePlatform extends PlatformPlugin sdkRoot: p.toUri('packages/\$sdk')); } - return new Pair(await _startProcess(platform, jsPath, socketPort), mapper); + return new Pair(await _startProcess(runtime, jsPath, socketPort), mapper); } - /// Starts the Node.js process for [platform] with [jsPath]. + /// Starts the Node.js process for [runtime] with [jsPath]. Future _startProcess( - TestPlatform platform, String jsPath, int socketPort) async { - var settings = _settings[platform]; + Runtime runtime, String jsPath, int socketPort) async { + var settings = _settings[runtime]; var nodeModules = p.absolute('node_modules'); var nodePath = Platform.environment["NODE_PATH"]; @@ -205,7 +199,7 @@ class NodePlatform extends PlatformPlugin } catch (error, stackTrace) { await new Future.error( new ApplicationException( - "Failed to run ${platform.name}: ${getErrorMessage(error)}"), + "Failed to run ${runtime.name}: ${getErrorMessage(error)}"), stackTrace); return null; } diff --git a/lib/src/runner/plugin/customizable_platform.dart b/lib/src/runner/plugin/customizable_platform.dart index e1ebd57e2..8f8e2e5dc 100644 --- a/lib/src/runner/plugin/customizable_platform.dart +++ b/lib/src/runner/plugin/customizable_platform.dart @@ -4,24 +4,23 @@ import 'package:yaml/yaml.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import 'platform.dart'; /// An interface for [PlatformPlugin]s that support per-platform customization. /// /// If a [PlatformPlugin] implements this, the user will be able to override the -/// [TestPlatform]s it supports using the +/// [Runtime]s it supports using the /// [`override_platforms`][override_platforms] configuration field, and define -/// new platforms based on them using the [`define_platforms`][define_platforms] +/// new runtimes based on them using the [`define_platforms`][define_platforms] /// field. The custom settings will be passed to the plugin using /// [customizePlatform]. /// /// [override_platforms]: https://github.com/dart-lang/test/blob/master/doc/configuration.md#override_platforms /// [define_platforms]: https://github.com/dart-lang/test/blob/master/doc/configuration.md#define_platforms /// -/// Plugins that implement this **must** support children of recognized -/// platforms (created by [TestPlatform.extend]) in their [loadChannel] or -/// [load] methods. +/// Plugins that implement this **must** support children of recognized runtimes +/// (created by [Runtime.extend]) in their [loadChannel] or [load] methods. abstract class CustomizablePlatform extends PlatformPlugin { /// Parses user-provided [settings] for a custom platform into a /// plugin-defined format. @@ -43,14 +42,14 @@ abstract class CustomizablePlatform extends PlatformPlugin { /// platform's settings with its parent's. T mergePlatformSettings(T settings1, T settings2); - /// Defines user-provided [settings] for [platform]. + /// Defines user-provided [settings] for [runtime]. /// - /// The [platform] is a platform this plugin was declared to accept when - /// registered with [Loader.registerPlatformPlugin], or a platform whose - /// [TestPlatform.parent] is one of those platforms. Subclasses should - /// customize the behavior for these platforms when [loadChannel] or [load] is - /// called with the given [platform], using the [settings] which are parsed by + /// The [runtime] is a runtime this plugin was declared to accept when + /// registered with [Loader.registerPlatformPlugin], or a runtime whose + /// [Runtime.parent] is one of those runtimes. Subclasses should customize the + /// behavior for these runtimes when [loadChannel] or [load] is called with + /// the given [runtime], using the [settings] which are parsed by /// [parsePlatformSettings]. This is guaranteed to be called before either /// `load` method. - void customizePlatform(TestPlatform platform, T settings); + void customizePlatform(Runtime runtime, T settings); } diff --git a/lib/src/runner/plugin/hack_register_platform.dart b/lib/src/runner/plugin/hack_register_platform.dart index ce2cfbf56..9d76f41b4 100644 --- a/lib/src/runner/plugin/hack_register_platform.dart +++ b/lib/src/runner/plugin/hack_register_platform.dart @@ -4,7 +4,7 @@ import 'dart:collection'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../utils.dart'; import 'platform.dart'; @@ -12,23 +12,23 @@ import 'platform.dart'; /// /// **Do not access this outside the test package**. final platformCallbacks = - new UnmodifiableMapView(_platformCallbacks); -final _platformCallbacks = {}; + new UnmodifiableMapView(_platformCallbacks); +final _platformCallbacks = {}; /// **Do not call this function without express permission from the test package /// authors**. /// -/// Registers a [PlatformPlugin] for [platforms]. +/// Registers a [PlatformPlugin] for [runtimes]. /// /// This globally registers a plugin for all [Loader]s. When the runner first -/// requests that a suite be loaded for one of the given platforms, this will +/// requests that a suite be loaded for one of the given runtimes, this will /// call [getPlugin] to load the platform plugin. It may return either a /// [PlatformPlugin] or a [Future]. That plugin is then -/// preserved and used to load all suites for all matching platforms. +/// preserved and used to load all suites for all matching runtimes. /// -/// This overwrites the default plugins for those platforms. -void registerPlatformPlugin(Iterable platforms, getPlugin()) { - for (var platform in platforms) { - _platformCallbacks[platform] = getPlugin; +/// This overwrites the default plugins for those runtimes. +void registerPlatformPlugin(Iterable runtimes, getPlugin()) { + for (var runtime in runtimes) { + _platformCallbacks[runtime] = getPlugin; } } diff --git a/lib/src/runner/reporter/compact.dart b/lib/src/runner/reporter/compact.dart index e7ce3c33e..8002cd08e 100644 --- a/lib/src/runner/reporter/compact.dart +++ b/lib/src/runner/reporter/compact.dart @@ -360,9 +360,9 @@ class CompactReporter implements Reporter { name = "${liveTest.suite.path}: $name"; } - if (_config.suiteDefaults.platforms.length > 1 && + if (_config.suiteDefaults.runtimes.length > 1 && liveTest.suite.platform != null) { - name = "[${liveTest.suite.platform.platform.name}] $name"; + name = "[${liveTest.suite.platform.runtime.name}] $name"; } if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; diff --git a/lib/src/runner/reporter/expanded.dart b/lib/src/runner/reporter/expanded.dart index 9e714ceb6..613e6b9e4 100644 --- a/lib/src/runner/reporter/expanded.dart +++ b/lib/src/runner/reporter/expanded.dart @@ -306,8 +306,8 @@ class ExpandedReporter implements Reporter { name = "${liveTest.suite.path}: $name"; } - if (_printPlatform && liveTest.suite.platform != null) { - name = "[${liveTest.suite.platform.platform.name}] $name"; + if (_printPlatform) { + name = "[${liveTest.suite.platform.runtime.name}] $name"; } if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; diff --git a/lib/src/runner/reporter/json.dart b/lib/src/runner/reporter/json.dart index 6f251dc5d..480dc9503 100644 --- a/lib/src/runner/reporter/json.dart +++ b/lib/src/runner/reporter/json.dart @@ -11,7 +11,7 @@ import '../../backend/live_test.dart'; import '../../backend/metadata.dart'; import '../../backend/state.dart'; import '../../backend/suite.dart'; -import '../../backend/test_platform.dart'; +import '../../backend/runtime.dart'; import '../../frontend/expect.dart'; import '../configuration.dart'; import '../configuration/suite.dart'; @@ -131,7 +131,7 @@ class JsonReporter implements Reporter { "metadata": _serializeMetadata(suiteConfig, liveTest.test.metadata) }, liveTest.test, - liveTest.suite.platform.platform) + liveTest.suite.platform.runtime) }); /// Convert the future to a stream so that the subscription can be paused or @@ -182,7 +182,7 @@ class JsonReporter implements Reporter { _emit("suite", { "suite": { "id": id, - "platform": suite.platform.platform.identifier, + "platform": suite.platform.runtime.identifier, "path": suite.path } }); @@ -218,7 +218,7 @@ class JsonReporter implements Reporter { "testCount": group.testCount }, group, - suite.platform.platform) + suite.platform.runtime) }); parentID = id; return id; @@ -284,9 +284,9 @@ class JsonReporter implements Reporter { /// /// Returns [map]. Map _addFrameInfo(SuiteConfiguration suiteConfig, - Map map, GroupEntry entry, TestPlatform platform) { + Map map, GroupEntry entry, Runtime runtime) { var frame = entry.trace?.frames?.first; - if (suiteConfig.jsTrace && platform.isJS) frame = null; + if (suiteConfig.jsTrace && runtime.isJS) frame = null; map["line"] = frame?.line; map["column"] = frame?.column; diff --git a/lib/src/runner/vm/platform.dart b/lib/src/runner/vm/platform.dart index d3842ac9e..133e1cb0e 100644 --- a/lib/src/runner/vm/platform.dart +++ b/lib/src/runner/vm/platform.dart @@ -8,8 +8,8 @@ import 'dart:isolate'; import 'package:path/path.dart' as p; import 'package:stream_channel/stream_channel.dart'; +import '../../backend/runtime.dart'; import '../../backend/suite_platform.dart'; -import '../../backend/test_platform.dart'; import '../../util/dart.dart' as dart; import '../configuration.dart'; import '../load_exception.dart'; @@ -23,7 +23,7 @@ class VMPlatform extends PlatformPlugin { VMPlatform(); StreamChannel loadChannel(String path, SuitePlatform platform) { - assert(platform.platform == TestPlatform.vm); + assert(platform.runtime == Runtime.vm); var isolate; var channel = StreamChannelCompleter.fromFuture(() async { diff --git a/lib/test.dart b/lib/test.dart index 2d9a7ab9a..cc84803ef 100644 --- a/lib/test.dart +++ b/lib/test.dart @@ -8,8 +8,8 @@ import 'package:path/path.dart' as p; import 'src/backend/declarer.dart'; import 'src/backend/invoker.dart'; +import 'src/backend/runtime.dart'; import 'src/backend/suite_platform.dart'; -import 'src/backend/test_platform.dart'; import 'src/frontend/timeout.dart'; import 'src/runner/configuration/suite.dart'; import 'src/runner/engine.dart'; @@ -62,7 +62,7 @@ Declarer get _declarer { const PluginEnvironment(), SuiteConfiguration.empty, _globalDeclarer.build(), - new SuitePlatform(TestPlatform.vm, os: currentOSGuess), + new SuitePlatform(Runtime.vm, os: currentOSGuess), path: p.prettyUri(Uri.base)); var engine = new Engine(); diff --git a/test/backend/metadata_test.dart b/test/backend/metadata_test.dart index a02a0baf0..dff315e3f 100644 --- a/test/backend/metadata_test.dart +++ b/test/backend/metadata_test.dart @@ -6,8 +6,8 @@ import 'package:boolean_selector/boolean_selector.dart'; import 'package:test/src/backend/metadata.dart'; import 'package:test/src/backend/platform_selector.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/backend/suite_platform.dart'; -import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/frontend/skip.dart'; import 'package:test/src/frontend/timeout.dart'; import 'package:test/test.dart'; @@ -145,14 +145,14 @@ void main() { }); var key = metadata.onPlatform.keys.first; - expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isTrue); - expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isFalse); + expect(key.evaluate(new SuitePlatform(Runtime.chrome)), isTrue); + expect(key.evaluate(new SuitePlatform(Runtime.vm)), isFalse); var value = metadata.onPlatform.values.first; expect(value.timeout.scaleFactor, equals(2)); key = metadata.onPlatform.keys.last; - expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); - expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isFalse); + expect(key.evaluate(new SuitePlatform(Runtime.vm)), isTrue); + expect(key.evaluate(new SuitePlatform(Runtime.chrome)), isFalse); value = metadata.onPlatform.values.last; expect(value.skip, isTrue); expect(value.timeout.scaleFactor, equals(3)); diff --git a/test/runner/browser/loader_test.dart b/test/runner/browser/loader_test.dart index 60c4b67e2..e0262f054 100644 --- a/test/runner/browser/loader_test.dart +++ b/test/runner/browser/loader_test.dart @@ -9,10 +9,10 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test_descriptor/test_descriptor.dart' as d; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/test.dart'; -import 'package:test/src/backend/test_platform.dart'; -import 'package:test/src/runner/configuration/platform_selection.dart'; +import 'package:test/src/runner/configuration/runtime_selection.dart'; import 'package:test/src/runner/configuration/suite.dart'; import 'package:test/src/runner/loader.dart'; import 'package:test/test.dart'; @@ -23,7 +23,7 @@ Loader _loader; /// A configuration that loads suites on Chrome. final _chrome = new SuiteConfiguration( - platforms: [new PlatformSelection(TestPlatform.chrome.identifier)]); + runtimes: [new RuntimeSelection(Runtime.chrome.identifier)]); void main() { setUp(() async { @@ -58,7 +58,7 @@ void main() { test("returns a suite with the file path and platform", () { expect(suite.path, equals(p.join(d.sandbox, 'a_test.dart'))); - expect(suite.platform.platform, equals(TestPlatform.chrome)); + expect(suite.platform.runtime, equals(Runtime.chrome)); }); test("returns tests with the correct names", () { @@ -126,15 +126,15 @@ Future main() { var suites = await _loader .loadFile( path, - new SuiteConfiguration(platforms: [ - new PlatformSelection(TestPlatform.vm.identifier), - new PlatformSelection(TestPlatform.chrome.identifier) + new SuiteConfiguration(runtimes: [ + new RuntimeSelection(Runtime.vm.identifier), + new RuntimeSelection(Runtime.chrome.identifier) ])) .asyncMap((loadSuite) => loadSuite.getSuite()) .toList(); - expect(suites[0].platform.platform, equals(TestPlatform.vm)); + expect(suites[0].platform.runtime, equals(Runtime.vm)); expect(suites[0].path, equals(path)); - expect(suites[1].platform.platform, equals(TestPlatform.chrome)); + expect(suites[1].platform.runtime, equals(Runtime.chrome)); expect(suites[1].path, equals(path)); for (var suite in suites) { diff --git a/test/runner/configuration/custom_platform_test.dart b/test/runner/configuration/custom_platform_test.dart index 9c4b2a2a1..ca9e0ee94 100644 --- a/test/runner/configuration/custom_platform_test.dart +++ b/test/runner/configuration/custom_platform_test.dart @@ -9,7 +9,7 @@ import 'dart:io'; import 'package:test_descriptor/test_descriptor.dart' as d; import 'package:test_process/test_process.dart'; -import 'package:test/src/backend/test_platform.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/runner/browser/default_settings.dart'; import 'package:test/src/util/exit_codes.dart' as exit_codes; import 'package:test/test.dart'; @@ -82,7 +82,7 @@ void main() { path = await process.stdout.next; await process.shouldExit(0); } else { - path = defaultSettings[TestPlatform.chrome].executable; + path = defaultSettings[Runtime.chrome].executable; } await d.file("dart_test.yaml", """ @@ -480,7 +480,7 @@ void main() { path = await process.stdout.next; await process.shouldExit(0); } else { - path = defaultSettings[TestPlatform.chrome].executable; + path = defaultSettings[Runtime.chrome].executable; } await d.file("dart_test.yaml", """ diff --git a/test/runner/configuration/suite_test.dart b/test/runner/configuration/suite_test.dart index e7db1e46f..253685304 100644 --- a/test/runner/configuration/suite_test.dart +++ b/test/runner/configuration/suite_test.dart @@ -7,8 +7,8 @@ import 'package:boolean_selector/boolean_selector.dart'; import 'package:test/test.dart'; import 'package:test/src/backend/platform_selector.dart'; -import 'package:test/src/backend/test_platform.dart'; -import 'package:test/src/runner/configuration/platform_selection.dart'; +import 'package:test/src/backend/runtime.dart'; +import 'package:test/src/runner/configuration/runtime_selection.dart'; import 'package:test/src/runner/configuration/suite.dart'; void main() { @@ -19,22 +19,21 @@ void main() { expect(merged.jsTrace, isFalse); expect(merged.runSkipped, isFalse); expect(merged.precompiledPath, isNull); - expect(merged.platforms, equals([TestPlatform.vm.identifier])); + expect(merged.runtimes, equals([Runtime.vm.identifier])); }); test("if only the old configuration's is defined, uses it", () { var merged = new SuiteConfiguration( - jsTrace: true, - runSkipped: true, - precompiledPath: "/tmp/js", - platforms: [ - new PlatformSelection(TestPlatform.chrome.identifier) - ]).merge(new SuiteConfiguration()); + jsTrace: true, + runSkipped: true, + precompiledPath: "/tmp/js", + runtimes: [new RuntimeSelection(Runtime.chrome.identifier)]) + .merge(new SuiteConfiguration()); expect(merged.jsTrace, isTrue); expect(merged.runSkipped, isTrue); expect(merged.precompiledPath, equals("/tmp/js")); - expect(merged.platforms, equals([TestPlatform.chrome.identifier])); + expect(merged.runtimes, equals([Runtime.chrome.identifier])); }); test("if only the new configuration's is defined, uses it", () { @@ -42,14 +41,12 @@ void main() { jsTrace: true, runSkipped: true, precompiledPath: "/tmp/js", - platforms: [ - new PlatformSelection(TestPlatform.chrome.identifier) - ])); + runtimes: [new RuntimeSelection(Runtime.chrome.identifier)])); expect(merged.jsTrace, isTrue); expect(merged.runSkipped, isTrue); expect(merged.precompiledPath, equals("/tmp/js")); - expect(merged.platforms, equals([TestPlatform.chrome.identifier])); + expect(merged.runtimes, equals([Runtime.chrome.identifier])); }); test( @@ -59,20 +56,18 @@ void main() { jsTrace: false, runSkipped: true, precompiledPath: "/tmp/js", - platforms: [new PlatformSelection(TestPlatform.chrome.identifier)]); + runtimes: [new RuntimeSelection(Runtime.chrome.identifier)]); var newer = new SuiteConfiguration( jsTrace: true, runSkipped: false, precompiledPath: "../js", - platforms: [ - new PlatformSelection(TestPlatform.firefox.identifier) - ]); + runtimes: [new RuntimeSelection(Runtime.firefox.identifier)]); var merged = older.merge(newer); expect(merged.jsTrace, isTrue); expect(merged.runSkipped, isFalse); expect(merged.precompiledPath, equals("../js")); - expect(merged.platforms, equals([TestPlatform.firefox.identifier])); + expect(merged.runtimes, equals([Runtime.firefox.identifier])); }); }); diff --git a/test/runner/load_suite_test.dart b/test/runner/load_suite_test.dart index 8003cd53a..1cf9587d8 100644 --- a/test/runner/load_suite_test.dart +++ b/test/runner/load_suite_test.dart @@ -8,7 +8,7 @@ import 'dart:async'; import 'package:test/src/backend/group.dart'; import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/test.dart'; -import 'package:test/src/backend/test_platform.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/runner/configuration/suite.dart'; import 'package:test/src/runner/load_exception.dart'; import 'package:test/src/runner/load_suite.dart'; @@ -124,7 +124,7 @@ void main() { expect(suite.group.entries, hasLength(1)); var newSuite = suite.changeSuite((suite) => suite); - expect(newSuite.platform.platform, equals(TestPlatform.vm)); + expect(newSuite.platform.runtime, equals(Runtime.vm)); expect(newSuite.group.entries.single.name, equals(suite.group.entries.single.name)); }); diff --git a/test/runner/loader_test.dart b/test/runner/loader_test.dart index 16ac88fa6..13eeae5db 100644 --- a/test/runner/loader_test.dart +++ b/test/runner/loader_test.dart @@ -9,7 +9,7 @@ import 'package:test_descriptor/test_descriptor.dart' as d; import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/test.dart'; -import 'package:test/src/backend/test_platform.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/runner/configuration/suite.dart'; import 'package:test/src/runner/loader.dart'; import 'package:test/test.dart'; @@ -51,7 +51,7 @@ void main() { test("returns a suite with the file path and platform", () { expect(suite.path, equals(p.join(d.sandbox, 'a_test.dart'))); - expect(suite.platform.platform, equals(TestPlatform.vm)); + expect(suite.platform.runtime, equals(Runtime.vm)); }); test("returns entries with the correct names and platforms", () { diff --git a/test/runner/parse_metadata_test.dart b/test/runner/parse_metadata_test.dart index ce1904705..d33fe0f64 100644 --- a/test/runner/parse_metadata_test.dart +++ b/test/runner/parse_metadata_test.dart @@ -8,8 +8,8 @@ import 'dart:io'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test/src/backend/platform_selector.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/backend/suite_platform.dart'; -import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/runner/parse_metadata.dart'; import 'package:test/src/util/io.dart'; @@ -43,20 +43,18 @@ void main() { new File(_path).writeAsStringSync("@foo.TestOn('vm')\n" "import 'package:test/test.dart' as foo;"); var metadata = parseMetadata(_path, new Set()); + expect(metadata.testOn.evaluate(new SuitePlatform(Runtime.vm)), isTrue); expect( - metadata.testOn.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); - expect(metadata.testOn.evaluate(new SuitePlatform(TestPlatform.chrome)), - isFalse); + metadata.testOn.evaluate(new SuitePlatform(Runtime.chrome)), isFalse); }); group("@TestOn:", () { test("parses a valid annotation", () { new File(_path).writeAsStringSync("@TestOn('vm')\nlibrary foo;"); var metadata = parseMetadata(_path, new Set()); + expect(metadata.testOn.evaluate(new SuitePlatform(Runtime.vm)), isTrue); expect( - metadata.testOn.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); - expect(metadata.testOn.evaluate(new SuitePlatform(TestPlatform.chrome)), - isFalse); + metadata.testOn.evaluate(new SuitePlatform(Runtime.chrome)), isFalse); }); test("ignores a constructor named TestOn", () { @@ -364,14 +362,14 @@ library foo;"""); var metadata = parseMetadata(_path, new Set()); var key = metadata.onPlatform.keys.first; - expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isTrue); - expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isFalse); + expect(key.evaluate(new SuitePlatform(Runtime.chrome)), isTrue); + expect(key.evaluate(new SuitePlatform(Runtime.vm)), isFalse); var value = metadata.onPlatform.values.first; expect(value.timeout.scaleFactor, equals(2)); key = metadata.onPlatform.keys.last; - expect(key.evaluate(new SuitePlatform(TestPlatform.vm)), isTrue); - expect(key.evaluate(new SuitePlatform(TestPlatform.chrome)), isFalse); + expect(key.evaluate(new SuitePlatform(Runtime.vm)), isTrue); + expect(key.evaluate(new SuitePlatform(Runtime.chrome)), isFalse); value = metadata.onPlatform.values.last; expect(value.skip, isTrue); expect(value.timeout.scaleFactor, equals(3)); diff --git a/test/utils.dart b/test/utils.dart index 4810623d1..d534616bd 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -11,10 +11,10 @@ import 'package:test/src/backend/group_entry.dart'; import 'package:test/src/backend/invoker.dart'; import 'package:test/src/backend/live_test.dart'; import 'package:test/src/backend/metadata.dart'; +import 'package:test/src/backend/runtime.dart'; import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/suite.dart'; import 'package:test/src/backend/suite_platform.dart'; -import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/runner/application_exception.dart'; import 'package:test/src/runner/configuration/suite.dart'; import 'package:test/src/runner/engine.dart'; @@ -30,7 +30,7 @@ import 'package:test/test.dart'; final String closureString = (() {}).toString(); /// A dummy suite platform to use for testing suites. -final suitePlatform = new SuitePlatform(TestPlatform.vm); +final suitePlatform = new SuitePlatform(Runtime.vm); // The last state change detected via [expectStates]. State lastState; From bbfe7c58dc72a3e425b89db49cdc873bd9153fbb Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 27 Feb 2018 14:56:05 -0800 Subject: [PATCH 4/4] Add comments about platform vs runtime --- lib/src/runner/configuration/args.dart | 5 +++++ lib/src/runner/configuration/load.dart | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/src/runner/configuration/args.dart b/lib/src/runner/configuration/args.dart index a4c372f91..f984c08fb 100644 --- a/lib/src/runner/configuration/args.dart +++ b/lib/src/runner/configuration/args.dart @@ -61,6 +61,11 @@ final ArgParser _parser = (() { help: 'Run skipped tests instead of skipping them.'); parser.addSeparator("======== Running Tests"); + + // The UI term "platform" corresponds with the implementation term "runtime". + // The [Runtime] class used to be called [TestPlatform], but it was changed to + // avoid conflicting with [SuitePlatform]. We decided not to also change the + // UI to avoid a painful migration. parser.addOption("platform", abbr: 'p', help: 'The platform(s) on which to run the tests.\n' diff --git a/lib/src/runner/configuration/load.dart b/lib/src/runner/configuration/load.dart index b9a57f8bf..69f5b2638 100644 --- a/lib/src/runner/configuration/load.dart +++ b/lib/src/runner/configuration/load.dart @@ -208,6 +208,10 @@ class _ConfigurationLoader { var concurrency = _getInt("concurrency"); + // The UI term "platform" corresponds with the implementation term + // "runtime". The [Runtime] class used to be called [TestPlatform], but it + // was changed to avoid conflicting with [SuitePlatform]. We decided not to + // also change the UI to avoid a painful migration. var runtimes = _getList( "platforms", (runtimeNode) => new RuntimeSelection(