| 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 // Multitests are Dart test scripts containing lines of the form | 7 // Multitests are Dart test scripts containing lines of the form |
| 8 // " [some dart code] /// [key]: [error type]" | 8 // " [some dart code] /// [key]: [error type]" |
| 9 // | 9 // |
| 10 // For each key in the file, a new test file is made containing all | 10 // For each key in the file, a new test file is made containing all |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 for (String key in testsAsLines.getKeys()) { | 111 for (String key in testsAsLines.getKeys()) { |
| 112 tests[key] = | 112 tests[key] = |
| 113 Strings.join(testsAsLines[key], line_separator) + line_separator; | 113 Strings.join(testsAsLines[key], line_separator) + line_separator; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 void DoMultitest(String filename, | 118 void DoMultitest(String filename, |
| 119 String buildDir, | 119 String buildDir, |
| 120 String testDir, | 120 String testDir, |
| 121 bool supportsFatalTypeErrors, |
| 121 Function doTest(String filename, | 122 Function doTest(String filename, |
| 122 bool isNegative, | 123 bool isNegative, |
| 123 [bool isNegativeIfChecked]), | 124 [bool isNegativeIfChecked]), |
| 124 Function multitestDone) { | 125 Function multitestDone) { |
| 125 // Each new test is a single String value in the Map tests. | 126 // Each new test is a single String value in the Map tests. |
| 126 Map<String, String> tests = new Map<String, String>(); | 127 Map<String, String> tests = new Map<String, String>(); |
| 127 Map<String, String> outcomes = new Map<String, String>(); | 128 Map<String, String> outcomes = new Map<String, String>(); |
| 128 ExtractTestsFromMultitest(filename, tests, outcomes); | 129 ExtractTestsFromMultitest(filename, tests, outcomes); |
| 129 | 130 |
| 130 String directory = CreateMultitestDirectory(buildDir, testDir); | 131 String directory = CreateMultitestDirectory(buildDir, testDir); |
| 131 String pathSeparator = new Platform().pathSeparator(); | 132 String pathSeparator = new Platform().pathSeparator(); |
| 132 int start = filename.lastIndexOf(pathSeparator) + 1; | 133 int start = filename.lastIndexOf(pathSeparator) + 1; |
| 133 int end = filename.indexOf('.dart', start); | 134 int end = filename.indexOf('.dart', start); |
| 134 String baseFilename = filename.substring(start, end); | 135 String baseFilename = filename.substring(start, end); |
| 135 Iterator currentKey = tests.getKeys().iterator(); | 136 Iterator currentKey = tests.getKeys().iterator(); |
| 136 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, | 137 WriteMultitestToFileAndQueueIt(tests, |
| 138 outcomes, |
| 139 supportsFatalTypeErrors, |
| 140 currentKey, |
| 137 '$directory$pathSeparator$baseFilename', | 141 '$directory$pathSeparator$baseFilename', |
| 138 doTest, multitestDone); | 142 doTest, |
| 143 multitestDone); |
| 139 } | 144 } |
| 140 | 145 |
| 141 | 146 |
| 142 // Write multiple tests to files, using tail recursion in a callback | 147 // Write multiple tests to files, using tail recursion in a callback |
| 143 // to serialize the file operations, rather than opening all files at once. | 148 // to serialize the file operations, rather than opening all files at once. |
| 144 WriteMultitestToFileAndQueueIt(Map<String, String> tests, | 149 WriteMultitestToFileAndQueueIt(Map<String, String> tests, |
| 145 Map<String, String> outcomes, | 150 Map<String, String> outcomes, |
| 151 bool supportsFatalTypeErrors, |
| 146 Iterator currentKey, | 152 Iterator currentKey, |
| 147 String basePath, | 153 String basePath, |
| 148 Function doTest, | 154 Function doTest, |
| 149 Function done) { | 155 Function done) { |
| 150 if (!currentKey.hasNext()) { | 156 if (!currentKey.hasNext()) { |
| 151 done(); | 157 done(); |
| 152 return; | 158 return; |
| 153 } | 159 } |
| 154 final String key = currentKey.next(); | 160 final String key = currentKey.next(); |
| 155 final String filename = '${basePath}_$key.dart'; | 161 final String filename = '${basePath}_$key.dart'; |
| 156 final File file = new File(filename); | 162 final File file = new File(filename); |
| 157 file.errorHandler = (error) { | 163 file.errorHandler = (error) { |
| 158 Expect.fail("Error creating temp file: $error"); | 164 Expect.fail("Error creating temp file: $error"); |
| 159 }; | 165 }; |
| 160 file.createHandler = () { | 166 file.createHandler = () { |
| 161 file.open(writable: true); | 167 file.open(writable: true); |
| 162 }; | 168 }; |
| 163 file.openHandler = () { | 169 file.openHandler = () { |
| 164 var bytes = tests[key].charCodes(); | 170 var bytes = tests[key].charCodes(); |
| 165 file.writeList(bytes, 0, bytes.length); | 171 file.writeList(bytes, 0, bytes.length); |
| 166 }; | 172 }; |
| 167 file.noPendingWriteHandler =() { | 173 file.noPendingWriteHandler =() { |
| 168 file.close(); | 174 file.close(); |
| 169 }; | 175 }; |
| 170 file.closeHandler = () { | 176 file.closeHandler = () { |
| 171 var outcome = outcomes[key]; | 177 var outcome = outcomes[key]; |
| 172 bool isNegative = outcome.contains('compile-time error') || | 178 bool enableFatalTypeErrors = (supportsFatalTypeErrors && |
| 173 outcome.contains('runtime error'); | 179 outcome.contains('static type error')); |
| 180 bool isNegative = (outcome.contains('compile-time error') || |
| 181 outcome.contains('runtime error') || |
| 182 enableFatalTypeErrors); |
| 174 bool isNegativeIfChecked = outcome.contains('type error'); | 183 bool isNegativeIfChecked = outcome.contains('type error'); |
| 175 doTest(filename, isNegative, isNegativeIfChecked); | 184 doTest(filename, |
| 176 // TODO(whesse): Register files and directories to be deleted. | 185 isNegative, |
| 177 // They should be registered in a persistent list, so they can | 186 isNegativeIfChecked, |
| 178 // be deleted later even if the test script is interrupted. | 187 enableFatalTypeErrors); |
| 179 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, | 188 WriteMultitestToFileAndQueueIt(tests, |
| 180 basePath, doTest, done); | 189 outcomes, |
| 190 supportsFatalTypeErrors, |
| 191 currentKey, |
| 192 basePath, |
| 193 doTest, |
| 194 done); |
| 181 }; | 195 }; |
| 182 file.create(); | 196 file.create(); |
| 183 } | 197 } |
| 184 | 198 |
| 185 String CreateMultitestDirectory(String buildDir, String testDir) { | 199 String CreateMultitestDirectory(String buildDir, String testDir) { |
| 186 final String generatedTestDirectory = 'generated_tests/'; | 200 final String generatedTestDirectory = 'generated_tests/'; |
| 187 Directory parent_dir = new Directory(buildDir + generatedTestDirectory); | 201 Directory parent_dir = new Directory(buildDir + generatedTestDirectory); |
| 188 if (!parent_dir.existsSync()) { | 202 if (!parent_dir.existsSync()) { |
| 189 parent_dir.createSync(); | 203 parent_dir.createSync(); |
| 190 } | 204 } |
| 191 var split = testDir.split(new Platform().pathSeparator()); | 205 var split = testDir.split(new Platform().pathSeparator()); |
| 192 var lastComponent = split.removeLast(); | 206 var lastComponent = split.removeLast(); |
| 193 Expect.isTrue(lastComponent == 'src'); | 207 Expect.isTrue(lastComponent == 'src'); |
| 194 String path = parent_dir.path + split.last(); | 208 String path = parent_dir.path + split.last(); |
| 195 Directory dir = new Directory(path); | 209 Directory dir = new Directory(path); |
| 196 if (!dir.existsSync()) { | 210 if (!dir.existsSync()) { |
| 197 dir.createSync(); | 211 dir.createSync(); |
| 198 } | 212 } |
| 199 return path; | 213 return path; |
| 200 } | 214 } |
| OLD | NEW |