| 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, |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 var packageName = new Path(fullPath).filename; | 431 var packageName = new Path(fullPath).filename; |
| 432 if (isValid(packageName)) { | 432 if (isValid(packageName)) { |
| 433 return [packageName, path.append(packageName).toNativePath()]; | 433 return [packageName, path.append(packageName).toNativePath()]; |
| 434 } | 434 } |
| 435 return null; | 435 return null; |
| 436 }) | 436 }) |
| 437 .where((name) => name != null) | 437 .where((name) => name != null) |
| 438 .toList(); | 438 .toList(); |
| 439 }); | 439 }); |
| 440 } | 440 } |
| 441 | |
| 442 Future<Map> discoverPackagesInRepository() { | |
| 443 /* | |
| 444 * Layout of packages inside the dart repository: | |
| 445 * dart/ | |
| 446 * pkg/PACKAGE_NAME | |
| 447 * third_party/pkg/PACKAGE_NAME | |
| 448 * third_party/pkg_tested/PACKAGE_NAME | |
| 449 * runtime/observatory/PACKAGE_NAME | |
| 450 * sdk/lib/_internal/PACKAGE_NAME | |
| 451 */ | |
| 452 | |
| 453 // Directories containing "-" are not valid pub packages and we therefore | |
| 454 // do not include them in the list of packages. | |
| 455 isValid(packageName) => | |
| 456 packageName != 'third_party' && !packageName.contains('-'); | |
| 457 | |
| 458 var dartDir = TestUtils.dartDir; | |
| 459 var futures = [ | |
| 460 listDir(dartDir.append('pkg'), isValid), | |
| 461 listDir(dartDir.append('third_party').append('pkg'), isValid), | |
| 462 listDir(dartDir.append('third_party').append('pkg_tested'), isValid), | |
| 463 listDir(dartDir.append('runtime').append('observatory'), isValid), | |
| 464 listDir(dartDir.append('sdk').append('lib').append('_internal'), isValid), | |
| 465 ]; | |
| 466 return Future.wait(futures).then((results) { | |
| 467 var packageDirectories = {}; | |
| 468 for (var result in results) { | |
| 469 for (var packageTuple in result) { | |
| 470 String packageName = packageTuple[0]; | |
| 471 String fullPath = packageTuple[1]; | |
| 472 String yamlFile = | |
| 473 new Path(fullPath).append('pubspec.yaml').toNativePath(); | |
| 474 if (new File(yamlFile).existsSync()) { | |
| 475 packageDirectories[packageName] = fullPath; | |
| 476 } | |
| 477 } | |
| 478 } | |
| 479 return packageDirectories; | |
| 480 }); | |
| 481 } | |
| 482 | |
| 483 Future<Map> discoverSamplesInRepository() { | |
| 484 /* | |
| 485 * Layout of samples inside the dart repository: | |
| 486 * dart/ | |
| 487 * samples/SAMPLE_NAME | |
| 488 * samples/third_party/SAMPLE_NAME | |
| 489 */ | |
| 490 | |
| 491 isValid(packageName) => packageName != 'third_party'; | |
| 492 | |
| 493 var dartDir = TestUtils.dartDir; | |
| 494 var futures = [ | |
| 495 listDir(dartDir.append('samples'), isValid), | |
| 496 listDir(dartDir.append('samples').append('third_party'), isValid), | |
| 497 ]; | |
| 498 return Future.wait(futures).then((results) { | |
| 499 var packageDirectories = {}; | |
| 500 for (var result in results) { | |
| 501 for (var packageTuple in result) { | |
| 502 String packageName = packageTuple[0]; | |
| 503 String fullPath = packageTuple[1]; | |
| 504 packageDirectories[packageName] = fullPath; | |
| 505 } | |
| 506 } | |
| 507 return packageDirectories; | |
| 508 }); | |
| 509 } | |
| 510 } | 441 } |
| 511 | 442 |
| 512 Future<Iterable<String>> ccTestLister(String runnerPath) { | 443 Future<Iterable<String>> ccTestLister(String runnerPath) { |
| 513 return Process.run(runnerPath, ["--list"]).then((ProcessResult result) { | 444 return Process.run(runnerPath, ["--list"]).then((ProcessResult result) { |
| 514 if (result.exitCode != 0) { | 445 if (result.exitCode != 0) { |
| 515 throw "Failed to list tests: '$runnerPath --list'. " | 446 throw "Failed to list tests: '$runnerPath --list'. " |
| 516 "Process exited with ${result.exitCode}"; | 447 "Process exited with ${result.exitCode}"; |
| 517 } | 448 } |
| 518 return result.stdout | 449 return result.stdout |
| 519 .split('\n') | 450 .split('\n') |
| (...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 bool isTestFile(String filename) { | 1802 bool isTestFile(String filename) { |
| 1872 // NOTE: We exclude tests and patch files for now. | 1803 // NOTE: We exclude tests and patch files for now. |
| 1873 return filename.endsWith(".dart") && | 1804 return filename.endsWith(".dart") && |
| 1874 !filename.endsWith("_test.dart") && | 1805 !filename.endsWith("_test.dart") && |
| 1875 !filename.contains("_internal/js_runtime/lib"); | 1806 !filename.contains("_internal/js_runtime/lib"); |
| 1876 } | 1807 } |
| 1877 | 1808 |
| 1878 bool get listRecursively => true; | 1809 bool get listRecursively => true; |
| 1879 } | 1810 } |
| 1880 | 1811 |
| 1881 class PkgBuildTestSuite extends TestSuite { | |
| 1882 final String statusFilePath; | |
| 1883 | |
| 1884 PkgBuildTestSuite(Map configuration, String suiteName, this.statusFilePath) | |
| 1885 : super(configuration, suiteName) { | |
| 1886 assert(configuration['use_sdk']); | |
| 1887 ; | |
| 1888 } | |
| 1889 | |
| 1890 void forEachTest(void onTest(TestCase testCase), _, [void onDone()]) { | |
| 1891 bool fileExists(Path path) => new File(path.toNativePath()).existsSync(); | |
| 1892 | |
| 1893 bool dirExists(Path path) => | |
| 1894 new Directory(path.toNativePath()).existsSync(); | |
| 1895 | |
| 1896 enqueueTestCases( | |
| 1897 Map<String, String> localPackageDirectories, | |
| 1898 Map<String, String> localSampleDirectories, | |
| 1899 TestExpectations testExpectations) { | |
| 1900 enqueueTestCase(String packageName, String directory) { | |
| 1901 var absoluteDirectoryPath = new Path(directory); | |
| 1902 | |
| 1903 // Early return if this package is not using pub. | |
| 1904 if (!fileExists(absoluteDirectoryPath.append('pubspec.yaml'))) { | |
| 1905 return; | |
| 1906 } | |
| 1907 | |
| 1908 var directoryPath = absoluteDirectoryPath.relativeTo(TestUtils.dartDir); | |
| 1909 var testName = "$directoryPath"; | |
| 1910 var displayName = '$suiteName/$testName'; | |
| 1911 | |
| 1912 var checkoutDir = | |
| 1913 createPubPackageBuildsDirectory(absoluteDirectoryPath); | |
| 1914 var cacheDir = new Path(checkoutDir).append("pub-cache").toNativePath(); | |
| 1915 | |
| 1916 // Build all commands | |
| 1917 // In order to debug timeouts on the buildbots, We run `pub get` with | |
| 1918 // "--verbose". See https://github.com/dart-lang/sdk/issues/28734. | |
| 1919 var commands = [ | |
| 1920 CommandBuilder.instance.getCopyCommand(directory, checkoutDir), | |
| 1921 CommandBuilder.instance.getPubCommand( | |
| 1922 "get", pubPath, checkoutDir, cacheDir, | |
| 1923 arguments: ['--verbose']) | |
| 1924 ]; | |
| 1925 | |
| 1926 bool containsWebDirectory = dirExists(directoryPath.append('web')); | |
| 1927 bool containsBuildDartFile = | |
| 1928 fileExists(directoryPath.append('build.dart')); | |
| 1929 if (containsBuildDartFile) { | |
| 1930 var dartBinary = new File(dartVmBinaryFileName).absolute.path; | |
| 1931 | |
| 1932 commands.add(CommandBuilder.instance.getProcessCommand( | |
| 1933 "custom_build", | |
| 1934 dartBinary, | |
| 1935 ['build.dart'], | |
| 1936 {'PUB_CACHE': cacheDir}, | |
| 1937 checkoutDir)); | |
| 1938 | |
| 1939 // We only try to deploy the application if it's a webapp. | |
| 1940 if (containsWebDirectory) { | |
| 1941 commands.add(CommandBuilder.instance.getProcessCommand( | |
| 1942 "custom_deploy", | |
| 1943 dartBinary, | |
| 1944 ['build.dart', '--deploy'], | |
| 1945 {'PUB_CACHE': cacheDir}, | |
| 1946 checkoutDir)); | |
| 1947 } | |
| 1948 } else if (containsWebDirectory) { | |
| 1949 commands.add(CommandBuilder.instance | |
| 1950 .getPubCommand("build", pubPath, checkoutDir, cacheDir)); | |
| 1951 } | |
| 1952 | |
| 1953 // Enqueue TestCase | |
| 1954 var testCase = new TestCase(displayName, commands, configuration, | |
| 1955 testExpectations.expectations(testName)); | |
| 1956 enqueueNewTestCase(testCase); | |
| 1957 } | |
| 1958 | |
| 1959 localPackageDirectories.forEach(enqueueTestCase); | |
| 1960 localSampleDirectories.forEach(enqueueTestCase); | |
| 1961 | |
| 1962 doTest = null; | |
| 1963 // Notify we're done | |
| 1964 if (onDone != null) onDone(); | |
| 1965 } | |
| 1966 | |
| 1967 doTest = onTest; | |
| 1968 List<String> statusFiles = [ | |
| 1969 TestUtils.dartDir.join(new Path(statusFilePath)).toNativePath() | |
| 1970 ]; | |
| 1971 ReadTestExpectations(statusFiles, configuration).then((expectations) { | |
| 1972 Future.wait([ | |
| 1973 discoverPackagesInRepository(), | |
| 1974 discoverSamplesInRepository() | |
| 1975 ]).then((List results) { | |
| 1976 Map packageDirectories = results[0]; | |
| 1977 Map sampleDirectories = results[1]; | |
| 1978 enqueueTestCases(packageDirectories, sampleDirectories, expectations); | |
| 1979 }); | |
| 1980 }); | |
| 1981 } | |
| 1982 } | |
| 1983 | |
| 1984 class LastModifiedCache { | 1812 class LastModifiedCache { |
| 1985 Map<String, DateTime> _cache = <String, DateTime>{}; | 1813 Map<String, DateTime> _cache = <String, DateTime>{}; |
| 1986 | 1814 |
| 1987 /** | 1815 /** |
| 1988 * Returns the last modified date of the given [uri]. | 1816 * Returns the last modified date of the given [uri]. |
| 1989 * | 1817 * |
| 1990 * The return value will be cached for future queries. If [uri] is a local | 1818 * The return value will be cached for future queries. If [uri] is a local |
| 1991 * file, it's last modified [Date] will be returned. If the file does not | 1819 * file, it's last modified [Date] will be returned. If the file does not |
| 1992 * exist, null will be returned instead. | 1820 * exist, null will be returned instead. |
| 1993 * In case [uri] is not a local file, this method will always return | 1821 * In case [uri] is not a local file, this method will always return |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 } | 2235 } |
| 2408 if (path.length > WINDOWS_SHORTEN_PATH_LIMIT) { | 2236 if (path.length > WINDOWS_SHORTEN_PATH_LIMIT) { |
| 2409 ++shortNameCounter; | 2237 ++shortNameCounter; |
| 2410 var pathEnd = path.substring(path.length - WINDOWS_PATH_END_LENGTH); | 2238 var pathEnd = path.substring(path.length - WINDOWS_PATH_END_LENGTH); |
| 2411 path = "short${shortNameCounter}_$pathEnd"; | 2239 path = "short${shortNameCounter}_$pathEnd"; |
| 2412 } | 2240 } |
| 2413 } | 2241 } |
| 2414 return path; | 2242 return path; |
| 2415 } | 2243 } |
| 2416 } | 2244 } |
| OLD | NEW |