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

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: Address review comments. 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()) {
33 result.add(args);
34 } else {
35 for (var vmOptions in vmOptionsList) {
36 vmOptions.addAll(args);
37 result.add(vmOptions);
38 }
39 }
40
41 return result;
42 }
43
44 /**
45 * Extract test options from the test file itself.
46 */
47 static Map optionsFromFile(String filename, Map configuration) {
48 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
49 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
50
51 // Read the entire file into a byte buffer and transform it to a
52 // String. This will treat the file as ascii but the only parts
53 // we are interested in will be ascii in any case.
54 File file = new File(filename);
55 file.openSync();
56 List chars = new List(file.lengthSync());
57 var offset = 0;
58 while (offset != chars.length) {
59 offset += file.readListSync(chars, offset, chars.length - offset);
60 }
61 file.closeSync();
62 String contents = new String.fromCharCodes(chars);
63 chars = null;
64
65 // Find the options in the file.
66 List<List> result = new List<List>();
67 List<String> dartOptions;
68 bool isNegative = false;
69
70 Iterable<Match> matches = testOptionsRegExp.allMatches(contents);
71 for (var match in matches) {
72 result.add(match[1].split(' ').filter((e) => e != ''));
73 }
74
75 matches = dartOptionsRegExp.allMatches(contents);
76 for (var match in matches) {
77 if (dartOptions != null) {
78 throw new Exception(
79 'More than one "// DartOptions=" line in test $filename');
80 }
81 dartOptions = match[1].split(' ').filter((e) => e != '');
82 }
83
84 if (contents.contains("@compile-error") ||
85 contents.contains("@runtime-error")) {
86 isNegative = true;
87 } else if (contents.contains("@dynamic-type-error") &&
88 configuration['checked']) {
89 isNegative = true;
90 }
91
92 return { "vmOptions": result,
93 "dartOptions": dartOptions,
94 "isNegative" : isNegative };
95 }
96 }
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