| 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 /** | 5 /** |
| 6 * Classes and methods for enumerating and preparing tests. | 6 * Classes and methods for enumerating and preparing tests. |
| 7 * | 7 * |
| 8 * This library includes: | 8 * This library includes: |
| 9 * | 9 * |
| 10 * - Creating tests by listing all the Dart files in certain directories, | 10 * - Creating tests by listing all the Dart files in certain directories, |
| 11 * and creating [TestCase]s for those files that meet the relevant criteria. | 11 * and creating [TestCase]s for those files that meet the relevant criteria. |
| 12 * - Preparing tests, including copying files and frameworks to temporary | 12 * - Preparing tests, including copying files and frameworks to temporary |
| 13 * directories, and computing the command line and arguments to be run. | 13 * directories, and computing the command line and arguments to be run. |
| 14 */ | 14 */ |
| 15 #library("test_suite"); | 15 #library("test_suite"); |
| 16 | 16 |
| 17 #import("dart:io"); | 17 #import("dart:io"); |
| 18 #import("dart:builtin"); | 18 #import("dart:builtin"); |
| 19 #import("dart:isolate"); | 19 #import("dart:isolate"); |
| 20 #import("status_file_parser.dart"); | 20 #import("status_file_parser.dart"); |
| 21 #import("test_runner.dart"); | 21 #import("test_runner.dart"); |
| 22 #import("multitest.dart"); | 22 #import("multitest.dart"); |
| 23 #import("drt_updater.dart"); | 23 #import("drt_updater.dart"); |
| 24 | 24 |
| 25 #source("browser_test.dart"); | 25 #source("browser_test.dart"); |
| 26 | 26 |
| 27 | 27 |
| 28 // TODO(rnystrom): Add to dart:core? |
| 29 /** |
| 30 * A simple function that tests [arg] and returns `true` or `false`. |
| 31 */ |
| 32 typedef bool Predicate<T>(T arg); |
| 33 |
| 34 |
| 28 /** | 35 /** |
| 29 * A TestSuite represents a collection of tests. It creates a [TestCase] | 36 * A TestSuite represents a collection of tests. It creates a [TestCase] |
| 30 * object for each test to be run, and passes the test cases to a callback. | 37 * object for each test to be run, and passes the test cases to a callback. |
| 31 * | 38 * |
| 32 * Most TestSuites represent a directory or directory tree containing tests, | 39 * Most TestSuites represent a directory or directory tree containing tests, |
| 33 * and a status file containing the expected results when these tests are run. | 40 * and a status file containing the expected results when these tests are run. |
| 34 */ | 41 */ |
| 35 interface TestSuite { | 42 interface TestSuite { |
| 36 /** | 43 /** |
| 37 * Call the callback function onTest with a [TestCase] argument for each | 44 * Call the callback function onTest with a [TestCase] argument for each |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 bool isNegativeIfChecked; | 186 bool isNegativeIfChecked; |
| 180 bool hasFatalTypeErrors; | 187 bool hasFatalTypeErrors; |
| 181 bool hasRuntimeErrors; | 188 bool hasRuntimeErrors; |
| 182 Set<String> multitestOutcome; | 189 Set<String> multitestOutcome; |
| 183 | 190 |
| 184 TestInformation(this.filename, this.optionsFromFile, this.isNegative, | 191 TestInformation(this.filename, this.optionsFromFile, this.isNegative, |
| 185 this.isNegativeIfChecked, this.hasFatalTypeErrors, | 192 this.isNegativeIfChecked, this.hasFatalTypeErrors, |
| 186 this.hasRuntimeErrors, this.multitestOutcome); | 193 this.hasRuntimeErrors, this.multitestOutcome); |
| 187 } | 194 } |
| 188 | 195 |
| 196 |
| 189 /** | 197 /** |
| 190 * A standard [TestSuite] implementation that searches for tests in a | 198 * A standard [TestSuite] implementation that searches for tests in a |
| 191 * directory, and creates [TestCase]s that compile and/or run them. | 199 * directory, and creates [TestCase]s that compile and/or run them. |
| 192 */ | 200 */ |
| 193 class StandardTestSuite implements TestSuite { | 201 class StandardTestSuite implements TestSuite { |
| 194 Map configuration; | 202 Map configuration; |
| 195 String suiteName; | 203 String suiteName; |
| 196 String directoryPath; | 204 String directoryPath; |
| 197 List<String> statusFilePaths; | 205 List<String> statusFilePaths; |
| 198 Function doTest; | 206 Function doTest; |
| 199 Function doDone; | 207 Function doDone; |
| 200 int activeTestGenerators = 0; | 208 int activeTestGenerators = 0; |
| 201 bool listingDone = false; | 209 bool listingDone = false; |
| 202 TestExpectations testExpectations; | 210 TestExpectations testExpectations; |
| 203 List<TestInformation> cachedTests; | 211 List<TestInformation> cachedTests; |
| 204 final String dartDir; | 212 final String dartDir; |
| 205 Function globalTemporaryDirectory; | 213 Function globalTemporaryDirectory; |
| 214 Predicate<String> isTestFilePredicate; |
| 206 | 215 |
| 207 StandardTestSuite(Map this.configuration, | 216 StandardTestSuite(Map this.configuration, |
| 208 String this.suiteName, | 217 String this.suiteName, |
| 209 String this.directoryPath, | 218 String this.directoryPath, |
| 210 List<String> this.statusFilePaths) | 219 List<String> this.statusFilePaths, |
| 220 [Predicate<String> this.isTestFilePredicate]) |
| 211 : dartDir = TestUtils.dartDir(); | 221 : dartDir = TestUtils.dartDir(); |
| 212 | 222 |
| 213 /** | 223 /** |
| 224 * Creates a test suite whose file organization matches an expected structure. |
| 225 * To use this, your suite should look like: |
| 226 * |
| 227 * dart/ |
| 228 * path/ |
| 229 * to/ |
| 230 * mytestsuite/ |
| 231 * mytestsuite.status |
| 232 * example1_tests.dart |
| 233 * example2_tests.dart |
| 234 * example3_tests.dart |
| 235 * |
| 236 * The important parts: |
| 237 * |
| 238 * * The leaf directory name is the name of your test suite. |
| 239 * * The status file uses the same name. |
| 240 * * Test files are directly in that directory and end in "_tests.dart". |
| 241 * |
| 242 * If you follow that convention, then you can construct one of these like: |
| 243 * |
| 244 * new DirectoryTestSuite(configuration, 'path/to/mytestsuite'); |
| 245 * |
| 246 * instead of having to create a custom [StandardTestSuite] subclass. In |
| 247 * particular, if you add 'path/to/mytestsuite' to [TEST_SUITE_DIRECTORIES] |
| 248 * in test.dart, this will all be set up for you. |
| 249 */ |
| 250 factory StandardTestSuite.forDirectory( |
| 251 Map configuration, String directory) { |
| 252 final name = directory.substring(directory.lastIndexOf('/') + 1); |
| 253 |
| 254 return new StandardTestSuite(configuration, |
| 255 name, directory, ['$directory/$name.status'], |
| 256 (filename) => filename.endsWith('_tests.dart')); |
| 257 } |
| 258 |
| 259 /** |
| 214 * The default implementation assumes a file is a test if | 260 * The default implementation assumes a file is a test if |
| 215 * it ends in "Test.dart". | 261 * it ends in "Test.dart". |
| 216 */ | 262 */ |
| 217 bool isTestFile(String filename) => filename.endsWith("Test.dart"); | 263 bool isTestFile(String filename) { |
| 264 // Use the specified predicate, if provided. |
| 265 if (isTestFilePredicate != null) return isTestFilePredicate(filename); |
| 266 |
| 267 filename.endsWith("Test.dart"); |
| 268 } |
| 218 | 269 |
| 219 bool listRecursively() => false; | 270 bool listRecursively() => false; |
| 220 | 271 |
| 221 String shellPath() => TestUtils.dartShellFileName(configuration); | 272 String shellPath() => TestUtils.dartShellFileName(configuration); |
| 222 | 273 |
| 223 List<String> additionalOptions(String filename) => []; | 274 List<String> additionalOptions(String filename) => []; |
| 224 | 275 |
| 225 void forEachTest(Function onTest, Map testCache, String globalTempDir(), | 276 void forEachTest(Function onTest, Map testCache, String globalTempDir(), |
| 226 [Function onDone = null]) { | 277 [Function onDone = null]) { |
| 227 // If DumpRenderTree is required, and not yet updated, wait for update. | 278 // If DumpRenderTree is required, and not yet updated, wait for update. |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 * $noCrash tests are expected to be flaky but not crash | 1290 * $noCrash tests are expected to be flaky but not crash |
| 1240 * $pass tests are expected to pass | 1291 * $pass tests are expected to pass |
| 1241 * $failOk tests are expected to fail that we won't fix | 1292 * $failOk tests are expected to fail that we won't fix |
| 1242 * $fail tests are expected to fail that we should fix | 1293 * $fail tests are expected to fail that we should fix |
| 1243 * $crash tests are expected to crash that we should fix | 1294 * $crash tests are expected to crash that we should fix |
| 1244 * $timeout tests are allowed to timeout | 1295 * $timeout tests are allowed to timeout |
| 1245 """; | 1296 """; |
| 1246 print(report); | 1297 print(report); |
| 1247 } | 1298 } |
| 1248 } | 1299 } |
| OLD | NEW |