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 | 8 |
| 9 // Multitests are Dart test scripts containing lines of the form | 9 // Multitests are Dart test scripts containing lines of the form |
| 10 // " [some dart code] /// [key]: [error type]" | 10 // " [some dart code] /// [key]: [error type]" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 // Copy all the tests into the output map tests, as multiline strings. | 111 // Copy all the tests into the output map tests, as multiline strings. |
| 112 for (String key in testsAsLines.getKeys()) { | 112 for (String key in testsAsLines.getKeys()) { |
| 113 tests[key] = | 113 tests[key] = |
| 114 Strings.join(testsAsLines[key], line_separator) + line_separator; | 114 Strings.join(testsAsLines[key], line_separator) + line_separator; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 | 118 |
| 119 void DoMultitest(String filename, | 119 void DoMultitest(String filename, |
| 120 String component, | 120 String component, |
|
Siggi Cherem (dart-lang)
2012/02/24 19:18:52
seems like this arg might not be necessary anymore
ngeoffray
2012/02/27 09:08:03
Good point. Removed in https://chromiumcodereview.
| |
| 121 String outputDir, | 121 String outputDir, |
| 122 String testDir, | 122 String testDir, |
| 123 Function doTest(String filename, | 123 Function doTest(String filename, |
| 124 bool isNegative, | 124 bool isNegative, |
| 125 [bool isNegativeIfChecked, | 125 [bool isNegativeIfChecked, |
| 126 bool hasFatalTypeErrors]), | 126 bool hasFatalTypeErrors, |
| 127 bool hasRuntimeErrors]), | |
| 127 Function multitestDone) { | 128 Function multitestDone) { |
| 128 // Each new test is a single String value in the Map tests. | 129 // Each new test is a single String value in the Map tests. |
| 129 Map<String, String> tests = new Map<String, String>(); | 130 Map<String, String> tests = new Map<String, String>(); |
| 130 Map<String, String> outcomes = new Map<String, String>(); | 131 Map<String, String> outcomes = new Map<String, String>(); |
| 131 ExtractTestsFromMultitest(filename, tests, outcomes); | 132 ExtractTestsFromMultitest(filename, tests, outcomes); |
| 132 | 133 |
| 133 String directory = CreateMultitestDirectory(outputDir, testDir); | 134 String directory = CreateMultitestDirectory(outputDir, testDir); |
| 134 String pathSeparator = new Platform().pathSeparator(); | 135 String pathSeparator = new Platform().pathSeparator(); |
| 135 int start = filename.lastIndexOf(pathSeparator) + 1; | 136 int start = filename.lastIndexOf(pathSeparator) + 1; |
| 136 int end = filename.indexOf('.dart', start); | 137 int end = filename.indexOf('.dart', start); |
| 137 String baseFilename = filename.substring(start, end); | 138 String baseFilename = filename.substring(start, end); |
| 138 for (String key in tests.getKeys()) { | 139 for (String key in tests.getKeys()) { |
| 139 final String filename = '$directory/${baseFilename}_$key.dart'; | 140 final String filename = '$directory/${baseFilename}_$key.dart'; |
| 140 final File file = new File(filename); | 141 final File file = new File(filename); |
| 141 | 142 |
| 142 file.createSync(); | 143 file.createSync(); |
| 143 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); | 144 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); |
| 144 var bytes = tests[key].charCodes(); | 145 var bytes = tests[key].charCodes(); |
| 145 openedFile.writeListSync(bytes, 0, bytes.length); | 146 openedFile.writeListSync(bytes, 0, bytes.length); |
| 146 openedFile.closeSync(); | 147 openedFile.closeSync(); |
| 147 var outcome = outcomes[key]; | 148 var outcome = outcomes[key]; |
| 148 bool enableFatalTypeErrors = outcome.contains('static type error'); | 149 bool enableFatalTypeErrors = outcome.contains('static type error'); |
| 149 bool isNegative = (outcome.contains('compile-time error') | 150 bool hasRuntimeErrors = outcome.contains('runtime error'); |
| 150 || (outcome.contains('runtime error') && (component != 'dartc'))); | 151 bool isNegative = hasRuntimeErrors |
| 152 || outcome.contains('compile-time error'); | |
| 151 bool isNegativeIfChecked = outcome.contains('dynamic type error'); | 153 bool isNegativeIfChecked = outcome.contains('dynamic type error'); |
| 152 doTest(filename, | 154 doTest(filename, |
| 153 isNegative, | 155 isNegative, |
| 154 isNegativeIfChecked, | 156 isNegativeIfChecked, |
| 155 enableFatalTypeErrors); | 157 enableFatalTypeErrors, |
| 158 hasRuntimeErrors); | |
| 156 } | 159 } |
| 157 multitestDone(); | 160 multitestDone(); |
| 158 } | 161 } |
| 159 | 162 |
| 160 | 163 |
| 161 String CreateMultitestDirectory(String outputDir, String testDir) { | 164 String CreateMultitestDirectory(String outputDir, String testDir) { |
| 162 final String generatedTestDirectory = 'generated_tests'; | 165 final String generatedTestDirectory = 'generated_tests'; |
| 163 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); | 166 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); |
| 164 if (!new Directory(outputDir).existsSync()) { | 167 if (!new Directory(outputDir).existsSync()) { |
| 165 new Directory(outputDir).createSync(); | 168 new Directory(outputDir).createSync(); |
| 166 } | 169 } |
| 167 if (!generatedTestDir.existsSync()) { | 170 if (!generatedTestDir.existsSync()) { |
| 168 generatedTestDir.createSync(); | 171 generatedTestDir.createSync(); |
| 169 } | 172 } |
| 170 var split = testDir.split('/'); | 173 var split = testDir.split('/'); |
| 171 var lastComponent = split.removeLast(); | 174 var lastComponent = split.removeLast(); |
| 172 Expect.isTrue(lastComponent == 'src'); | 175 Expect.isTrue(lastComponent == 'src'); |
| 173 String path = '${generatedTestDir.path}/${split.last()}'; | 176 String path = '${generatedTestDir.path}/${split.last()}'; |
| 174 Directory dir = new Directory(path); | 177 Directory dir = new Directory(path); |
| 175 if (!dir.existsSync()) { | 178 if (!dir.existsSync()) { |
| 176 dir.createSync(); | 179 dir.createSync(); |
| 177 } | 180 } |
| 178 return path; | 181 return path; |
| 179 } | 182 } |
| OLD | NEW |