Skip to content

Commit 8984694

Browse files
committed
Print out experimental test.py reproduction command
[email protected] Review URL: https://codereview.chromium.org//17361003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24231 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 54e2031 commit 8984694

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

tools/testing/dart/test_options.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,56 @@ Note: currently only implemented for dart2js.''',
462462

463463
List<Map> expandedConfigs = _expandConfigurations(configuration);
464464
List<Map> result = expandedConfigs.where(_isValidConfig).toList();
465+
for (var config in result) {
466+
config['_reproducing_arguments_'] =
467+
_constructReproducingCommandArguments(config);
468+
}
465469
return result.isEmpty ? null : result;
466470
}
467471

472+
// For printing out reproducing command lines, we don't want to add these
473+
// options.
474+
Set<String> _blacklistedOptions = new Set<String>.from([
475+
'progress', 'failure-summary', 'step_name', 'report', 'tasks', 'verbose',
476+
'time', 'dart', 'drt', 'dartium', 'build_directory', 'append_logs',
477+
'write_debug_log', 'local_ip', 'shard', 'shards',
478+
]);
479+
480+
List<String> _constructReproducingCommandArguments(Map config) {
481+
var arguments = new List<String>();
482+
for (var configKey in config.keys) {
483+
if (!_blacklistedOptions.contains(configKey)) {
484+
for (var option in _options) {
485+
var configValue = config[configKey];
486+
// We only include entries of [conf] if we find an option for it.
487+
if (configKey == option.name && configValue != option.defaultValue) {
488+
var isBooleanOption = option.type == 'bool';
489+
// Sort by length, so we get the shortest variant.
490+
var possibleOptions = new List.from(option.keys);
491+
possibleOptions.sort((a, b) => (a.length < b.length ? -1 : 1));
492+
var key = possibleOptions[0];
493+
if (key.startsWith('--')) {
494+
// long version
495+
arguments.add(key);
496+
if (!isBooleanOption) {
497+
arguments.add("$configValue");
498+
}
499+
} else {
500+
// short version
501+
assert(key.startsWith('-'));
502+
if (!isBooleanOption) {
503+
arguments.add("$key$configValue");
504+
} else {
505+
arguments.add(key);
506+
}
507+
}
508+
}
509+
}
510+
}
511+
}
512+
return arguments;
513+
}
514+
468515
/**
469516
* Determine if a particular configuration has a valid combination of compiler
470517
* and runtime elements.

tools/testing/dart/test_progress.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ List<String> _buildFailureOutput(TestCase test,
137137
output.add('Did not run');
138138
}
139139
}
140+
141+
var arguments = ['python', 'tools/test.py'];
142+
arguments.addAll(test.configuration['_reproducing_arguments_']);
143+
arguments.add(test.displayName);
144+
var testPyCommandline = arguments.map(escapeCommandLineArgument).join(' ');
145+
146+
output.add('');
147+
output.add('Short reproduction command (experimental):');
148+
output.add(" $testPyCommandline");
140149
return output;
141150
}
142151

tools/testing/dart/test_runner.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ class Command {
116116
executable = executable.replaceAll('/', '\\');
117117
}
118118
var quotedArguments = [];
119-
arguments.forEach((argument) => quotedArguments.add('"$argument"'));
120-
commandLine = "\"$executable\" ${quotedArguments.join(' ')}";
119+
quotedArguments.add(escapeCommandLineArgument(executable));
120+
quotedArguments.addAll(arguments.map(escapeCommandLineArgument));
121+
commandLine = quotedArguments.join(' ');
121122
}
122123

123124
String toString() => commandLine;

tools/testing/dart/utils.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ String decodeUtf8(List<int> bytes) {
7575
return utf.decodeUtf8(bytes);
7676
}
7777

78+
// This function is pretty stupid and only puts quotes around an argument if
79+
// it the argument contains a space.
80+
String escapeCommandLineArgument(String argument) {
81+
if (argument.contains(' ')) {
82+
return '"$argument"';
83+
}
84+
return argument;
85+
}
86+

0 commit comments

Comments
 (0)