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

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

Issue 8715006: tools/test.dart: Add multitest support to Dart implementation of test runner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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') | tools/testing/dart/test_suite.dart » ('J')
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("multitest");
6
7 //#import("status_file_parser.dart");
Mads Ager (google) 2011/11/29 08:12:04 Code in comments. Remove?
Søren Gjesse 2011/11/29 08:35:30 Remove these.
Bill Hesse 2011/11/29 16:38:55 Done.
8 //#import("test_runner.dart");
9
10
Søren Gjesse 2011/11/29 08:35:30 A short comment here showing what is actually happ
Bill Hesse 2011/11/29 16:38:55 Done.
11 List ExtractTestsFromMultitest(String filename) {
12 // Read the entire file into a byte buffer and transform it to a
13 // String. This will treat the file as ascii but the only parts
14 // we are interested in will be ascii in any case.
15 File file = new File(filename);
16 file.openSync();
17 List chars = new List(file.lengthSync());
18 int offset = 0;
19 while (offset != chars.length) {
20 offset += file.readListSync(chars, offset, chars.length - offset);
21 }
22 file.closeSync();
23 String contents = new String.fromCharCodes(chars);
24 chars = null;
25 int first_newline = contents.indexOf('\n');
26 final String line_separator =
27 (first_newline == 0 || contents[first_newline - 1] != '\r')
28 ? '\n'
29 : '\r\n';
30 List<String> lines = contents.split(line_separator);
31 if (lines.last() == '') lines.removeLast();
Mads Ager (google) 2011/11/29 08:12:04 Do you need to do this? If you do, don't you need
Bill Hesse 2011/11/29 16:38:55 This should just get rid of a spurious empty line
32 contents = null;
33 Set<String> validMultitestOutcomes = new Set<String>.from(
34 ['compile-time error', 'runtime error',
35 'static type error', 'dynamic type error', '']);
36
37 List<String> testTemplate = new List<String>();
38 testTemplate.add('// Test created from multitest named $filename.');
39 // Create the set of multitests, which will have a new test added each
40 // time we see a multitest line with a new key.
41 Map<String, List<String>> tests = new Map<String, List<String>>();
42 Map<String, String> outcomes = new Map<String, String>();
43
44 for (String line in lines) {
45 if (line.contains('///')) {
46 var parts = line.split('///')[1].split(':');
47 var key = parts[0].trim();
48 var rest = parts[1].trim();
49 if (tests.containsKey(key)) {
50 Expect.equals('continued', rest);
51 tests[key].add(line);
52 } else {
53 (tests[key] = new List<String>.from(testTemplate)).add(line);
54 outcomes[key] = rest;
55 Expect.isTrue(validMultitestOutcomes.contains(rest));
56 }
57 } else {
58 testTemplate.add(line);
59 for (var test in tests.getValues()) test.add(line);
60 }
61 }
62 tests[''] = testTemplate;
Mads Ager (google) 2011/11/29 08:12:04 What is this used for. Can you add a comment about
Bill Hesse 2011/11/29 16:38:55 The key is now "none". There is always a "none" m
63 outcomes[''] = '';
64
65 for (String key in tests.getKeys()) {
66 tests[key] = [Strings.join(tests[key], line_separator) + line_separator,
67 outcomes[key]];
68
69 print('');
Mads Ager (google) 2011/11/29 08:12:04 Remove printing.
Søren Gjesse 2011/11/29 08:35:30 Remove print.
Bill Hesse 2011/11/29 16:38:55 Done.
70 print('Test $key, outcomes ${outcomes[key]}');
71 for (var line in tests[key]) {
72 print(line);
73 }
74 }
75 return tests;
76 }
77
78 void DoMultitest(String filename,
79 Function doTest(List<String> args, bool isNegative)) {
80 // Convert multitest into a map: key -> [String test, String outcome]
81 Map tests = ExtractTestsFromMultitest(filename);
Mads Ager (google) 2011/11/29 08:12:04 You could pass in the maps to be filled out here a
Bill Hesse 2011/11/29 16:38:55 Done.
82
83 String pathSeparator = new Platform().pathSeparator();
84 int start = filename.lastIndexOf(pathSeparator) + 1;
85 int end = filename.indexOf('.dart', start);
86 String baseFilename = filename.substring(start, end);
87 Directory dir = new Directory("");
88 AddErrorHandler(dir, "Error creating temp directory");
Mads Ager (google) 2011/11/29 08:12:04 I would just add the error handler. Abstracting th
89
90 Async((){dir.createTemp();}).thenHandler((){
Mads Ager (google) 2011/11/29 08:12:04 Urgh. I don't like this at all. I find it very har
Søren Gjesse 2011/11/29 08:35:30 See comment below.
91 dir.createTempHandler = (){
92 String path = dir.path + new Platform().pathSeparator();
93 for (String key in tests.getKeys()) {
94 WriteMultitestToFileAndQueueIt(tests[key], '$path$baseFilename$key.dart',
95 doTest);
96 //RegisterFileForDeletion('$path$baseFilename$key.dart');
Mads Ager (google) 2011/11/29 08:12:04 Code in comments. And below as well.
Søren Gjesse 2011/11/29 08:35:30 Code in comments.
97 }
98 //RegisterDirForDeletion(dir.path);
Søren Gjesse 2011/11/29 08:35:30 Ditto.
99 };});
100 }
101
102 WriteMultitestToFileAndQueueIt(List test, String filename, doTest) {
103 FileThen file = new FileThen(new File(filename));
Mads Ager (google) 2011/11/29 08:12:04 Why are you inventing new stuff? We have everythin
104 AddErrorHandler(file, "Error creating temp file");
Mads Ager (google) 2011/11/29 08:12:04 Just add the error handler?
105 file.createThen((){
Mads Ager (google) 2011/11/29 08:12:04 Please use our APIs for this. Don't create extra l
Søren Gjesse 2011/11/29 08:35:30 I think it would me much more readable to have a n
106 file.openThen(file.WRITABLE, (){
Mads Ager (google) 2011/11/29 08:12:04 file.openHandler = () { ... }; file.open(writable:
107 var bytes = test[0].charCodes();
108 var outcome = test[1];
109 file.writeListThen(bytes, 0, bytes.length, (){
110 file.closeThen((){
111 bool isNegative = outcome.contains('compile-time error') ||
112 outcome.contains('runtime error');
113 bool isNegativeIfChecked = outcome.contains('type error');
114
115 doTest(filename, isNegative, isNegativeIfChecked);
116 });
117 });
118 });
119 });
120 }
121
122
123 void AddErrorHandler(object, String error_string) {
Mads Ager (google) 2011/11/29 08:12:04 Please get rid of all of this stuff. There is no n
124 object.errorHandler = (error) { Expect.fail(error_string + ": $error"); };
125 }
126
127 class DelayedFunction {
128 Function later;
129 DelayedFunction(this.later);
130
131 void after(Function f) {
132 f();
133 later();
134 }
135
136 void thenHandler(Function f) => after(f);
137 }
138
139 DelayedFunction Async(Function delayed) => new DelayedFunction(delayed);
140
141
142 class FileThen {
143 File file;
144 FileThen(this.file);
145 final bool WRITABLE = true;
146
147 void existsThen(void handler(bool exists)) {
148 file.existsHandler = handler;
149 file.exists();
150 }
151 void createThen(void handler()) {
152 file.createHandler = handler;
153 file.create();
154 }
155 void deleteThen(void handler()) {
156 file.deleteHandler = handler;
157 file.delete();
158 }
159 void openThen(bool writeable, void handler()) {
160 file.openHandler = handler;
161 file.open(writeable);
162 }
163 void closeThen(void handler()) {
164 file.closeHandler = handler;
165 file.close();
166 }
167
168 void writeListThen(List<int> buffer, int offset, int bytes, void handler()) {
169 file.noPendingWriteHandler = handler;
170 file.writeList(buffer, offset, bytes);
171 }
172
173 String get name() => file.name;
174
175 void set errorHandler(void handler(String error)) {
176 file.errorHandler = handler;
177 }
178 }
179
180 // Alternatively, we could write
Søren Gjesse 2011/11/29 08:35:30 Code in comments.
181 // file.create().then(handler)
182 // instead of
183 // file.createThen(handler)
184 //
185 // by having a class Setter {
186 // Function setter;
187 // Setter(this.setter);
188 // void then(Function foo) { setter(foo); }
189 // }
190 // then FileThen.create() would be
191 // create() => new Setter((handler) {
192 // file.createHandler = handler;
193 // file.create();
194 // }
OLDNEW
« no previous file with comments | « no previous file | tools/testing/dart/test_suite.dart » ('j') | tools/testing/dart/test_suite.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698