Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: utils/testrunner/options.dart

Issue 10897016: Testrunner for 3rd parties. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Create and return an options parser for the test runner.
6 ArgParser getOptionParser() {
7 var parser = new ArgParser();
8
9 parser.addOption('help', abbr: '?',
10 help: 'Show usage information.');
11
12 parser.addOption('runtime', abbr: 'r', defaultsTo: 'vm',
13 help: 'Where the tests should be run.',
14 allowed: ['vm', 'drt-dart', 'drt-js', 'd8'],
15 allowedHelp: {
16 'vm': 'Run Dart code natively on the standalone dart vm.',
17 'drt-dart': 'Run Dart code natively in the headless version of\n'
18 'Chrome, DumpRenderTree.',
19 'drt-js': 'Run Dart compiled to JavaScript in the headless version\n'
20 'of Chrome, DumpRenderTree.',
21 'd8': 'Run Dart compiled to JavaScript from the command line using v8.'
22 });
23
24 parser.addFlag('checked', defaultsTo: false,
25 help: 'Run tests in checked mode.');
26
27 parser.addOption('timeout', abbr: 't',
28 help: 'Timeout in seconds', defaultsTo: '60');
29
30 parser.addOption('tasks', abbr: 'j',
31 defaultsTo: Platform.numberOfProcessors.toString(),
32 help: 'The number of parallel tasks to run.');
33
34 parser.addOption('out', abbr: 'o', defaultsTo: 'stdout',
35 help: 'File to send test results. This should be a '
36 'file name or one of stdout, stderr, or none.');
37
38 parser.addOption('format', abbr: 'f',
39 defaultsTo: '${Meta.testResult}${Meta.testTime}'
40 '${Meta.testfile}${Meta.testGroup}'
41 '${Meta.testDescription}${Meta.testMessage}',
42 help: 'Format for test result output.');
43
44 parser.addFlag('summary', defaultsTo: false,
45 help: 'Print a summary of tests passed/failed for each test file.');
46
47 parser.addOption('log', abbr: 'l', defaultsTo: 'none',
48 help: 'File to send test log/print output to. This should be a '
49 'file name or one of stdout, stderr, or none.');
50
51 // TODO(gram) - add loglevel once we have switched unittest to use the log
52 // library.
53
54 parser.addFlag('list-files', defaultsTo: false,
55 help: 'List test files only, do not run them.');
56
57 parser.addFlag('list-tests', defaultsTo: false,
58 help: 'List tests only, do not run them.');
59
60 parser.addFlag('list-groups', defaultsTo: false,
61 help: 'List test groups only, do not run tests.');
62
63 parser.addFlag('keep-generated-tests', defaultsTo: false,
64 help: 'Keep the generated files in the temporary directory.');
65
66 parser.addFlag('list-options', defaultsTo: false,
67 help: 'Print non-default option settings, usable as a test.config.');
68
69 parser.addFlag('list-all-options', defaultsTo: false,
70 help: 'Print all option settings, usable as a test.config.');
71
72 parser.addFlag('time',
73 help: 'Print timing information after running tests',
74 defaultsTo: false);
75
76 parser.addFlag('stop-on-failure', defaultsTo: false,
77 help: 'Stop execution upon first failure.');
78
79 parser.addFlag('isolate', defaultsTo: false,
80 help: 'Runs each test in a separate isolate.');
81
82 parser.addOption('configfile', help: 'Path to an argument file to load.');
83
84 // The defaults here should be the name of the executable, with
85 // the assumption that it is available on the PATH.
86 parser.addOption('dart2js', help: 'Path to dart2js executable.',
87 defaultsTo: 'dart2js');
88 parser.addOption('dart', help: 'Path to dart executable.',
89 defaultsTo: 'dart');
90 parser.addOption('drt', help: 'Path to DumpRenderTree executable.',
91 defaultsTo: 'drt');
92 parser.addOption('d8', help: 'Path to d8 executable.',
93 defaultsTo: 'd8');
94
95 parser.addOption('tempdir', help: 'Directory to store temp files.',
96 defaultsTo: '${Platform.pathSeparator}tmp'
97 '${Platform.pathSeparator}testrunner');
98
99 parser.addOption('test-file-pat',
100 help: 'A regular expression that test file names must match '
101 'to be considered', defaultsTo: '_test.dart\$');
102
103 parser.addOption('include',
104 help: 'Only run tests from the specified group(s).',
105 allowMultiple: true);
106
107 parser.addOption('exclude',
108 help: 'Exclude tests from the specified group(s).',
109 allowMultiple: true);
110
111 parser.addFlag('recurse', abbr: 'R',
112 help: 'Recurse through child directories looking for tests.',
113 defaultsTo: false);
114
115 parser.addOption('unittest', help: '#import path for unit test library.');
116
117 parser.addOption('pass-text',
118 help: 'Text to use in messages for passing tests.',
119 defaultsTo: 'PASS');
120
121 parser.addOption('fail-text',
122 help: 'Text to use in messages for failing tests.',
123 defaultsTo: 'FAIL');
124
125 parser.addOption('error-text',
126 help: 'Text to use in messages for tests with errors.',
127 defaultsTo: 'ERROR');
128 return parser;
129 }
130
131 // Print a value option, quoting it if it has embedded spaces.
132 _printValueOption(String name, value, OutputStream stream) {
133 if (value.indexOf(' ') >= 0) {
134 stream.writeString("--$name='$value'\n");
135 } else {
136 stream.writeString("--$name=$value\n");
137 }
138 }
139
140 // Print the current option values.
141 printOptions(ArgParser parser, ArgResults arguments,
142 bool includeDefaults, OutputStream stream) {
143 if (stream == null) return;
144 for (var name in arguments.options) {
145 if (!name.startsWith('list-')) {
146 var value = arguments[name];
147 var defaultValue = parser.getDefault(name);
148 if (value is bool) {
149 if (includeDefaults || (value != defaultValue)) {
150 stream.writeString('--${value ? "" : "no-"}$name\n');
151 }
152 } else if (value is List) {
153 if (value.length > 0) {
154 for (var v in value) {
155 _printValueOption(name, v, stream);
156 }
157 }
158 } else if (value != null && (includeDefaults || value != defaultValue)) {
159 _printValueOption(name, value, stream);
160 }
161 }
162 }
163 }
164
165 // Get the test runner configuration. This loads options from multiple
166 // sources, in increasing order of priority: a test.config file in the
167 // current directory, a test config file specified with --configfile on
168 // the command line, and other arguments specified on the command line.
169 ArgResults loadConfiguration(optionsParser) {
170 var options = new List();
171 // We first load options from a test.config file in the working directory.
172 options.addAll(getFileContents('test.config', false).
173 filter((e) => e.trim().length > 0 && e[0] != '#'));
174 // Next we look to see if the command line included a -testconfig argument,
175 // and if so, load options from that file too; where these are not
176 // multi-valued they will take precedence over the ones in test.config.
177 var commandLineArgs = new Options().arguments;
178 var cfgarg = '--configfile';
179 for (var i = 0; i < commandLineArgs.length; i++) {
180 if (commandLineArgs[i].startsWith(cfgarg)) {
181 if (commandLineArgs[i] == cfgarg) {
182 if (i == commandLineArgs.length - 1) {
183 throw new Exception('Missing argument to $cfgarg');
184 }
185 options.addAll(getFileContents(commandLineArgs[++i], true).
186 filter((e) => e.trim().length > 0 && e[0] != '#'));
187 } else if (commandLineArgs[i].startsWith('$cfgarg=')) {
188 options.addAll(
189 getFileContents(commandLineArgs[i].substring(cfgarg.length), true).
190 filter((e) => e.trim().length > 0 && e[0] != '#'));
191 } else {
192 throw new Exception('Missing argument to $cfgarg');
193 }
194 }
195 }
196 // Finally, we add options from the command line. These have the highest
197 // precedence of all.
198 options.addAll(commandLineArgs);
199 // Now try parse the whole collection of options, and if this fails,
200 // issue a usage message.
201 try {
202 return optionsParser.parse(options);
203 } catch (var e) {
204 print(e);
205 print('Usage: testrunner <options> [<directory or file> ...]');
206 print(optionsParser.getUsage());
207 return null;
208 }
209 }
210
211 // Perform some sanity checking of the configuration.
212 bool sane(ArgResults config) {
213 if (config == null) {
214 return false;
215 }
216 if (config['runtime'] == null) {
217 print('Missing required option --runtime');
218 return false;
219 }
220 if (config['unittest'] == null) {
221 print('Missing required option --unittest');
222 return false;
223 }
224 if (config['include'].length > 0 &&
225 config['exclude'].length > 0) {
226 print('--include and --exclude are mutually exclusive.');
227 return false;
228 }
229 return true;
230 }
231
232
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698