| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 /** | 379 /** |
| 380 * Create a directories for generated assets (tests, html files, | 380 * Create a directories for generated assets (tests, html files, |
| 381 * pubspec checkouts ...). | 381 * pubspec checkouts ...). |
| 382 */ | 382 */ |
| 383 | 383 |
| 384 String createOutputDirectory(Path testPath, String optionsName) { | 384 String createOutputDirectory(Path testPath, String optionsName) { |
| 385 var checked = configuration['checked'] ? '-checked' : ''; | 385 var checked = configuration['checked'] ? '-checked' : ''; |
| 386 var strong = configuration['strong'] ? '-strong' : ''; | 386 var strong = configuration['strong'] ? '-strong' : ''; |
| 387 var minified = configuration['minified'] ? '-minified' : ''; | 387 var minified = configuration['minified'] ? '-minified' : ''; |
| 388 var sdk = configuration['use_sdk'] ? '-sdk' : ''; | 388 var sdk = configuration['use_sdk'] ? '-sdk' : ''; |
| 389 var packages = | |
| 390 configuration['use_public_packages'] ? '-public_packages' : ''; | |
| 391 var dirName = "${configuration['compiler']}-${configuration['runtime']}" | 389 var dirName = "${configuration['compiler']}-${configuration['runtime']}" |
| 392 "$checked$strong$minified$packages$sdk"; | 390 "$checked$strong$minified$sdk"; |
| 393 return createGeneratedTestDirectoryHelper( | 391 return createGeneratedTestDirectoryHelper( |
| 394 "tests", dirName, testPath, optionsName); | 392 "tests", dirName, testPath, optionsName); |
| 395 } | 393 } |
| 396 | 394 |
| 397 String createCompilationOutputDirectory(Path testPath) { | 395 String createCompilationOutputDirectory(Path testPath) { |
| 398 var checked = configuration['checked'] ? '-checked' : ''; | 396 var checked = configuration['checked'] ? '-checked' : ''; |
| 399 var strong = configuration['strong'] ? '-strong' : ''; | 397 var strong = configuration['strong'] ? '-strong' : ''; |
| 400 var minified = configuration['minified'] ? '-minified' : ''; | 398 var minified = configuration['minified'] ? '-minified' : ''; |
| 401 var csp = configuration['csp'] ? '-csp' : ''; | 399 var csp = configuration['csp'] ? '-csp' : ''; |
| 402 var sdk = configuration['use_sdk'] ? '-sdk' : ''; | 400 var sdk = configuration['use_sdk'] ? '-sdk' : ''; |
| 403 var packages = | |
| 404 configuration['use_public_packages'] ? '-public_packages' : ''; | |
| 405 var dirName = "${configuration['compiler']}" | 401 var dirName = "${configuration['compiler']}" |
| 406 "$checked$strong$minified$csp$packages$sdk"; | 402 "$checked$strong$minified$csp$sdk"; |
| 407 return createGeneratedTestDirectoryHelper( | 403 return createGeneratedTestDirectoryHelper( |
| 408 "compilations", dirName, testPath, ""); | 404 "compilations", dirName, testPath, ""); |
| 409 } | 405 } |
| 410 | 406 |
| 411 String createPubspecCheckoutDirectory(Path directoryOfPubspecYaml) { | 407 String createPubspecCheckoutDirectory(Path directoryOfPubspecYaml) { |
| 412 var sdk = configuration['use_sdk'] ? '-sdk' : ''; | 408 var sdk = configuration['use_sdk'] ? 'sdk' : ''; |
| 413 var pkg = configuration['use_public_packages'] | |
| 414 ? 'public_packages' | |
| 415 : 'repo_packages'; | |
| 416 return createGeneratedTestDirectoryHelper( | 409 return createGeneratedTestDirectoryHelper( |
| 417 "pubspec_checkouts", '$pkg$sdk', directoryOfPubspecYaml, ""); | 410 "pubspec_checkouts", sdk, directoryOfPubspecYaml, ""); |
| 418 } | 411 } |
| 419 | 412 |
| 420 String createPubPackageBuildsDirectory(Path directoryOfPubspecYaml) { | 413 String createPubPackageBuildsDirectory(Path directoryOfPubspecYaml) { |
| 421 var pkg = configuration['use_public_packages'] | |
| 422 ? 'public_packages' | |
| 423 : 'repo_packages'; | |
| 424 return createGeneratedTestDirectoryHelper( | 414 return createGeneratedTestDirectoryHelper( |
| 425 "pub_package_builds", pkg, directoryOfPubspecYaml, ""); | 415 "pub_package_builds", 'public_packages', directoryOfPubspecYaml, ""); |
| 426 } | 416 } |
| 427 | 417 |
| 428 /** | 418 /** |
| 429 * Helper function for discovering the packages in the dart repository. | 419 * Helper function for discovering the packages in the dart repository. |
| 430 */ | 420 */ |
| 431 Future<List> listDir(Path path, Function isValid) { | 421 Future<List> listDir(Path path, Function isValid) { |
| 432 var dir = new Directory(path.toNativePath()); | 422 var dir = new Directory(path.toNativePath()); |
| 433 return dir.exists().then((var exist) { | 423 return dir.exists().then((var exist) { |
| 434 if (!exist) return []; | 424 if (!exist) return []; |
| 435 return dir | 425 return dir |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 for (var result in results) { | 499 for (var result in results) { |
| 510 for (var packageTuple in result) { | 500 for (var packageTuple in result) { |
| 511 String packageName = packageTuple[0]; | 501 String packageName = packageTuple[0]; |
| 512 String fullPath = packageTuple[1]; | 502 String fullPath = packageTuple[1]; |
| 513 packageDirectories[packageName] = fullPath; | 503 packageDirectories[packageName] = fullPath; |
| 514 } | 504 } |
| 515 } | 505 } |
| 516 return packageDirectories; | 506 return packageDirectories; |
| 517 }); | 507 }); |
| 518 } | 508 } |
| 519 | |
| 520 /** | |
| 521 * Helper function for building dependency_overrides for pubspec.yaml files. | |
| 522 */ | |
| 523 Map buildPubspecDependencyOverrides(Map packageDirectories) { | |
| 524 Map overrides = {}; | |
| 525 packageDirectories.forEach((String packageName, String fullPath) { | |
| 526 overrides[packageName] = {'path': fullPath}; | |
| 527 }); | |
| 528 return overrides; | |
| 529 } | |
| 530 } | 509 } |
| 531 | 510 |
| 532 Future<Iterable<String>> ccTestLister(String runnerPath) { | 511 Future<Iterable<String>> ccTestLister(String runnerPath) { |
| 533 return Process.run(runnerPath, ["--list"]).then((ProcessResult result) { | 512 return Process.run(runnerPath, ["--list"]).then((ProcessResult result) { |
| 534 if (result.exitCode != 0) { | 513 if (result.exitCode != 0) { |
| 535 throw "Failed to list tests: '$runnerPath --list'. " | 514 throw "Failed to list tests: '$runnerPath --list'. " |
| 536 "Process exited with ${result.exitCode}"; | 515 "Process exited with ${result.exitCode}"; |
| 537 } | 516 } |
| 538 return result.stdout | 517 return result.stdout |
| 539 .split('\n') | 518 .split('\n') |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 | 868 |
| 890 void enqueueTestCaseFromTestInformation(TestInformation info) { | 869 void enqueueTestCaseFromTestInformation(TestInformation info) { |
| 891 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, | 870 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, |
| 892 multitestName: | 871 multitestName: |
| 893 info.optionsFromFile['isMultitest'] ? info.multitestKey : ""); | 872 info.optionsFromFile['isMultitest'] ? info.multitestKey : ""); |
| 894 Set<Expectation> expectations = testExpectations.expectations(testName); | 873 Set<Expectation> expectations = testExpectations.expectations(testName); |
| 895 if (info is HtmlTestInformation) { | 874 if (info is HtmlTestInformation) { |
| 896 enqueueHtmlTest(info, testName, expectations); | 875 enqueueHtmlTest(info, testName, expectations); |
| 897 return; | 876 return; |
| 898 } | 877 } |
| 899 var filePath = info.filePath; | |
| 900 var optionsFromFile = info.optionsFromFile; | 878 var optionsFromFile = info.optionsFromFile; |
| 901 | 879 |
| 902 Map buildSpecialPackageRoot(Path pubspecYamlFile) { | |
| 903 var commands = <Command>[]; | |
| 904 var packageDir = pubspecYamlFile.directoryPath; | |
| 905 var packageName = packageDir.filename; | |
| 906 | |
| 907 var checkoutDirectory = createPubspecCheckoutDirectory(packageDir); | |
| 908 var modifiedYamlFile = new Path(checkoutDirectory).append("pubspec.yaml"); | |
| 909 var pubCacheDirectory = new Path(checkoutDirectory).append("pub-cache"); | |
| 910 var newPackageRoot = new Path(checkoutDirectory).append("packages"); | |
| 911 | |
| 912 // Remove the old packages directory, so we can do a clean 'pub get'. | |
| 913 var newPackagesDirectory = new Directory(newPackageRoot.toNativePath()); | |
| 914 if (newPackagesDirectory.existsSync()) { | |
| 915 newPackagesDirectory.deleteSync(recursive: true); | |
| 916 } | |
| 917 | |
| 918 // NOTE: We make a link in the package-root to [packageName], since | |
| 919 // 'pub get' doesn't create the link to the package containing | |
| 920 // pubspec.yaml if there is no lib directory. | |
| 921 var packageLink = newPackageRoot.append(packageName); | |
| 922 var packageLinkTarget = packageDir.append('lib'); | |
| 923 | |
| 924 // NOTE: We make a link in the package-root to pkg/expect, since | |
| 925 // 'package:expect' is not available on pub.dartlang.org! | |
| 926 var expectLink = newPackageRoot.append('expect'); | |
| 927 var expectLinkTarget = | |
| 928 TestUtils.dartDir.append('pkg').append('expect').append('lib'); | |
| 929 | |
| 930 // Generate dependency overrides if we use repository packages. | |
| 931 var packageDirectories = {}; | |
| 932 if (configuration['use_repository_packages']) { | |
| 933 packageDirectories = new Map.from(localPackageDirectories); | |
| 934 | |
| 935 // Don't create a dependency override for pub, since it's an application | |
| 936 // package and it has a dependency on compiler_unsupported which isn't | |
| 937 // in the repo. | |
| 938 packageDirectories.remove('pub'); | |
| 939 | |
| 940 // Do not create an dependency override for the package itself. | |
| 941 if (packageDirectories.containsKey(packageName)) { | |
| 942 packageDirectories.remove(packageName); | |
| 943 } | |
| 944 } | |
| 945 var overrides = buildPubspecDependencyOverrides(packageDirectories); | |
| 946 | |
| 947 commands.add(CommandBuilder.instance.getModifyPubspecCommand( | |
| 948 pubspecYamlFile.toNativePath(), overrides, | |
| 949 destinationFile: modifiedYamlFile.toNativePath())); | |
| 950 commands.add(CommandBuilder.instance.getPubCommand( | |
| 951 "get", pubPath, checkoutDirectory, pubCacheDirectory.toNativePath())); | |
| 952 if (new Directory(packageLinkTarget.toNativePath()).existsSync()) { | |
| 953 commands.add(CommandBuilder.instance.getMakeSymlinkCommand( | |
| 954 packageLink.toNativePath(), packageLinkTarget.toNativePath())); | |
| 955 } | |
| 956 commands.add(CommandBuilder.instance.getMakeSymlinkCommand( | |
| 957 expectLink.toNativePath(), expectLinkTarget.toNativePath())); | |
| 958 | |
| 959 return {'commands': commands, 'package-root': newPackageRoot,}; | |
| 960 } | |
| 961 | |
| 962 // If this test is inside a package, we will check if there is a | 880 // If this test is inside a package, we will check if there is a |
| 963 // pubspec.yaml file and if so, create a custom package root for it. | 881 // pubspec.yaml file and if so, create a custom package root for it. |
| 964 List<Command> baseCommands = <Command>[]; | 882 List<Command> baseCommands = <Command>[]; |
| 965 Path packageRoot; | 883 Path packageRoot; |
| 966 Path packages; | 884 Path packages; |
| 967 if (configuration['use_repository_packages'] || | 885 |
| 968 configuration['use_public_packages']) { | |
| 969 Path pubspecYamlFile = _findPubspecYamlFile(filePath); | |
| 970 if (pubspecYamlFile != null) { | |
| 971 var result = buildSpecialPackageRoot(pubspecYamlFile); | |
| 972 baseCommands.addAll(result['commands']); | |
| 973 packageRoot = result['package-root']; | |
| 974 if (optionsFromFile['packageRoot'] == null || | |
| 975 optionsFromFile['packageRoot'] == "") { | |
| 976 optionsFromFile['packageRoot'] = packageRoot.toNativePath(); | |
| 977 } | |
| 978 } | |
| 979 } | |
| 980 if (optionsFromFile['packageRoot'] == null && | 886 if (optionsFromFile['packageRoot'] == null && |
| 981 optionsFromFile['packages'] == null) { | 887 optionsFromFile['packages'] == null) { |
| 982 if (configuration['package_root'] != null) { | 888 if (configuration['package_root'] != null) { |
| 983 packageRoot = new Path(configuration['package_root']); | 889 packageRoot = new Path(configuration['package_root']); |
| 984 optionsFromFile['packageRoot'] = packageRoot.toNativePath(); | 890 optionsFromFile['packageRoot'] = packageRoot.toNativePath(); |
| 985 } | 891 } |
| 986 if (configuration['packages'] != null) { | 892 if (configuration['packages'] != null) { |
| 987 Path packages = new Path(configuration['packages']); | 893 Path packages = new Path(configuration['packages']); |
| 988 optionsFromFile['packages'] = packages.toNativePath(); | 894 optionsFromFile['packages'] = packages.toNativePath(); |
| 989 } | 895 } |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 var absoluteDirectoryPath = new Path(directory); | 1916 var absoluteDirectoryPath = new Path(directory); |
| 2011 | 1917 |
| 2012 // Early return if this package is not using pub. | 1918 // Early return if this package is not using pub. |
| 2013 if (!fileExists(absoluteDirectoryPath.append('pubspec.yaml'))) { | 1919 if (!fileExists(absoluteDirectoryPath.append('pubspec.yaml'))) { |
| 2014 return; | 1920 return; |
| 2015 } | 1921 } |
| 2016 | 1922 |
| 2017 var directoryPath = absoluteDirectoryPath.relativeTo(TestUtils.dartDir); | 1923 var directoryPath = absoluteDirectoryPath.relativeTo(TestUtils.dartDir); |
| 2018 var testName = "$directoryPath"; | 1924 var testName = "$directoryPath"; |
| 2019 var displayName = '$suiteName/$testName'; | 1925 var displayName = '$suiteName/$testName'; |
| 2020 var packageName = directoryPath.filename; | |
| 2021 | 1926 |
| 2022 // Collect necessary paths for pubspec.yaml overrides, pub-cache, ... | |
| 2023 var checkoutDir = | 1927 var checkoutDir = |
| 2024 createPubPackageBuildsDirectory(absoluteDirectoryPath); | 1928 createPubPackageBuildsDirectory(absoluteDirectoryPath); |
| 2025 var cacheDir = new Path(checkoutDir).append("pub-cache").toNativePath(); | 1929 var cacheDir = new Path(checkoutDir).append("pub-cache").toNativePath(); |
| 2026 var pubspecYamlFile = | |
| 2027 new Path(checkoutDir).append('pubspec.yaml').toNativePath(); | |
| 2028 | |
| 2029 var packageDirectories = {}; | |
| 2030 if (!configuration['use_public_packages']) { | |
| 2031 packageDirectories = new Map.from(localPackageDirectories); | |
| 2032 | |
| 2033 // Don't create a dependency override for pub, since it's an | |
| 2034 // application package and it has a dependency on compiler_unsupported | |
| 2035 // which isn't in the repo. | |
| 2036 packageDirectories.remove('pub'); | |
| 2037 | |
| 2038 if (packageDirectories.containsKey(packageName)) { | |
| 2039 packageDirectories.remove(packageName); | |
| 2040 } | |
| 2041 } | |
| 2042 var dependencyOverrides = | |
| 2043 buildPubspecDependencyOverrides(packageDirectories); | |
| 2044 | 1930 |
| 2045 // Build all commands | 1931 // Build all commands |
| 2046 var commands = new List<Command>(); | 1932 var commands = [ |
| 2047 commands.add( | 1933 CommandBuilder.instance.getCopyCommand(directory, checkoutDir), |
| 2048 CommandBuilder.instance.getCopyCommand(directory, checkoutDir)); | 1934 CommandBuilder.instance.getPubCommand( |
| 2049 commands.add(CommandBuilder.instance | 1935 "get", pubPath, checkoutDir, cacheDir) |
| 2050 .getModifyPubspecCommand(pubspecYamlFile, dependencyOverrides)); | 1936 ]; |
| 2051 commands.add(CommandBuilder.instance | |
| 2052 .getPubCommand("get", pubPath, checkoutDir, cacheDir)); | |
| 2053 | 1937 |
| 2054 bool containsWebDirectory = dirExists(directoryPath.append('web')); | 1938 bool containsWebDirectory = dirExists(directoryPath.append('web')); |
| 2055 bool containsBuildDartFile = | 1939 bool containsBuildDartFile = |
| 2056 fileExists(directoryPath.append('build.dart')); | 1940 fileExists(directoryPath.append('build.dart')); |
| 2057 if (containsBuildDartFile) { | 1941 if (containsBuildDartFile) { |
| 2058 var dartBinary = new File(dartVmBinaryFileName).absolute.path; | 1942 var dartBinary = new File(dartVmBinaryFileName).absolute.path; |
| 2059 | 1943 |
| 2060 commands.add(CommandBuilder.instance.getProcessCommand( | 1944 commands.add(CommandBuilder.instance.getProcessCommand( |
| 2061 "custom_build", | 1945 "custom_build", |
| 2062 dartBinary, | 1946 dartBinary, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2254 | 2138 |
| 2255 static deleteTempSnapshotDirectory(Map configuration) { | 2139 static deleteTempSnapshotDirectory(Map configuration) { |
| 2256 if (configuration['compiler'] == 'dart2app' || | 2140 if (configuration['compiler'] == 'dart2app' || |
| 2257 configuration['compiler'] == 'dart2appjit' || | 2141 configuration['compiler'] == 'dart2appjit' || |
| 2258 configuration['compiler'] == 'precompiler') { | 2142 configuration['compiler'] == 'precompiler') { |
| 2259 var checked = configuration['checked'] ? '-checked' : ''; | 2143 var checked = configuration['checked'] ? '-checked' : ''; |
| 2260 var strong = configuration['strong'] ? '-strong' : ''; | 2144 var strong = configuration['strong'] ? '-strong' : ''; |
| 2261 var minified = configuration['minified'] ? '-minified' : ''; | 2145 var minified = configuration['minified'] ? '-minified' : ''; |
| 2262 var csp = configuration['csp'] ? '-csp' : ''; | 2146 var csp = configuration['csp'] ? '-csp' : ''; |
| 2263 var sdk = configuration['use_sdk'] ? '-sdk' : ''; | 2147 var sdk = configuration['use_sdk'] ? '-sdk' : ''; |
| 2264 var packages = | |
| 2265 configuration['use_public_packages'] ? '-public_packages' : ''; | |
| 2266 var dirName = "${configuration['compiler']}" | 2148 var dirName = "${configuration['compiler']}" |
| 2267 "$checked$strong$minified$csp$packages$sdk"; | 2149 "$checked$strong$minified$csp$sdk"; |
| 2268 String generatedPath = "${TestUtils.buildDir(configuration)}" | 2150 String generatedPath = "${TestUtils.buildDir(configuration)}" |
| 2269 "/generated_compilations/$dirName"; | 2151 "/generated_compilations/$dirName"; |
| 2270 TestUtils.deleteDirectory(generatedPath); | 2152 TestUtils.deleteDirectory(generatedPath); |
| 2271 } | 2153 } |
| 2272 } | 2154 } |
| 2273 | 2155 |
| 2274 static Path debugLogfile() { | 2156 static Path debugLogfile() { |
| 2275 return new Path(".debug.log"); | 2157 return new Path(".debug.log"); |
| 2276 } | 2158 } |
| 2277 | 2159 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 } | 2420 } |
| 2539 if (path.length > WINDOWS_SHORTEN_PATH_LIMIT) { | 2421 if (path.length > WINDOWS_SHORTEN_PATH_LIMIT) { |
| 2540 ++shortNameCounter; | 2422 ++shortNameCounter; |
| 2541 var pathEnd = path.substring(path.length - WINDOWS_PATH_END_LENGTH); | 2423 var pathEnd = path.substring(path.length - WINDOWS_PATH_END_LENGTH); |
| 2542 path = "short${shortNameCounter}_$pathEnd"; | 2424 path = "short${shortNameCounter}_$pathEnd"; |
| 2543 } | 2425 } |
| 2544 } | 2426 } |
| 2545 return path; | 2427 return path; |
| 2546 } | 2428 } |
| 2547 } | 2429 } |
| OLD | NEW |