Skip to content

Commit 7ce978b

Browse files
committed
Tighten types in test.dart even more.
This removes all implicit casts and many implicit uses of dynamic. It adds a gratuitous number of explicit "as" casts and arguably makes the code worse. This is an interim step towards replacing the big configuration map with an actual typed object. These "as" casts should help catch places where the configuration object is being used and where the code will need to be changed to use a new object. [email protected] Review-Url: https://codereview.chromium.org/2903703002 .
1 parent d32e55e commit 7ce978b

24 files changed

+421
-369
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
analyzer:
2-
strong-mode: true
2+
strong-mode:
3+
implicit-casts: false

tools/testing/dart/android.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ Future<AdbCommandResult> _executeCommand(String executable, List<String> args,
7676
if (timer != null) timer.cancel();
7777

7878
String command = "$executable ${args.join(' ')}";
79-
return new AdbCommandResult(
80-
command, results[0], results[1], results[2], timedOut);
79+
return new AdbCommandResult(command, results[0] as String,
80+
results[1] as String, results[2] as int, timedOut);
8181
});
8282
}
8383

@@ -251,7 +251,7 @@ class AdbDevice {
251251
* Upload data to the device, unless [local] is the same as the most recently
252252
* used source for [remote].
253253
*/
254-
Future pushCachedData(String local, String remote) {
254+
Future<AdbCommandResult> pushCachedData(String local, String remote) {
255255
if (_cachedData[remote] == local) {
256256
return new Future.value(
257257
new AdbCommandResult("Skipped cached push", "", "", 0, false));
@@ -390,7 +390,7 @@ class AdbHelper {
390390
"stderr: ${result.stderr}]");
391391
}
392392
return _deviceLineRegexp
393-
.allMatches(result.stdout)
393+
.allMatches(result.stdout as String)
394394
.map((Match m) => m.group(1))
395395
.toList();
396396
});

tools/testing/dart/browser_controller.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,15 @@ class Chrome extends Browser {
468468
_logEvent("Make sure $_binary is a valid program for running chrome");
469469
return false;
470470
}
471-
_version = versionResult.stdout;
471+
_version = versionResult.stdout as String;
472472
return true;
473473
});
474474
}
475475

476476
Future<bool> start(String url) {
477477
_logEvent("Starting chrome browser on: $url");
478478
// Get the version and log that.
479-
return _getVersion().then((success) {
479+
return _getVersion().then<bool>((success) {
480480
if (!success) return false;
481481
_logEvent("Got version: $_version");
482482

@@ -615,9 +615,11 @@ class IE extends Browser {
615615
// HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
616616
// version REG_SZ 9.0.8112.16421
617617
var findString = "REG_SZ";
618-
var index = result.stdout.indexOf(findString);
618+
var index = (result.stdout as String).indexOf(findString);
619619
if (index > 0) {
620-
return result.stdout.substring(index + findString.length).trim();
620+
return (result.stdout as String)
621+
.substring(index + findString.length)
622+
.trim();
621623
}
622624
}
623625
return "Could not get the version of internet explorer";
@@ -817,7 +819,7 @@ class Firefox extends Browser {
817819
_logEvent("Make sure $_binary is a valid program for running firefox");
818820
return new Future.value(false);
819821
}
820-
version = versionResult.stdout;
822+
version = versionResult.stdout as String;
821823
_logEvent("Got version: $version");
822824

823825
return Directory.systemTemp.createTemp().then((userDir) {
@@ -943,7 +945,7 @@ class BrowserTestRunner {
943945
/// If the queue was recently empty, don't start another browser.
944946
static const Duration MIN_NONEMPTY_QUEUE_TIME = const Duration(seconds: 1);
945947

946-
final Map<String, String> configuration;
948+
final Map<String, dynamic> configuration;
947949
final BrowserTestingServer testingServer;
948950

949951
final String localIp;
@@ -996,12 +998,12 @@ class BrowserTestRunner {
996998
if (_currentStartingBrowserId == id) _currentStartingBrowserId = null;
997999
}
9981000

999-
BrowserTestRunner(Map configuration, String localIp, String browserName,
1000-
this.maxNumBrowsers)
1001+
BrowserTestRunner(Map<String, dynamic> configuration, String localIp,
1002+
String browserName, this.maxNumBrowsers)
10011003
: configuration = configuration,
10021004
localIp = localIp,
10031005
browserName = (browserName == 'ff') ? 'firefox' : browserName,
1004-
checkedMode = configuration['checked'],
1006+
checkedMode = configuration['checked'] as bool,
10051007
testingServer = new BrowserTestingServer(
10061008
configuration,
10071009
localIp,
@@ -1380,7 +1382,7 @@ class BrowserTestingServer {
13801382
this.configuration, this.localIp, this.useIframe, this.requiresFocus);
13811383

13821384
Future start() {
1383-
var testDriverErrorPort = configuration['test_driver_error_port'];
1385+
var testDriverErrorPort = configuration['test_driver_error_port'] as int;
13841386
return HttpServer
13851387
.bind(localIp, testDriverErrorPort)
13861388
.then(setupErrorServer)
@@ -1416,7 +1418,7 @@ class BrowserTestingServer {
14161418
}
14171419

14181420
void setupDispatchingServer(_) {
1419-
DispatchingServer server = configuration['_servers_'].server;
1421+
var server = (configuration['_servers_'] as TestingServers).server;
14201422
void noCache(HttpRequest request) {
14211423
request.response.headers
14221424
.set("Cache-Control", "no-cache, no-store, must-revalidate");
@@ -1532,7 +1534,7 @@ class BrowserTestingServer {
15321534
exit(1);
15331535
// This should never happen - exit immediately;
15341536
}
1535-
var port = configuration['_servers_'].port;
1537+
var port = (configuration['_servers_'] as TestingServers).port;
15361538
return "http://$localIp:$port/driver/$browserId";
15371539
}
15381540

tools/testing/dart/co19_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const List<List<String>> COMMAND_LINES = const <List<String>>[
6060
void main(List<String> args) {
6161
TestUtils.setDartDirUri(Platform.script.resolve('../../..'));
6262
var optionsParser = new OptionsParser();
63-
var configurations = <Map>[];
63+
var configurations = <Map<String, dynamic>>[];
6464
for (var commandLine in COMMAND_LINES) {
6565
var arguments = <String>[];
6666
arguments.addAll(COMMON_ARGUMENTS);

tools/testing/dart/co19_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'test_suite.dart';
1010
class Co19TestSuite extends StandardTestSuite {
1111
RegExp _testRegExp = new RegExp(r"t[0-9]{2}.dart$");
1212

13-
Co19TestSuite(Map configuration)
13+
Co19TestSuite(Map<String, dynamic> configuration)
1414
: super(configuration, "co19", new Path("tests/co19/src"), [
1515
"tests/co19/co19-co19.status",
1616
"tests/co19/co19-analyzer.status",

tools/testing/dart/compiler_configuration.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ abstract class CompilerConfiguration {
5656
// TODO(ahe): Remove this constructor and move the switch to
5757
// test_options.dart. We probably want to store an instance of
5858
// [CompilerConfiguration] in [configuration] there.
59-
factory CompilerConfiguration(Map configuration) {
60-
String compiler = configuration['compiler'];
59+
factory CompilerConfiguration(Map<String, dynamic> configuration) {
60+
var compiler = configuration['compiler'] as String;
6161

6262
// TODO(ahe): Move these booleans into a struction configuration object
6363
// which can eventually completely replace the Map-based configuration
6464
// object.
65-
bool isDebug = configuration['mode'] == 'debug';
66-
bool isChecked = configuration['checked'];
67-
bool isStrong = configuration['strong'];
68-
bool isHostChecked = configuration['host_checked'];
69-
bool useSdk = configuration['use_sdk'];
70-
bool isCsp = configuration['csp'];
71-
bool useBlobs = configuration['use_blobs'];
72-
bool hotReload = configuration['hot_reload'];
73-
bool hotReloadRollback = configuration['hot_reload_rollback'];
74-
bool useFastStartup = configuration['fast_startup'];
75-
bool useKernelInDart2js = configuration['dart2js_with_kernel'];
65+
var isDebug = (configuration['mode'] as String) == 'debug';
66+
var isChecked = configuration['checked'] as bool;
67+
var isStrong = configuration['strong'] as bool;
68+
var isHostChecked = configuration['host_checked'] as bool;
69+
var useSdk = configuration['use_sdk'] as bool;
70+
var isCsp = configuration['csp'] as bool;
71+
var useBlobs = configuration['use_blobs'] as bool;
72+
var hotReload = configuration['hot_reload'] as bool;
73+
var hotReloadRollback = configuration['hot_reload_rollback'] as bool;
74+
var useFastStartup = configuration['fast_startup'] as bool;
75+
var useKernelInDart2js = configuration['dart2js_with_kernel'] as bool;
7676

7777
switch (compiler) {
7878
case 'dart2analyzer':
@@ -100,7 +100,7 @@ abstract class CompilerConfiguration {
100100
return new PrecompilerCompilerConfiguration(
101101
isDebug: isDebug,
102102
isChecked: isChecked,
103-
arch: configuration['arch'],
103+
arch: configuration['arch'] as String,
104104
useBlobs: useBlobs,
105105
isAndroid: configuration['system'] == 'android');
106106
case 'dartk':
@@ -116,7 +116,7 @@ abstract class CompilerConfiguration {
116116
return new PrecompilerCompilerConfiguration(
117117
isDebug: isDebug,
118118
isChecked: isChecked,
119-
arch: configuration['arch'],
119+
arch: configuration['arch'] as String,
120120
useBlobs: useBlobs,
121121
isAndroid: configuration['system'] == 'android',
122122
useDfe: true);

tools/testing/dart/drt_updater.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ _DartiumUpdater _contentShellUpdater;
7171
_DartiumUpdater _dartiumUpdater;
7272

7373
_DartiumUpdater runtimeUpdater(Map configuration) {
74-
String runtime = configuration['runtime'];
74+
var runtime = configuration['runtime'] as String;
7575
if (runtime == 'drt' && configuration['drt'] == '') {
7676
// Download the default content shell from Google Storage.
7777
if (_contentShellUpdater == null) {

tools/testing/dart/html_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ HtmlTestInformation getInformation(String filename) {
2727
" Should end in _htmltest.html.");
2828
return null;
2929
}
30-
String contents = new File(filename).readAsStringSync();
30+
31+
var contents = new File(filename).readAsStringSync();
3132
var match = htmlAnnotation.firstMatch(contents);
3233
if (match == null) return null;
34+
3335
var annotation = JSON.decode(match[1]);
3436
if (annotation is! Map ||
3537
annotation['expectedMessages'] is! List ||
@@ -38,8 +40,11 @@ HtmlTestInformation getInformation(String filename) {
3840
" Should have {'scripts':[...], 'expectedMessages':[...]}");
3941
return null;
4042
}
41-
return new HtmlTestInformation(new Path(filename),
42-
annotation['expectedMessages'], annotation['scripts']);
43+
44+
return new HtmlTestInformation(
45+
new Path(filename),
46+
new List<String>.from(annotation['expectedMessages'] as List),
47+
new List<String>.from(annotation['scripts'] as List));
4348
}
4449

4550
String getContents(HtmlTestInformation info, bool compileToJS) {

tools/testing/dart/http_server.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ void main(List<String> arguments) {
8888
help: 'The runtime we are using (for csp flags).', defaultsTo: 'none');
8989

9090
var args = parser.parse(arguments);
91-
if (args['help']) {
91+
if (args['help'] as bool) {
9292
print(parser.getUsage());
9393
} else {
94-
var servers = new TestingServers(args['build-directory'], args['csp'],
95-
args['runtime'], null, args['package-root'], args['packages']);
96-
var port = int.parse(args['port']);
97-
var crossOriginPort = int.parse(args['crossOriginPort']);
94+
var servers = new TestingServers(
95+
args['build-directory'] as String,
96+
args['csp'] as bool,
97+
args['runtime'] as String,
98+
null,
99+
args['package-root'] as String,
100+
args['packages'] as String);
101+
var port = int.parse(args['port'] as String);
102+
var crossOriginPort = int.parse(args['crossOriginPort'] as String);
98103
servers
99-
.startServers(args['network'],
104+
.startServers(args['network'] as String,
100105
port: port, crossOriginPort: crossOriginPort)
101106
.then((_) {
102107
DebugLogger.info('Server listening on port ${servers.port}');
@@ -212,7 +217,8 @@ class TestingServers {
212217
DebugLogger.error('HttpServer: an error occured', e);
213218
}
214219

215-
Future _startHttpServer(String host, {int port: 0, int allowedPort: -1}) {
220+
Future<DispatchingServer> _startHttpServer(String host,
221+
{int port: 0, int allowedPort: -1}) {
216222
return HttpServer.bind(host, port).then((HttpServer httpServer) {
217223
var server = new DispatchingServer(httpServer, _onError, _sendNotFound);
218224
server.addHandler('/echo', _handleEchoRequest);

0 commit comments

Comments
 (0)