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

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

Issue 9621015: Multitest annotations now accept multiple annotations on one line. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("multitest"); 5 #library("multitest");
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 #import("test_suite.dart"); 8 #import("test_suite.dart");
9 9
10 // Multitests are Dart test scripts containing lines of the form 10 // Multitests are Dart test scripts containing lines of the form
(...skipping 26 matching lines...) Expand all
37 // I_am_a_multitest_02.dart 37 // I_am_a_multitest_02.dart
38 // aaa 38 // aaa
39 // bbb /// 02: runtime error 39 // bbb /// 02: runtime error
40 // ccc /// 02: continued 40 // ccc /// 02: continued
41 // eee 41 // eee
42 // 42 //
43 // and I_am_a_multitest_07.dart 43 // and I_am_a_multitest_07.dart
44 // aaa 44 // aaa
45 // ddd /// 07: static type error 45 // ddd /// 07: static type error
46 // eee 46 // eee
47 //
48 // Note that it is possible to indicate more than one acceptable outcome
49 // in the case of dynamic and static type errors
50 // aaa
51 // ddd /// 07: static type error, dynamic type error
52 // eee
47 53
48 void ExtractTestsFromMultitest(String filename, 54 void ExtractTestsFromMultitest(String filename,
49 Map<String, String> tests, 55 Map<String, String> tests,
50 Map<String, String> outcomes) { 56 Map<String, Set<String>> outcomes) {
51 // Read the entire file into a byte buffer and transform it to a 57 // 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 58 // String. This will treat the file as ascii but the only parts
53 // we are interested in will be ascii in any case. 59 // we are interested in will be ascii in any case.
54 RandomAccessFile file = (new File(filename)).openSync(); 60 RandomAccessFile file = (new File(filename)).openSync();
55 List chars = new List(file.lengthSync()); 61 List chars = new List(file.lengthSync());
56 int offset = 0; 62 int offset = 0;
57 while (offset != chars.length) { 63 while (offset != chars.length) {
58 offset += file.readListSync(chars, offset, chars.length - offset); 64 offset += file.readListSync(chars, offset, chars.length - offset);
59 } 65 }
60 file.closeSync(); 66 file.closeSync();
(...skipping 21 matching lines...) Expand all
82 for (String line in lines) { 88 for (String line in lines) {
83 lineCount++; 89 lineCount++;
84 if (line.contains('///')) { 90 if (line.contains('///')) {
85 var parts = line.split('///')[1].split(':'); 91 var parts = line.split('///')[1].split(':');
86 var key = parts[0].trim(); 92 var key = parts[0].trim();
87 var rest = parts[1].trim(); 93 var rest = parts[1].trim();
88 if (testsAsLines.containsKey(key)) { 94 if (testsAsLines.containsKey(key)) {
89 Expect.equals('continued', rest); 95 Expect.equals('continued', rest);
90 testsAsLines[key].add(line); 96 testsAsLines[key].add(line);
91 } else { 97 } else {
98 // TODO(zundel): parse a list here
92 (testsAsLines[key] = new List<String>.from(testTemplate)).add(line); 99 (testsAsLines[key] = new List<String>.from(testTemplate)).add(line);
93 outcomes[key] = rest; 100 List<String> outcomesList = rest.split(',');
94 if (!validMultitestOutcomes.contains(rest)) { 101 for (String nextOutcome in outcomesList) {
95 Expect.fail("Invalid test directive on line ${lineCount}: $rest "); 102 nextOutcome = nextOutcome.trim();
103 if (outcomes[key] == null) {
104 outcomes[key] = new Set<String>();
105 }
106 outcomes[key].add(nextOutcome.trim());
Bill Hesse 2012/03/08 10:21:49 This can be replaced by: outcomes.putIfAbsent(key,
zundel 2012/03/08 13:18:00 nice
107 if (!validMultitestOutcomes.contains(nextOutcome)) {
108 Expect.fail(
109 "Invalid test directive '$nextOutcome' on line ${lineCount}: $rest ");
110 }
96 } 111 }
97 } 112 }
98 } else { 113 } else {
99 testTemplate.add(line); 114 testTemplate.add(line);
100 for (var test in testsAsLines.getValues()) test.add(line); 115 for (var test in testsAsLines.getValues()) test.add(line);
101 } 116 }
102 } 117 }
103 // Add the template, with no multitest lines, as a test with key 'none'. 118 // Add the template, with no multitest lines, as a test with key 'none'.
104 testsAsLines['none'] = testTemplate; 119 testsAsLines['none'] = testTemplate;
105 outcomes['none'] = ''; 120 outcomes['none'] = new Set<String>();
106 121
Bill Hesse 2012/03/08 10:21:49 Either the no-error case is an empty set, or it is
zundel 2012/03/08 13:18:00 I'm going with the empty set.
107 // Copy all the tests into the output map tests, as multiline strings. 122 // Copy all the tests into the output map tests, as multiline strings.
108 for (String key in testsAsLines.getKeys()) { 123 for (String key in testsAsLines.getKeys()) {
109 tests[key] = 124 tests[key] =
110 Strings.join(testsAsLines[key], line_separator) + line_separator; 125 Strings.join(testsAsLines[key], line_separator) + line_separator;
111 } 126 }
112 } 127 }
113 128
114 // Find all relative imports and copy them into the dir that contains 129 // Find all relative imports and copy them into the dir that contains
115 // the generated tests. 130 // the generated tests.
116 Set<String> _findAllRelativeImports(String topLibrary) { 131 Set<String> _findAllRelativeImports(String topLibrary) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // with the 'multitestOutcome' field? 173 // with the 'multitestOutcome' field?
159 Function doTest(String filename, 174 Function doTest(String filename,
160 bool isNegative, 175 bool isNegative,
161 [bool isNegativeIfChecked, 176 [bool isNegativeIfChecked,
162 bool hasFatalTypeErrors, 177 bool hasFatalTypeErrors,
163 bool hasRuntimeErrors, 178 bool hasRuntimeErrors,
164 String multitestOutcome]), 179 String multitestOutcome]),
165 Function multitestDone) { 180 Function multitestDone) {
166 // Each new test is a single String value in the Map tests. 181 // Each new test is a single String value in the Map tests.
167 Map<String, String> tests = new Map<String, String>(); 182 Map<String, String> tests = new Map<String, String>();
168 Map<String, String> outcomes = new Map<String, String>(); 183 Map<String, Set<String>> outcomes = new Map<String, Set<String>>();
169 ExtractTestsFromMultitest(filename, tests, outcomes); 184 ExtractTestsFromMultitest(filename, tests, outcomes);
170 185
171 String directory = CreateMultitestDirectory(outputDir, testDir); 186 String directory = CreateMultitestDirectory(outputDir, testDir);
172 Expect.isNotNull(directory); 187 Expect.isNotNull(directory);
173 String pathSep = new Platform().pathSeparator(); 188 String pathSep = new Platform().pathSeparator();
174 int start = filename.lastIndexOf(pathSep) + 1; 189 int start = filename.lastIndexOf(pathSep) + 1;
175 int end = filename.indexOf('.dart', start); 190 int end = filename.indexOf('.dart', start);
176 String baseFilename = filename.substring(start, end); 191 String baseFilename = filename.substring(start, end);
177 String sourceDirectory = filename.substring(0, start - 1); 192 String sourceDirectory = filename.substring(0, start - 1);
178 Set<String> importsToCopy = _findAllRelativeImports(filename); 193 Set<String> importsToCopy = _findAllRelativeImports(filename);
(...skipping 11 matching lines...) Expand all
190 } 205 }
191 for (String key in tests.getKeys()) { 206 for (String key in tests.getKeys()) {
192 final String filename = '$directory/${baseFilename}_$key.dart'; 207 final String filename = '$directory/${baseFilename}_$key.dart';
193 final File file = new File(filename); 208 final File file = new File(filename);
194 209
195 file.createSync(); 210 file.createSync();
196 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 211 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
197 var bytes = tests[key].charCodes(); 212 var bytes = tests[key].charCodes();
198 openedFile.writeListSync(bytes, 0, bytes.length); 213 openedFile.writeListSync(bytes, 0, bytes.length);
199 openedFile.closeSync(); 214 openedFile.closeSync();
200 var outcome = outcomes[key]; 215 Set<String> outcome = outcomes[key];
201 bool enableFatalTypeErrors = outcome.contains('static type error'); 216 bool enableFatalTypeErrors = outcome.contains('static type error');
202 bool hasRuntimeErrors = outcome.contains('runtime error'); 217 bool hasRuntimeErrors = outcome.contains('runtime error');
203 bool isNegative = hasRuntimeErrors 218 bool isNegative = hasRuntimeErrors
204 || outcome.contains('compile-time error'); 219 || outcome.contains('compile-time error');
205 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 220 bool isNegativeIfChecked = outcome.contains('dynamic type error');
206 doTest(filename, 221 doTest(filename,
207 isNegative, 222 isNegative,
208 isNegativeIfChecked, 223 isNegativeIfChecked,
209 enableFatalTypeErrors, 224 enableFatalTypeErrors,
210 hasRuntimeErrors, 225 hasRuntimeErrors,
(...skipping 15 matching lines...) Expand all
226 var split = testDir.split('/'); 241 var split = testDir.split('/');
227 var lastComponent = split.removeLast(); 242 var lastComponent = split.removeLast();
228 Expect.isTrue(lastComponent == 'src'); 243 Expect.isTrue(lastComponent == 'src');
229 String path = '${generatedTestDir.path}/${split.last()}'; 244 String path = '${generatedTestDir.path}/${split.last()}';
230 Directory dir = new Directory(path); 245 Directory dir = new Directory(path);
231 if (!dir.existsSync()) { 246 if (!dir.existsSync()) {
232 dir.createSync(); 247 dir.createSync();
233 } 248 }
234 return path; 249 return path;
235 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698