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

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

Issue 9649015: Change string used to annotate static type issues to 'static type warning' in multitest (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merged up to tip 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
11 // " [some dart code] /// [key]: [error type]" 11 // " [some dart code] /// [key]: [error type]"
12 // 12 //
13 // For each key in the file, a new test file is made containing all 13 // For each key in the file, a new test file is made containing all
14 // the normal lines of the file, and all of the multitest lines containing 14 // the normal lines of the file, and all of the multitest lines containing
15 // that key, in the same order as in the source file. The new test 15 // that key, in the same order as in the source file. The new test
16 // is expected to fail if there is a non-empty error type listed, of 16 // is expected to fail if there is a non-empty error type listed, of
17 // type 'compile-time error', 'runtime error', 'static type error', or 17 // type 'compile-time error', 'runtime error', 'static type warning', or
18 // 'dynamic type error'. The type error tests fail only in checked mode. 18 // 'dynamic type error'. The type error tests fail only in checked mode.
19 // There is also a test created from only the untagged lines of the file, 19 // There is also a test created from only the untagged lines of the file,
20 // with key "none", which is expected to pass. This library extracts these 20 // with key "none", which is expected to pass. This library extracts these
21 // tests, writes them into a temporary directory, and passes them to the test 21 // tests, writes them into a temporary directory, and passes them to the test
22 // runner. These tests may be referred to in the status files with the 22 // runner. These tests may be referred to in the status files with the
23 // pattern [test name]/[key]. 23 // pattern [test name]/[key].
24 // 24 //
25 // For example: file I_am_a_multitest.dart 25 // For example: file I_am_a_multitest.dart
26 // aaa 26 // aaa
27 // bbb /// 02: runtime error 27 // bbb /// 02: runtime error
28 // ccc /// 02: continued 28 // ccc /// 02: continued
29 // ddd /// 07: static type error 29 // ddd /// 07: static type warning
30 // eee 30 // eee
31 // 31 //
32 // should create three tests: 32 // should create three tests:
33 // I_am_a_multitest_none.dart 33 // I_am_a_multitest_none.dart
34 // aaa 34 // aaa
35 // eee 35 // eee
36 // 36 //
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 warning
46 // eee 46 // eee
47 // 47 //
48 // Note that it is possible to indicate more than one acceptable outcome 48 // Note that it is possible to indicate more than one acceptable outcome
49 // in the case of dynamic and static type errors 49 // in the case of dynamic and static type warnings
50 // aaa 50 // aaa
51 // ddd /// 07: static type error, dynamic type error 51 // ddd /// 07: static type warning, dynamic type error
52 // eee 52 // eee
53 53
54 void ExtractTestsFromMultitest(String filename, 54 void ExtractTestsFromMultitest(String filename,
55 Map<String, String> tests, 55 Map<String, String> tests,
56 Map<String, Set<String>> outcomes) { 56 Map<String, Set<String>> outcomes) {
57 // 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
58 // 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
59 // we are interested in will be ascii in any case. 59 // we are interested in will be ascii in any case.
60 RandomAccessFile file = (new File(filename)).openSync(); 60 RandomAccessFile file = (new File(filename)).openSync();
61 List chars = new List(file.lengthSync()); 61 List chars = new List(file.lengthSync());
62 int offset = 0; 62 int offset = 0;
63 while (offset != chars.length) { 63 while (offset != chars.length) {
64 offset += file.readListSync(chars, offset, chars.length - offset); 64 offset += file.readListSync(chars, offset, chars.length - offset);
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 error', '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('// Test created from multitest named $filename.'); 82 testTemplate.add('// Test created from multitest named $filename.');
83 // Create the set of multitests, which will have a new test added each 83 // Create the set of multitests, which will have a new test added each
84 // time we see a multitest line with a new key. 84 // time we see a multitest line with a new key.
85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); 85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>();
86 86
87 int lineCount = 0; 87 int lineCount = 0;
88 for (String line in lines) { 88 for (String line in lines) {
89 lineCount++; 89 lineCount++;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for (String key in tests.getKeys()) { 202 for (String key in tests.getKeys()) {
203 final String filename = '$directory/${baseFilename}_$key.dart'; 203 final String filename = '$directory/${baseFilename}_$key.dart';
204 final File file = new File(filename); 204 final File file = new File(filename);
205 205
206 file.createSync(); 206 file.createSync();
207 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 207 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
208 var bytes = tests[key].charCodes(); 208 var bytes = tests[key].charCodes();
209 openedFile.writeListSync(bytes, 0, bytes.length); 209 openedFile.writeListSync(bytes, 0, bytes.length);
210 openedFile.closeSync(); 210 openedFile.closeSync();
211 Set<String> outcome = outcomes[key]; 211 Set<String> outcome = outcomes[key];
212 bool enableFatalTypeErrors = outcome.contains('static type error'); 212 bool enableFatalTypeErrors = outcome.contains('static type warning');
213 bool hasRuntimeErrors = outcome.contains('runtime error'); 213 bool hasRuntimeErrors = outcome.contains('runtime error');
214 bool isNegative = hasRuntimeErrors 214 bool isNegative = hasRuntimeErrors
215 || outcome.contains('compile-time error'); 215 || outcome.contains('compile-time error');
216 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 216 bool isNegativeIfChecked = outcome.contains('dynamic type error');
217 doTest(filename, 217 doTest(filename,
218 isNegative, 218 isNegative,
219 isNegativeIfChecked, 219 isNegativeIfChecked,
220 enableFatalTypeErrors, 220 enableFatalTypeErrors,
221 hasRuntimeErrors, 221 hasRuntimeErrors,
222 outcome); 222 outcome);
(...skipping 14 matching lines...) Expand all
237 var split = testDir.split('/'); 237 var split = testDir.split('/');
238 var lastComponent = split.removeLast(); 238 var lastComponent = split.removeLast();
239 Expect.isTrue(lastComponent == 'src'); 239 Expect.isTrue(lastComponent == 'src');
240 String path = '${generatedTestDir.path}/${split.last()}'; 240 String path = '${generatedTestDir.path}/${split.last()}';
241 Directory dir = new Directory(path); 241 Directory dir = new Directory(path);
242 if (!dir.existsSync()) { 242 if (!dir.existsSync()) {
243 dir.createSync(); 243 dir.createSync();
244 } 244 }
245 return path; 245 return path;
246 } 246 }
OLDNEW
« no previous file with comments | « tests/language/src/WrongNumberTypeArgumentsTest.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698