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

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

Issue 8773004: tools/test.dart: Add synchronization, so the process queue knows when all multitests are done. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, fix type error. Created 9 years 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 | « no previous file | tools/testing/dart/test_suite.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) 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 // Multitests are Dart test scripts containing lines of the form 7 // Multitests are Dart test scripts containing lines of the form
8 // " [some dart code] /// [key]: [error type]" 8 // " [some dart code] /// [key]: [error type]"
9 // 9 //
10 // For each key in the file, a new test file is made containing all 10 // For each key in the file, a new test file is made containing all
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 for (String key in testsAsLines.getKeys()) { 111 for (String key in testsAsLines.getKeys()) {
112 tests[key] = 112 tests[key] =
113 Strings.join(testsAsLines[key], line_separator) + line_separator; 113 Strings.join(testsAsLines[key], line_separator) + line_separator;
114 } 114 }
115 } 115 }
116 116
117 117
118 void DoMultitest(String filename, 118 void DoMultitest(String filename,
119 String buildDir, 119 String buildDir,
120 String testDir, 120 String testDir,
121 Function doTest(List<String> args, 121 Function doTest(String filename,
122 bool isNegative, 122 bool isNegative,
123 bool isNegativeIfChecked)) { 123 [bool isNegativeIfChecked]),
124 Function multitestDone) {
124 // Each new test is a single String value in the Map tests. 125 // Each new test is a single String value in the Map tests.
125 Map<String, String> tests = new Map<String, String>(); 126 Map<String, String> tests = new Map<String, String>();
126 Map<String, String> outcomes = new Map<String, String>(); 127 Map<String, String> outcomes = new Map<String, String>();
127 ExtractTestsFromMultitest(filename, tests, outcomes); 128 ExtractTestsFromMultitest(filename, tests, outcomes);
128 129
129 String directory = CreateMultitestDirectory(buildDir, testDir); 130 String directory = CreateMultitestDirectory(buildDir, testDir);
130 String pathSeparator = new Platform().pathSeparator(); 131 String pathSeparator = new Platform().pathSeparator();
131 int start = filename.lastIndexOf(pathSeparator) + 1; 132 int start = filename.lastIndexOf(pathSeparator) + 1;
132 int end = filename.indexOf('.dart', start); 133 int end = filename.indexOf('.dart', start);
133 String baseFilename = filename.substring(start, end); 134 String baseFilename = filename.substring(start, end);
134 Iterator currentKey = tests.getKeys().iterator(); 135 Iterator currentKey = tests.getKeys().iterator();
135 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, 136 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey,
136 '$directory$pathSeparator$baseFilename', doTest); 137 '$directory$pathSeparator$baseFilename',
138 doTest, multitestDone);
137 } 139 }
138 140
139 141
140 // Write multiple tests to files, using tail recursion in a callback 142 // Write multiple tests to files, using tail recursion in a callback
141 // to serialize the file operations, rather than opening all files at once. 143 // to serialize the file operations, rather than opening all files at once.
142 WriteMultitestToFileAndQueueIt(Map<String, String> tests, 144 WriteMultitestToFileAndQueueIt(Map<String, String> tests,
143 Map<String, String> outcomes, 145 Map<String, String> outcomes,
144 Iterator currentKey, 146 Iterator currentKey,
145 String basePath, 147 String basePath,
146 Function doTest) { 148 Function doTest,
147 if (!currentKey.hasNext()) return; 149 Function done) {
150 if (!currentKey.hasNext()) {
151 done();
152 return;
153 }
148 final String key = currentKey.next(); 154 final String key = currentKey.next();
149 final String filename = '${basePath}_$key.dart'; 155 final String filename = '${basePath}_$key.dart';
150 final File file = new File(filename); 156 final File file = new File(filename);
151 file.errorHandler = (error) { 157 file.errorHandler = (error) {
152 Expect.fail("Error creating temp file: $error"); 158 Expect.fail("Error creating temp file: $error");
153 }; 159 };
154 file.createHandler = () { 160 file.createHandler = () {
155 file.open(writable: true); 161 file.open(writable: true);
156 }; 162 };
157 file.openHandler = () { 163 file.openHandler = () {
158 var bytes = tests[key].charCodes(); 164 var bytes = tests[key].charCodes();
159 file.writeList(bytes, 0, bytes.length); 165 file.writeList(bytes, 0, bytes.length);
160 }; 166 };
161 file.noPendingWriteHandler =() { 167 file.noPendingWriteHandler =() {
162 file.close(); 168 file.close();
163 }; 169 };
164 file.closeHandler = () { 170 file.closeHandler = () {
165 var outcome = outcomes[key]; 171 var outcome = outcomes[key];
166 bool isNegative = outcome.contains('compile-time error') || 172 bool isNegative = outcome.contains('compile-time error') ||
167 outcome.contains('runtime error'); 173 outcome.contains('runtime error');
168 bool isNegativeIfChecked = outcome.contains('type error'); 174 bool isNegativeIfChecked = outcome.contains('type error');
169 doTest(filename, isNegative, isNegativeIfChecked); 175 doTest(filename, isNegative, isNegativeIfChecked);
170 // TODO(whesse): Register files and directories to be deleted. 176 // TODO(whesse): Register files and directories to be deleted.
171 // They should be registered in a persistent list, so they can 177 // They should be registered in a persistent list, so they can
172 // be deleted later even if the test script is interrupted. 178 // be deleted later even if the test script is interrupted.
173 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, 179 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey,
174 basePath, doTest); 180 basePath, doTest, done);
175 }; 181 };
176 file.create(); 182 file.create();
177 } 183 }
178 184
179 String CreateMultitestDirectory(String buildDir, String testDir) { 185 String CreateMultitestDirectory(String buildDir, String testDir) {
180 final String generatedTestDirectory = 'generated_tests/'; 186 final String generatedTestDirectory = 'generated_tests/';
181 Directory parent_dir = new Directory(buildDir + generatedTestDirectory); 187 Directory parent_dir = new Directory(buildDir + generatedTestDirectory);
182 if (!parent_dir.existsSync()) { 188 if (!parent_dir.existsSync()) {
183 parent_dir.createSync(); 189 parent_dir.createSync();
184 } 190 }
185 final String prefix = 'tests/'; 191 final String prefix = 'tests/';
186 final String suffix = '/src'; 192 final String suffix = '/src';
187 Expect.isTrue(testDir.startsWith(prefix)); 193 Expect.isTrue(testDir.startsWith(prefix));
188 Expect.isTrue(testDir.endsWith(suffix)); 194 Expect.isTrue(testDir.endsWith(suffix));
189 String path = parent_dir.path + 195 String path = parent_dir.path +
190 testDir.substring(prefix.length, testDir.length - suffix.length); 196 testDir.substring(prefix.length, testDir.length - suffix.length);
191 Directory dir = new Directory(path); 197 Directory dir = new Directory(path);
192 if (!dir.existsSync()) { 198 if (!dir.existsSync()) {
193 dir.createSync(); 199 dir.createSync();
194 } 200 }
195 return path; 201 return path;
196 } 202 }
OLDNEW
« no previous file with comments | « no previous file | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698