OLD | NEW |
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:async"; | 7 import "dart:async"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 import "test_suite.dart"; | 9 import "test_suite.dart"; |
| 10 import "utils.dart"; |
10 | 11 |
11 // Multitests are Dart test scripts containing lines of the form | 12 // Multitests are Dart test scripts containing lines of the form |
12 // " [some dart code] /// [key]: [error type]" | 13 // " [some dart code] /// [key]: [error type]" |
13 // | 14 // |
14 // For each key in the file, a new test file is made containing all | 15 // For each key in the file, a new test file is made containing all |
15 // the normal lines of the file, and all of the multitest lines containing | 16 // the normal lines of the file, and all of the multitest lines containing |
16 // that key, in the same order as in the source file. The new test | 17 // that key, in the same order as in the source file. The new test |
17 // is expected to fail if there is a non-empty error type listed, of | 18 // is expected to fail if there is a non-empty error type listed, of |
18 // type 'compile-time error', 'runtime error', 'static type warning', or | 19 // type 'compile-time error', 'runtime error', 'static type warning', or |
19 // 'dynamic type error'. The type error tests fail only in checked mode. | 20 // 'dynamic type error'. The type error tests fail only in checked mode. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // aaa | 52 // aaa |
52 // ddd /// 07: static type warning, dynamic type error | 53 // ddd /// 07: static type warning, dynamic type error |
53 // eee | 54 // eee |
54 | 55 |
55 void ExtractTestsFromMultitest(Path filePath, | 56 void ExtractTestsFromMultitest(Path filePath, |
56 Map<String, String> tests, | 57 Map<String, String> tests, |
57 Map<String, Set<String>> outcomes) { | 58 Map<String, Set<String>> outcomes) { |
58 // Read the entire file into a byte buffer and transform it to a | 59 // Read the entire file into a byte buffer and transform it to a |
59 // String. This will treat the file as ascii but the only parts | 60 // String. This will treat the file as ascii but the only parts |
60 // we are interested in will be ascii in any case. | 61 // we are interested in will be ascii in any case. |
61 RandomAccessFile file = new File.fromPath(filePath).openSync(FileMode.READ); | 62 List bytes = new File.fromPath(filePath).readAsBytesSync(); |
62 List chars = new List(file.lengthSync()); | 63 String contents = decodeUtf8(bytes); |
63 int offset = 0; | |
64 while (offset != chars.length) { | |
65 offset += file.readListSync(chars, offset, chars.length - offset); | |
66 } | |
67 file.closeSync(); | |
68 String contents = new String.fromCharCodes(chars); | |
69 chars = null; | |
70 int first_newline = contents.indexOf('\n'); | 64 int first_newline = contents.indexOf('\n'); |
71 final String line_separator = | 65 final String line_separator = |
72 (first_newline == 0 || contents[first_newline - 1] != '\r') | 66 (first_newline == 0 || contents[first_newline - 1] != '\r') |
73 ? '\n' | 67 ? '\n' |
74 : '\r\n'; | 68 : '\r\n'; |
75 List<String> lines = contents.split(line_separator); | 69 List<String> lines = contents.split(line_separator); |
76 if (lines.last == '') lines.removeLast(); | 70 if (lines.last == '') lines.removeLast(); |
| 71 bytes = null; |
77 contents = null; | 72 contents = null; |
78 Set<String> validMultitestOutcomes = new Set<String>.from( | 73 Set<String> validMultitestOutcomes = new Set<String>.from( |
79 ['compile-time error', 'runtime error', | 74 ['compile-time error', 'runtime error', |
80 'static type warning', 'dynamic type error']); | 75 'static type warning', 'dynamic type error']); |
81 | 76 |
82 List<String> testTemplate = new List<String>(); | 77 List<String> testTemplate = new List<String>(); |
83 testTemplate.add( | 78 testTemplate.add( |
84 '// Test created from multitest named ${filePath.toNativePath()}.'); | 79 '// Test created from multitest named ${filePath.toNativePath()}.'); |
85 // Create the set of multitests, which will have a new test added each | 80 // Create the set of multitests, which will have a new test added each |
86 // time we see a multitest line with a new key. | 81 // time we see a multitest line with a new key. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // TestSuite.forDirectory. | 256 // TestSuite.forDirectory. |
262 split.removeLast(); | 257 split.removeLast(); |
263 } | 258 } |
264 String path = '${generatedTestDir.path}/${split.last}'; | 259 String path = '${generatedTestDir.path}/${split.last}'; |
265 Directory dir = new Directory(path); | 260 Directory dir = new Directory(path); |
266 if (!dir.existsSync()) { | 261 if (!dir.existsSync()) { |
267 dir.createSync(); | 262 dir.createSync(); |
268 } | 263 } |
269 return new Path(new File(path).fullPathSync()); | 264 return new Path(new File(path).fullPathSync()); |
270 } | 265 } |
OLD | NEW |