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

Side by Side Diff: tools/testing/dart/test_config_utils.dart

Issue 8574052: Start extracting common test_config.dart functionality into a utility library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « tests/standalone/test_config.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 #library("test_config_utils");
6
7 /**
8 * TestUtils is a collection of utility methods used to write
9 * test_config.dart scripts for test suites.
10 */
11 class TestUtils {
12
13 /**
14 * Get a list of argument lists for the dart shell command.
15 */
16 static List<List<String>> argumentLists(String filename,
17 Map optionsFromFile,
18 Map configuration) {
19 List args = ["--ignore-unrecognized-flags"];
20 if (configuration["checked"]) {
21 args.add("--enable_type_checks");
22 }
23 if (configuration["component"] == "leg") {
24 args.add("--enable_leg");
25 }
26
27 List<String> dartOptions = optionsFromFile["dartOptions"];
28 args.addAll(dartOptions == null ? [filename] : dartOptions);
29
30 var result = new List<List<String>>();
31 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
32 if (vmOptionsList.isEmpty()) return [args];
33 for (var vmOptions in vmOptionsList) {
Bill Hesse 2011/11/17 09:35:24 I like better if (vmOptionsList.isEmpty() { res
Mads Ager (google) 2011/11/17 09:38:07 Done. I actually like the early return better but
34 vmOptions.addAll(args);
35 result.add(vmOptions);
36 }
37
38 return result;
39 }
40
41 /**
42 * Extract test options from the test file itself.
43 */
44 static Map optionsFromFile(String filename, Map configuration) {
45 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
46 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
47
48 // Read the entire file into a byte buffer and transform it to a
49 // String. This will treat the file as ascii but the only parts
50 // we are interested in will be ascii in any case.
51 File file = new File(filename);
52 file.openSync();
53 List chars = new List(file.lengthSync());
54 var offset = 0;
55 while (offset != chars.length) {
56 offset += file.readListSync(chars, offset, chars.length - offset);
57 }
58 file.closeSync();
59 String contents = new String.fromCharCodes(chars);
60 chars = null;
61
62 // Find the options in the file.
63 List<List> result = new List<List>();
64 List<String> dartOptions;
65 bool isNegative = false;
66
67 Iterable<Match> matches = testOptionsRegExp.allMatches(contents);
68 for (var match in matches) {
69 result.add(match[1].split(' ').filter((e) => e != ''));
70 }
71
72 matches = dartOptionsRegExp.allMatches(contents);
73 for (var match in matches) {
74 if (dartOptions != null) {
75 throw new Exception(
76 'More than one "// DartOptions=" line in test $filename');
77 }
78 dartOptions = match[1].split(' ').filter((e) => e != '');
79 }
80
81 if (contents.contains("@compile-error") ||
82 contents.contains("@runtime-error")) {
83 isNegative = true;
84 } else if (contents.contains("@dynamic-type-error") &&
85 configuration['checked']) {
86 isNegative = true;
87 }
88
89 return { "vmOptions": result,
90 "dartOptions": dartOptions,
91 "isNegative" : isNegative };
92 }
93 }
OLDNEW
« no previous file with comments | « tests/standalone/test_config.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698