Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 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 error |
| 46 // eee | 46 // eee |
| 47 // | |
| 48 // Note that it is possible to indicate more than one acceptable outcome | |
| 49 // in the case of dynamic and static type errors | |
| 50 // aaa | |
| 51 // ddd /// 07: static type error, dynamic type error | |
| 52 // eee | |
| 47 | 53 |
| 48 void ExtractTestsFromMultitest(String filename, | 54 void ExtractTestsFromMultitest(String filename, |
| 49 Map<String, String> tests, | 55 Map<String, String> tests, |
| 50 Map<String, String> outcomes) { | 56 Map<String, Set<String>> outcomes) { |
| 51 // 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 |
| 52 // 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 |
| 53 // we are interested in will be ascii in any case. | 59 // we are interested in will be ascii in any case. |
| 54 RandomAccessFile file = (new File(filename)).openSync(); | 60 RandomAccessFile file = (new File(filename)).openSync(); |
| 55 List chars = new List(file.lengthSync()); | 61 List chars = new List(file.lengthSync()); |
| 56 int offset = 0; | 62 int offset = 0; |
| 57 while (offset != chars.length) { | 63 while (offset != chars.length) { |
| 58 offset += file.readListSync(chars, offset, chars.length - offset); | 64 offset += file.readListSync(chars, offset, chars.length - offset); |
| 59 } | 65 } |
| 60 file.closeSync(); | 66 file.closeSync(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 83 lineCount++; | 89 lineCount++; |
| 84 if (line.contains('///')) { | 90 if (line.contains('///')) { |
| 85 var parts = line.split('///')[1].split(':'); | 91 var parts = line.split('///')[1].split(':'); |
| 86 var key = parts[0].trim(); | 92 var key = parts[0].trim(); |
| 87 var rest = parts[1].trim(); | 93 var rest = parts[1].trim(); |
| 88 if (testsAsLines.containsKey(key)) { | 94 if (testsAsLines.containsKey(key)) { |
| 89 Expect.equals('continued', rest); | 95 Expect.equals('continued', rest); |
| 90 testsAsLines[key].add(line); | 96 testsAsLines[key].add(line); |
| 91 } else { | 97 } else { |
| 92 (testsAsLines[key] = new List<String>.from(testTemplate)).add(line); | 98 (testsAsLines[key] = new List<String>.from(testTemplate)).add(line); |
| 93 outcomes[key] = rest; | 99 List<String> outcomesList = rest.split(','); |
| 94 if (!validMultitestOutcomes.contains(rest)) { | 100 for (String nextOutcome in outcomesList) { |
| 95 Expect.fail("Invalid test directive on line ${lineCount}: $rest "); | 101 nextOutcome = nextOutcome.trim(); |
|
Bill Hesse
2012/03/08 13:52:57
Expect(nextOutcome != '')?
Is it illegal to have a
zundel
2012/03/09 00:34:22
The value in the comment has to match a constraine
| |
| 102 outcomes.putIfAbsent(key, () => new Set<String>()).add(nextOutcome); | |
| 103 if (!validMultitestOutcomes.contains(nextOutcome)) { | |
| 104 Expect.fail( | |
| 105 "Invalid test directive '$nextOutcome' on line ${lineCount}: $rest "); | |
|
Bill Hesse
2012/03/08 13:52:57
Is this line too long?
Bill Hesse
2012/03/08 13:52:57
$lineCount
| |
| 106 } | |
| 96 } | 107 } |
| 97 } | 108 } |
| 98 } else { | 109 } else { |
| 99 testTemplate.add(line); | 110 testTemplate.add(line); |
| 100 for (var test in testsAsLines.getValues()) test.add(line); | 111 for (var test in testsAsLines.getValues()) test.add(line); |
| 101 } | 112 } |
| 102 } | 113 } |
| 103 // Add the template, with no multitest lines, as a test with key 'none'. | 114 // Add the template, with no multitest lines, as a test with key 'none'. |
| 104 testsAsLines['none'] = testTemplate; | 115 testsAsLines['none'] = testTemplate; |
| 105 outcomes['none'] = ''; | 116 outcomes['none'] = new Set<String>(); |
| 106 | 117 |
| 107 // Copy all the tests into the output map tests, as multiline strings. | 118 // Copy all the tests into the output map tests, as multiline strings. |
| 108 for (String key in testsAsLines.getKeys()) { | 119 for (String key in testsAsLines.getKeys()) { |
| 109 tests[key] = | 120 tests[key] = |
| 110 Strings.join(testsAsLines[key], line_separator) + line_separator; | 121 Strings.join(testsAsLines[key], line_separator) + line_separator; |
| 111 } | 122 } |
| 112 } | 123 } |
| 113 | 124 |
| 114 // Find all relative imports and copy them into the dir that contains | 125 // Find all relative imports and copy them into the dir that contains |
| 115 // the generated tests. | 126 // the generated tests. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 // with the 'multitestOutcome' field? | 169 // with the 'multitestOutcome' field? |
| 159 Function doTest(String filename, | 170 Function doTest(String filename, |
| 160 bool isNegative, | 171 bool isNegative, |
| 161 [bool isNegativeIfChecked, | 172 [bool isNegativeIfChecked, |
| 162 bool hasFatalTypeErrors, | 173 bool hasFatalTypeErrors, |
| 163 bool hasRuntimeErrors, | 174 bool hasRuntimeErrors, |
| 164 String multitestOutcome]), | 175 String multitestOutcome]), |
| 165 Function multitestDone) { | 176 Function multitestDone) { |
| 166 // Each new test is a single String value in the Map tests. | 177 // Each new test is a single String value in the Map tests. |
| 167 Map<String, String> tests = new Map<String, String>(); | 178 Map<String, String> tests = new Map<String, String>(); |
| 168 Map<String, String> outcomes = new Map<String, String>(); | 179 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); |
| 169 ExtractTestsFromMultitest(filename, tests, outcomes); | 180 ExtractTestsFromMultitest(filename, tests, outcomes); |
| 170 | 181 |
| 171 String directory = CreateMultitestDirectory(outputDir, testDir); | 182 String directory = CreateMultitestDirectory(outputDir, testDir); |
| 172 Expect.isNotNull(directory); | 183 Expect.isNotNull(directory); |
| 173 String pathSep = new Platform().pathSeparator(); | 184 String pathSep = new Platform().pathSeparator(); |
| 174 int start = filename.lastIndexOf(pathSep) + 1; | 185 int start = filename.lastIndexOf(pathSep) + 1; |
| 175 int end = filename.indexOf('.dart', start); | 186 int end = filename.indexOf('.dart', start); |
| 176 String baseFilename = filename.substring(start, end); | 187 String baseFilename = filename.substring(start, end); |
| 177 String sourceDirectory = filename.substring(0, start - 1); | 188 String sourceDirectory = filename.substring(0, start - 1); |
| 178 Set<String> importsToCopy = _findAllRelativeImports(filename); | 189 Set<String> importsToCopy = _findAllRelativeImports(filename); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 190 } | 201 } |
| 191 for (String key in tests.getKeys()) { | 202 for (String key in tests.getKeys()) { |
| 192 final String filename = '$directory/${baseFilename}_$key.dart'; | 203 final String filename = '$directory/${baseFilename}_$key.dart'; |
| 193 final File file = new File(filename); | 204 final File file = new File(filename); |
| 194 | 205 |
| 195 file.createSync(); | 206 file.createSync(); |
| 196 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); | 207 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); |
| 197 var bytes = tests[key].charCodes(); | 208 var bytes = tests[key].charCodes(); |
| 198 openedFile.writeListSync(bytes, 0, bytes.length); | 209 openedFile.writeListSync(bytes, 0, bytes.length); |
| 199 openedFile.closeSync(); | 210 openedFile.closeSync(); |
| 200 var outcome = outcomes[key]; | 211 Set<String> outcome = outcomes[key]; |
| 201 bool enableFatalTypeErrors = outcome.contains('static type error'); | 212 bool enableFatalTypeErrors = outcome.contains('static type error'); |
| 202 bool hasRuntimeErrors = outcome.contains('runtime error'); | 213 bool hasRuntimeErrors = outcome.contains('runtime error'); |
| 203 bool isNegative = hasRuntimeErrors | 214 bool isNegative = hasRuntimeErrors |
| 204 || outcome.contains('compile-time error'); | 215 || outcome.contains('compile-time error'); |
| 205 bool isNegativeIfChecked = outcome.contains('dynamic type error'); | 216 bool isNegativeIfChecked = outcome.contains('dynamic type error'); |
| 206 doTest(filename, | 217 doTest(filename, |
| 207 isNegative, | 218 isNegative, |
| 208 isNegativeIfChecked, | 219 isNegativeIfChecked, |
| 209 enableFatalTypeErrors, | 220 enableFatalTypeErrors, |
| 210 hasRuntimeErrors, | 221 hasRuntimeErrors, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 226 var split = testDir.split('/'); | 237 var split = testDir.split('/'); |
| 227 var lastComponent = split.removeLast(); | 238 var lastComponent = split.removeLast(); |
| 228 Expect.isTrue(lastComponent == 'src'); | 239 Expect.isTrue(lastComponent == 'src'); |
| 229 String path = '${generatedTestDir.path}/${split.last()}'; | 240 String path = '${generatedTestDir.path}/${split.last()}'; |
| 230 Directory dir = new Directory(path); | 241 Directory dir = new Directory(path); |
| 231 if (!dir.existsSync()) { | 242 if (!dir.existsSync()) { |
| 232 dir.createSync(); | 243 dir.createSync(); |
| 233 } | 244 } |
| 234 return path; | 245 return path; |
| 235 } | 246 } |
| OLD | NEW |