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

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

Issue 11343008: Land update to tools directory with new binaries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « tools/testing/dart/co19_test.dart ('k') | tools/testing/dart/status_expression.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 file.closeSync(); 66 file.closeSync();
67 String contents = new String.fromCharCodes(chars); 67 String contents = new String.fromCharCodes(chars);
68 chars = null; 68 chars = null;
69 int first_newline = contents.indexOf('\n'); 69 int first_newline = contents.indexOf('\n');
70 final String line_separator = 70 final String line_separator =
71 (first_newline == 0 || contents[first_newline - 1] != '\r') 71 (first_newline == 0 || contents[first_newline - 1] != '\r')
72 ? '\n' 72 ? '\n'
73 : '\r\n'; 73 : '\r\n';
74 List<String> lines = contents.split(line_separator); 74 List<String> lines = contents.split(line_separator);
75 if (lines.last() == '') lines.removeLast(); 75 if (lines.last == '') lines.removeLast();
76 contents = null; 76 contents = null;
77 Set<String> validMultitestOutcomes = new Set<String>.from( 77 Set<String> validMultitestOutcomes = new Set<String>.from(
78 ['compile-time error', 'runtime error', 78 ['compile-time error', 'runtime error',
79 'static type warning', 'dynamic type error']); 79 'static type warning', 'dynamic type error']);
80 80
81 List<String> testTemplate = new List<String>(); 81 List<String> testTemplate = new List<String>();
82 testTemplate.add( 82 testTemplate.add(
83 '// Test created from multitest named ${filePath.toNativePath()}.'); 83 '// Test created from multitest named ${filePath.toNativePath()}.');
84 // Create the set of multitests, which will have a new test added each 84 // Create the set of multitests, which will have a new test added each
85 // time we see a multitest line with a new key. 85 // time we see a multitest line with a new key.
(...skipping 15 matching lines...) Expand all
101 outcomes[annotation.key].add(nextOutcome); 101 outcomes[annotation.key].add(nextOutcome);
102 if (!validMultitestOutcomes.contains(nextOutcome)) { 102 if (!validMultitestOutcomes.contains(nextOutcome)) {
103 Expect.fail( 103 Expect.fail(
104 "Invalid test directive '$nextOutcome' on line ${lineCount}:\n" 104 "Invalid test directive '$nextOutcome' on line ${lineCount}:\n"
105 "${annotation.rest} "); 105 "${annotation.rest} ");
106 } 106 }
107 } 107 }
108 } 108 }
109 } else { 109 } else {
110 testTemplate.add(line); 110 testTemplate.add(line);
111 for (var test in testsAsLines.getValues()) test.add(line); 111 for (var test in testsAsLines.values) test.add(line);
112 } 112 }
113 } 113 }
114 114
115 // Check that every key (other than the none case) has at least one outcome 115 // Check that every key (other than the none case) has at least one outcome
116 for (var outcomeKey in outcomes.getKeys()) { 116 for (var outcomeKey in outcomes.keys) {
117 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty()) { 117 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) {
118 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes.\n" 118 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes.\n"
119 "Expected one of: ${validMultitestOutcomes.toString()}"); 119 "Expected one of: ${validMultitestOutcomes.toString()}");
120 } 120 }
121 } 121 }
122 122
123 // Add the template, with no multitest lines, as a test with key 'none'. 123 // Add the template, with no multitest lines, as a test with key 'none'.
124 testsAsLines['none'] = testTemplate; 124 testsAsLines['none'] = testTemplate;
125 outcomes['none'] = new Set<String>(); 125 outcomes['none'] = new Set<String>();
126 126
127 // Copy all the tests into the output map tests, as multiline strings. 127 // Copy all the tests into the output map tests, as multiline strings.
128 for (String key in testsAsLines.getKeys()) { 128 for (String key in testsAsLines.keys) {
129 tests[key] = 129 tests[key] =
130 Strings.join(testsAsLines[key], line_separator).concat(line_separator); 130 Strings.join(testsAsLines[key], line_separator).concat(line_separator);
131 } 131 }
132 } 132 }
133 133
134 // Represents a mutlitest annotation in the special /// comment. 134 // Represents a mutlitest annotation in the special /// comment.
135 class _Annotation { 135 class _Annotation {
136 String key; 136 String key;
137 String rest; 137 String rest;
138 List<String> outcomesList; 138 List<String> outcomesList;
(...skipping 15 matching lines...) Expand all
154 // Find all relative imports and copy them into the dir that contains 154 // Find all relative imports and copy them into the dir that contains
155 // the generated tests. 155 // the generated tests.
156 Set<Path> _findAllRelativeImports(Path topLibrary) { 156 Set<Path> _findAllRelativeImports(Path topLibrary) {
157 Set<Path> toSearch = new Set<Path>.from([topLibrary]); 157 Set<Path> toSearch = new Set<Path>.from([topLibrary]);
158 Set<Path> foundImports = new HashSet<Path>(); 158 Set<Path> foundImports = new HashSet<Path>();
159 Path libraryDir = topLibrary.directoryPath; 159 Path libraryDir = topLibrary.directoryPath;
160 // Matches #import( or #source( followed by " or ' followed by anything 160 // Matches #import( or #source( followed by " or ' followed by anything
161 // except dart:, dart-ext: or /, at the beginning of a line. 161 // except dart:, dart-ext: or /, at the beginning of a line.
162 RegExp relativeImportRegExp = const RegExp( 162 RegExp relativeImportRegExp = const RegExp(
163 '^#(import|source)[(]["\'](?!(dart:|dart-ext:|/))([^"\']*)["\']'); 163 '^#(import|source)[(]["\'](?!(dart:|dart-ext:|/))([^"\']*)["\']');
164 while (!toSearch.isEmpty()) { 164 while (!toSearch.isEmpty) {
165 var thisPass = toSearch; 165 var thisPass = toSearch;
166 toSearch = new HashSet<Path>(); 166 toSearch = new HashSet<Path>();
167 for (Path filename in thisPass) { 167 for (Path filename in thisPass) {
168 File f = new File.fromPath(filename); 168 File f = new File.fromPath(filename);
169 for (String line in f.readAsLinesSync()) { 169 for (String line in f.readAsLinesSync()) {
170 Match match = relativeImportRegExp.firstMatch(line); 170 Match match = relativeImportRegExp.firstMatch(line);
171 if (match != null) { 171 if (match != null) {
172 Path relativePath = new Path(match.group(3)); 172 Path relativePath = new Path(match.group(3));
173 if (foundImports.contains(relativePath)) { 173 if (foundImports.contains(relativePath)) {
174 continue; 174 continue;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 TestUtils.mkdirRecursive(targetDir, importDir); 212 TestUtils.mkdirRecursive(targetDir, importDir);
213 } 213 }
214 // Copy file. 214 // Copy file.
215 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath), 215 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath),
216 targetDir.join(importPath))); 216 targetDir.join(importPath)));
217 } 217 }
218 218
219 // Wait until all imports are copied before scheduling test cases. 219 // Wait until all imports are copied before scheduling test cases.
220 Futures.wait(futureCopies).then((ignored) { 220 Futures.wait(futureCopies).then((ignored) {
221 String baseFilename = filePath.filenameWithoutExtension; 221 String baseFilename = filePath.filenameWithoutExtension;
222 for (String key in tests.getKeys()) { 222 for (String key in tests.keys) {
223 final Path multitestFilename = 223 final Path multitestFilename =
224 targetDir.append('${baseFilename}_$key.dart'); 224 targetDir.append('${baseFilename}_$key.dart');
225 final File file = new File.fromPath(multitestFilename); 225 final File file = new File.fromPath(multitestFilename);
226 226
227 file.createSync(); 227 file.createSync();
228 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 228 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
229 var bytes = tests[key].charCodes(); 229 var bytes = tests[key].charCodes;
230 openedFile.writeListSync(bytes, 0, bytes.length); 230 openedFile.writeListSync(bytes, 0, bytes.length);
231 openedFile.closeSync(); 231 openedFile.closeSync();
232 Set<String> outcome = outcomes[key]; 232 Set<String> outcome = outcomes[key];
233 bool enableFatalTypeErrors = outcome.contains('static type warning'); 233 bool enableFatalTypeErrors = outcome.contains('static type warning');
234 bool hasRuntimeErrors = outcome.contains('runtime error'); 234 bool hasRuntimeErrors = outcome.contains('runtime error');
235 bool hasCompileError = outcome.contains('compile-time error'); 235 bool hasCompileError = outcome.contains('compile-time error');
236 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 236 bool isNegativeIfChecked = outcome.contains('dynamic type error');
237 doTest(multitestFilename, 237 doTest(multitestFilename,
238 hasCompileError, 238 hasCompileError,
239 hasRuntimeErrors, 239 hasRuntimeErrors,
240 isNegativeIfChecked: isNegativeIfChecked, 240 isNegativeIfChecked: isNegativeIfChecked,
241 hasFatalTypeErrors: enableFatalTypeErrors, 241 hasFatalTypeErrors: enableFatalTypeErrors,
242 multitestOutcome: outcome); 242 multitestOutcome: outcome);
243 } 243 }
244 multitestDone(); 244 multitestDone();
245 }); 245 });
246 } 246 }
247 247
248 248
249 Path CreateMultitestDirectory(String outputDir, Path suiteDir) { 249 Path CreateMultitestDirectory(String outputDir, Path suiteDir) {
250 final String generatedTestDirectory = 'generated_tests'; 250 final String generatedTestDirectory = 'generated_tests';
251 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); 251 Directory generatedTestDir = new Directory('$outputDir/generated_tests');
252 if (!new Directory(outputDir).existsSync()) { 252 if (!new Directory(outputDir).existsSync()) {
253 new Directory(outputDir).createSync(); 253 new Directory(outputDir).createSync();
254 } 254 }
255 if (!generatedTestDir.existsSync()) { 255 if (!generatedTestDir.existsSync()) {
256 generatedTestDir.createSync(); 256 generatedTestDir.createSync();
257 } 257 }
258 var split = suiteDir.segments(); 258 var split = suiteDir.segments();
259 if (split.last() == 'src') { 259 if (split.last == 'src') {
260 // TODO(sigmund): remove this once all tests are migrated to use 260 // TODO(sigmund): remove this once all tests are migrated to use
261 // TestSuite.forDirectory. 261 // TestSuite.forDirectory.
262 split.removeLast(); 262 split.removeLast();
263 } 263 }
264 String path = '${generatedTestDir.path}/${split.last()}'; 264 String path = '${generatedTestDir.path}/${split.last}';
265 Directory dir = new Directory(path); 265 Directory dir = new Directory(path);
266 if (!dir.existsSync()) { 266 if (!dir.existsSync()) {
267 dir.createSync(); 267 dir.createSync();
268 } 268 }
269 return new Path.fromNative(new File(path).fullPathSync()); 269 return new Path.fromNative(new File(path).fullPathSync());
270 } 270 }
OLDNEW
« no previous file with comments | « tools/testing/dart/co19_test.dart ('k') | tools/testing/dart/status_expression.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698