| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 String get buildDir => configuration.buildDirectory; | 161 String get buildDir => configuration.buildDirectory; |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * The path to the compiler for this suite's configuration. Returns `null` if | 164 * The path to the compiler for this suite's configuration. Returns `null` if |
| 165 * no compiler should be used. | 165 * no compiler should be used. |
| 166 */ | 166 */ |
| 167 String get compilerPath { | 167 String get compilerPath { |
| 168 var compilerConfiguration = configuration.compilerConfiguration; | 168 var compilerConfiguration = configuration.compilerConfiguration; |
| 169 if (!compilerConfiguration.hasCompiler) return null; | 169 if (!compilerConfiguration.hasCompiler) return null; |
| 170 var name = compilerConfiguration.computeCompilerPath(buildDir); | 170 var name = compilerConfiguration.computeCompilerPath(buildDir); |
| 171 |
| 171 // TODO(ahe): Only validate this once, in test_options.dart. | 172 // TODO(ahe): Only validate this once, in test_options.dart. |
| 172 TestUtils.ensureExists(name, configuration); | 173 TestUtils.ensureExists(name, configuration); |
| 173 return name; | 174 return name; |
| 174 } | 175 } |
| 175 | 176 |
| 176 String get pubPath { | 177 String get pubPath { |
| 177 var prefix = 'sdk/bin/'; | 178 var prefix = 'sdk/bin/'; |
| 178 if (configuration.useSdk) { | 179 if (configuration.useSdk) { |
| 179 prefix = '$buildDir/dart-sdk/bin/'; | 180 prefix = '$buildDir/dart-sdk/bin/'; |
| 180 } | 181 } |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 optionsFromFile['packages'] = packages.toNativePath(); | 799 optionsFromFile['packages'] = packages.toNativePath(); |
| 799 } | 800 } |
| 800 } | 801 } |
| 801 if (configuration.compilerConfiguration.hasCompiler && | 802 if (configuration.compilerConfiguration.hasCompiler && |
| 802 expectCompileError(info)) { | 803 expectCompileError(info)) { |
| 803 // If a compile-time error is expected, and we're testing a | 804 // If a compile-time error is expected, and we're testing a |
| 804 // compiler, we never need to attempt to run the program (in a | 805 // compiler, we never need to attempt to run the program (in a |
| 805 // browser or otherwise). | 806 // browser or otherwise). |
| 806 enqueueStandardTest(info, testName, expectations); | 807 enqueueStandardTest(info, testName, expectations); |
| 807 } else if (configuration.runtime.isBrowser) { | 808 } else if (configuration.runtime.isBrowser) { |
| 809 Map<String, Set<Expectation>> expectationsMap; |
| 810 |
| 808 if (info.optionsFromFile['isMultiHtmlTest'] as bool) { | 811 if (info.optionsFromFile['isMultiHtmlTest'] as bool) { |
| 809 // A browser multi-test has multiple expectations for one test file. | 812 // A browser multi-test has multiple expectations for one test file. |
| 810 // Find all the different sub-test expecations for one entire test file. | 813 // Find all the different sub-test expecations for one entire test file. |
| 811 var subtestNames = info.optionsFromFile['subtestNames'] as List<String>; | 814 var subtestNames = info.optionsFromFile['subtestNames'] as List<String>; |
| 812 var multiHtmlTestExpectations = <String, Set<Expectation>>{}; | 815 expectationsMap = <String, Set<Expectation>>{}; |
| 813 for (var name in subtestNames) { | 816 for (var name in subtestNames) { |
| 814 var fullTestName = '$testName/$name'; | 817 var fullTestName = '$testName/$name'; |
| 815 multiHtmlTestExpectations[fullTestName] = | 818 expectationsMap[fullTestName] = |
| 816 testExpectations.expectations(fullTestName); | 819 testExpectations.expectations(fullTestName); |
| 817 } | 820 } |
| 818 enqueueBrowserTest( | |
| 819 packageRoot, packages, info, testName, multiHtmlTestExpectations); | |
| 820 } else { | 821 } else { |
| 821 enqueueBrowserTest(packageRoot, packages, info, testName, expectations); | 822 expectationsMap = {testName: expectations}; |
| 822 } | 823 } |
| 824 |
| 825 enqueueBrowserTest( |
| 826 packageRoot, packages, info, testName, expectationsMap); |
| 823 } else { | 827 } else { |
| 824 enqueueStandardTest(info, testName, expectations); | 828 enqueueStandardTest(info, testName, expectations); |
| 825 } | 829 } |
| 826 } | 830 } |
| 827 | 831 |
| 828 void enqueueStandardTest( | 832 void enqueueStandardTest( |
| 829 TestInformation info, String testName, Set<Expectation> expectations) { | 833 TestInformation info, String testName, Set<Expectation> expectations) { |
| 830 var commonArguments = | 834 var commonArguments = |
| 831 commonArgumentsFromFile(info.filePath, info.optionsFromFile); | 835 commonArgumentsFromFile(info.filePath, info.optionsFromFile); |
| 832 | 836 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 857 | 861 |
| 858 bool isNegative(TestInformation info) { | 862 bool isNegative(TestInformation info) { |
| 859 bool negative = expectCompileError(info) || | 863 bool negative = expectCompileError(info) || |
| 860 (configuration.isChecked && info.isNegativeIfChecked); | 864 (configuration.isChecked && info.isNegativeIfChecked); |
| 861 if (info.hasRuntimeError && hasRuntime) { | 865 if (info.hasRuntimeError && hasRuntime) { |
| 862 negative = true; | 866 negative = true; |
| 863 } | 867 } |
| 864 return negative; | 868 return negative; |
| 865 } | 869 } |
| 866 | 870 |
| 867 List<Command> makeCommands(TestInformation info, int vmOptionsVarient, | 871 List<Command> makeCommands(TestInformation info, int vmOptionsVariant, |
| 868 List<String> vmOptions, List<String> args) { | 872 List<String> vmOptions, List<String> args) { |
| 869 var commands = <Command>[]; | 873 var commands = <Command>[]; |
| 870 var compilerConfiguration = configuration.compilerConfiguration; | 874 var compilerConfiguration = configuration.compilerConfiguration; |
| 871 var sharedOptions = info.optionsFromFile['sharedOptions'] as List<String>; | 875 var sharedOptions = info.optionsFromFile['sharedOptions'] as List<String>; |
| 872 | 876 |
| 873 var compileTimeArguments = <String>[]; | 877 var compileTimeArguments = <String>[]; |
| 874 String tempDir; | 878 String tempDir; |
| 875 if (compilerConfiguration.hasCompiler) { | 879 if (compilerConfiguration.hasCompiler) { |
| 876 compileTimeArguments = compilerConfiguration.computeCompilerArguments( | 880 compileTimeArguments = compilerConfiguration.computeCompilerArguments( |
| 877 vmOptions, sharedOptions, args); | 881 vmOptions, sharedOptions, args); |
| 878 // Avoid doing this for analyzer. | 882 // Avoid doing this for analyzer. |
| 879 var path = info.filePath; | 883 var path = info.filePath; |
| 880 if (vmOptionsVarient != 0) { | 884 if (vmOptionsVariant != 0) { |
| 881 // Ensure a unique directory for each test case. | 885 // Ensure a unique directory for each test case. |
| 882 path = path.join(new Path(vmOptionsVarient.toString())); | 886 path = path.join(new Path(vmOptionsVariant.toString())); |
| 883 } | 887 } |
| 884 tempDir = createCompilationOutputDirectory(path); | 888 tempDir = createCompilationOutputDirectory(path); |
| 885 | 889 |
| 886 var otherResources = | 890 var otherResources = |
| 887 info.optionsFromFile['otherResources'] as List<String>; | 891 info.optionsFromFile['otherResources'] as List<String>; |
| 888 for (var name in otherResources) { | 892 for (var name in otherResources) { |
| 889 var namePath = new Path(name); | 893 var namePath = new Path(name); |
| 890 var fromPath = info.filePath.directoryPath.join(namePath); | 894 var fromPath = info.filePath.directoryPath.join(namePath); |
| 891 new File('$tempDir/$name').parent.createSync(recursive: true); | 895 new File('$tempDir/$name').parent.createSync(recursive: true); |
| 892 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); | 896 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 * JavaScript. This function creates a working directory to hold the | 1015 * JavaScript. This function creates a working directory to hold the |
| 1012 * JavaScript version of the test, and copies the appropriate framework | 1016 * JavaScript version of the test, and copies the appropriate framework |
| 1013 * files to that directory. It creates a [BrowserTestCase], which has | 1017 * files to that directory. It creates a [BrowserTestCase], which has |
| 1014 * two sequential steps to be run by the [ProcessQueue] when the test is | 1018 * two sequential steps to be run by the [ProcessQueue] when the test is |
| 1015 * executed: a compilation step and an execution step, both with the | 1019 * executed: a compilation step and an execution step, both with the |
| 1016 * appropriate executable and arguments. The [expectations] object can be | 1020 * appropriate executable and arguments. The [expectations] object can be |
| 1017 * either a Set<String> if the test is a regular test, or a Map<String | 1021 * either a Set<String> if the test is a regular test, or a Map<String |
| 1018 * subTestName, Set<String>> if we are running a browser multi-test (one | 1022 * subTestName, Set<String>> if we are running a browser multi-test (one |
| 1019 * compilation and many browser runs). | 1023 * compilation and many browser runs). |
| 1020 */ | 1024 */ |
| 1021 void enqueueBrowserTest( | 1025 void enqueueBrowserTest(Path packageRoot, Path packages, TestInformation info, |
| 1022 Path packageRoot, | 1026 String testName, Map<String, Set<Expectation>> expectations) { |
| 1023 Path packages, | |
| 1024 TestInformation info, | |
| 1025 String testName, | |
| 1026 /* Set<Expectation> | Map<String, Set<Expectation>> */ dynamic | |
| 1027 expectations) { | |
| 1028 var badChars = new RegExp('[-=/]'); | 1027 var badChars = new RegExp('[-=/]'); |
| 1029 var vmOptionsList = getVmOptions(info.optionsFromFile); | 1028 var vmOptionsList = getVmOptions(info.optionsFromFile); |
| 1030 var multipleOptions = vmOptionsList.length > 1; | 1029 var multipleOptions = vmOptionsList.length > 1; |
| 1031 for (var vmOptions in vmOptionsList) { | 1030 for (var vmOptions in vmOptionsList) { |
| 1032 var optionsName = | 1031 var optionsName = |
| 1033 multipleOptions ? vmOptions.join('-').replaceAll(badChars, '') : ''; | 1032 multipleOptions ? vmOptions.join('-').replaceAll(badChars, '') : ''; |
| 1034 var tempDir = createOutputDirectory(info.filePath, optionsName); | 1033 var tempDir = createOutputDirectory(info.filePath, optionsName); |
| 1035 enqueueBrowserTestWithOptions(packageRoot, packages, info, testName, | 1034 enqueueBrowserTestWithOptions(packageRoot, packages, info, testName, |
| 1036 expectations, vmOptions, tempDir); | 1035 expectations, vmOptions, tempDir); |
| 1037 } | 1036 } |
| 1038 } | 1037 } |
| 1039 | 1038 |
| 1040 void enqueueBrowserTestWithOptions( | 1039 void enqueueBrowserTestWithOptions( |
| 1041 Path packageRoot, | 1040 Path packageRoot, |
| 1042 Path packages, | 1041 Path packages, |
| 1043 TestInformation info, | 1042 TestInformation info, |
| 1044 String testName, | 1043 String testName, |
| 1045 /* Set<Expectation> | Map<String, Set<Expectation>> */ expectations, | 1044 Map<String, Set<Expectation>> expectations, |
| 1046 List<String> vmOptions, | 1045 List<String> vmOptions, |
| 1047 String tempDir) { | 1046 String tempDir) { |
| 1048 // TODO(Issue 14651): If we're on dartium, we need to pass [packageRoot] | 1047 // TODO(Issue 14651): If we're on dartium, we need to pass [packageRoot] |
| 1049 // on to the browser (it may be test specific). | 1048 // on to the browser (it may be test specific). |
| 1050 | |
| 1051 var filePath = info.filePath; | 1049 var filePath = info.filePath; |
| 1052 var fileName = filePath.toString(); | 1050 var fileName = filePath.toString(); |
| 1053 | 1051 |
| 1054 var optionsFromFile = info.optionsFromFile; | 1052 var optionsFromFile = info.optionsFromFile; |
| 1055 | |
| 1056 var compilationTempDir = createCompilationOutputDirectory(info.filePath); | 1053 var compilationTempDir = createCompilationOutputDirectory(info.filePath); |
| 1057 | |
| 1058 var dartWrapperFilename = '$tempDir/test.dart'; | 1054 var dartWrapperFilename = '$tempDir/test.dart'; |
| 1059 var compiledDartWrapperFilename = '$compilationTempDir/test.js'; | 1055 var compiledDartWrapperFilename = '$compilationTempDir/test.js'; |
| 1060 | |
| 1061 String content = null; | |
| 1062 var dir = filePath.directoryPath; | 1056 var dir = filePath.directoryPath; |
| 1063 var nameNoExt = filePath.filenameWithoutExtension; | 1057 var nameNoExt = filePath.filenameWithoutExtension; |
| 1064 | |
| 1065 var customHtmlPath = dir.append('$nameNoExt.html').toNativePath(); | 1058 var customHtmlPath = dir.append('$nameNoExt.html').toNativePath(); |
| 1066 var customHtml = new File(customHtmlPath); | 1059 var customHtml = new File(customHtmlPath); |
| 1067 | 1060 |
| 1068 // Construct the command(s) that compile all the inputs needed by the | 1061 // Construct the command(s) that compile all the inputs needed by the |
| 1069 // browser test. For running Dart in DRT, this will be noop commands. | 1062 // browser test. For running Dart in DRT, this will be noop commands. |
| 1070 var commands = <Command>[]; | 1063 var commands = <Command>[]; |
| 1071 | 1064 |
| 1072 // Use existing HTML document if available. | 1065 // Use existing HTML document if available. |
| 1073 String htmlPath; | 1066 String htmlPath; |
| 1067 String content; |
| 1074 if (customHtml.existsSync()) { | 1068 if (customHtml.existsSync()) { |
| 1075 // If necessary, run the Polymer deploy steps. | 1069 // If necessary, run the Polymer deploy steps. |
| 1076 // TODO(jmesserly): this should be generalized for any tests that | 1070 // TODO(jmesserly): this should be generalized for any tests that |
| 1077 // require Pub deploy, not just polymer. | 1071 // require Pub deploy, not just polymer. |
| 1072 // TODO(rnystrom): This does not appear to be used any more. Remove. |
| 1078 if (customHtml.readAsStringSync().contains('<!--polymer-test')) { | 1073 if (customHtml.readAsStringSync().contains('<!--polymer-test')) { |
| 1079 if (configuration.compiler != Compiler.none) { | 1074 if (configuration.compiler != Compiler.none) { |
| 1080 commands.add( | 1075 commands.add( |
| 1081 _polymerDeployCommand(customHtmlPath, tempDir, optionsFromFile)); | 1076 _polymerDeployCommand(customHtmlPath, tempDir, optionsFromFile)); |
| 1082 | 1077 |
| 1083 Path pubspecYamlFile = _findPubspecYamlFile(filePath); | 1078 Path pubspecYamlFile = _findPubspecYamlFile(filePath); |
| 1084 Path homeDir = | 1079 Path homeDir = |
| 1085 (pubspecYamlFile == null) ? dir : pubspecYamlFile.directoryPath; | 1080 (pubspecYamlFile == null) ? dir : pubspecYamlFile.directoryPath; |
| 1086 htmlPath = '$tempDir/${dir.relativeTo(homeDir)}/$nameNoExt.html'; | 1081 htmlPath = '$tempDir/${dir.relativeTo(homeDir)}/$nameNoExt.html'; |
| 1087 dartWrapperFilename = '${htmlPath}_bootstrap.dart'; | 1082 dartWrapperFilename = '${htmlPath}_bootstrap.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1106 } else { | 1101 } else { |
| 1107 compiledDartWrapperFilename = '$tempDir/$nameNoExt.js'; | 1102 compiledDartWrapperFilename = '$tempDir/$nameNoExt.js'; |
| 1108 var jsUrl = '$nameNoExt.js'; | 1103 var jsUrl = '$nameNoExt.js'; |
| 1109 htmlContents = htmlContents.replaceAll( | 1104 htmlContents = htmlContents.replaceAll( |
| 1110 '%TEST_SCRIPTS%', '<script src="$jsUrl"></script>'); | 1105 '%TEST_SCRIPTS%', '<script src="$jsUrl"></script>'); |
| 1111 } | 1106 } |
| 1112 new File(htmlPath).writeAsStringSync(htmlContents); | 1107 new File(htmlPath).writeAsStringSync(htmlContents); |
| 1113 } | 1108 } |
| 1114 } else { | 1109 } else { |
| 1115 htmlPath = '$tempDir/test.html'; | 1110 htmlPath = '$tempDir/test.html'; |
| 1116 if (configuration.compiler != Compiler.dart2js) { | 1111 if (configuration.compiler != Compiler.dart2js && |
| 1112 configuration.compiler != Compiler.dartdevc) { |
| 1117 // test.dart will import the dart test. | 1113 // test.dart will import the dart test. |
| 1118 _createWrapperFile(dartWrapperFilename, filePath); | 1114 _createWrapperFile(dartWrapperFilename, filePath); |
| 1119 } else { | 1115 } else { |
| 1120 dartWrapperFilename = fileName; | 1116 dartWrapperFilename = fileName; |
| 1121 } | 1117 } |
| 1122 | 1118 |
| 1123 // Create the HTML file for the test. | 1119 // Create the HTML file for the test. |
| 1124 var htmlTest = new File(htmlPath).openSync(mode: FileMode.WRITE); | 1120 var htmlTest = new File(htmlPath).openSync(mode: FileMode.WRITE); |
| 1125 | 1121 |
| 1126 var scriptPath = dartWrapperFilename; | 1122 var scriptPath = dartWrapperFilename; |
| 1127 if (configuration.compiler != Compiler.none) { | 1123 if (configuration.compiler != Compiler.none) { |
| 1128 scriptPath = compiledDartWrapperFilename; | 1124 scriptPath = compiledDartWrapperFilename; |
| 1129 } | 1125 } |
| 1130 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); | 1126 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); |
| 1131 | 1127 |
| 1132 content = getHtmlContents(fileName, scriptType, new Path("$scriptPath")); | 1128 if (configuration.compiler == Compiler.dart2js) { |
| 1129 content = getHtmlContents(fileName, scriptType, scriptPath); |
| 1130 } else { |
| 1131 var jsDir = new Path(compilationTempDir) |
| 1132 .relativeTo(TestUtils.dartDir) |
| 1133 .toString(); |
| 1134 content = dartdevcHtml(nameNoExt, jsDir); |
| 1135 } |
| 1136 |
| 1133 htmlTest.writeStringSync(content); | 1137 htmlTest.writeStringSync(content); |
| 1134 htmlTest.closeSync(); | 1138 htmlTest.closeSync(); |
| 1135 } | 1139 } |
| 1136 | 1140 |
| 1137 if (configuration.compiler != Compiler.none) { | 1141 switch (configuration.compiler) { |
| 1138 assert(configuration.compiler == Compiler.dart2js); | 1142 case Compiler.dart2js: |
| 1143 commands.add(_dart2jsCompileCommand(dartWrapperFilename, |
| 1144 compiledDartWrapperFilename, tempDir, optionsFromFile)); |
| 1145 break; |
| 1139 | 1146 |
| 1140 commands.add(_compileCommand(dartWrapperFilename, | 1147 case Compiler.dartdevc: |
| 1141 compiledDartWrapperFilename, tempDir, optionsFromFile)); | 1148 commands.add(_dartdevcCompileCommand(dartWrapperFilename, |
| 1149 '$compilationTempDir/$nameNoExt.js', optionsFromFile)); |
| 1150 break; |
| 1151 |
| 1152 default: |
| 1153 assert(false); |
| 1142 } | 1154 } |
| 1143 | 1155 |
| 1144 // some tests require compiling multiple input scripts. | 1156 // Some tests require compiling multiple input scripts. |
| 1145 var otherScripts = optionsFromFile['otherScripts'] as List<String>; | 1157 var otherScripts = optionsFromFile['otherScripts'] as List<String>; |
| 1146 for (var name in otherScripts) { | 1158 for (var name in otherScripts) { |
| 1147 var namePath = new Path(name); | 1159 var namePath = new Path(name); |
| 1148 var fromPath = filePath.directoryPath.join(namePath); | 1160 var fromPath = filePath.directoryPath.join(namePath); |
| 1149 | 1161 |
| 1150 if (configuration.compiler != Compiler.none) { | 1162 switch (configuration.compiler) { |
| 1151 assert(configuration.compiler == Compiler.dart2js); | 1163 case Compiler.dart2js: |
| 1152 assert(namePath.extension == 'dart'); | 1164 commands.add(_dart2jsCompileCommand(fromPath.toNativePath(), |
| 1165 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); |
| 1166 break; |
| 1153 | 1167 |
| 1154 commands.add(_compileCommand(fromPath.toNativePath(), | 1168 case Compiler.dartdevc: |
| 1155 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); | 1169 commands.add(_dartdevcCompileCommand(fromPath.toNativePath(), |
| 1170 '$tempDir/$nameNoExt.js', optionsFromFile)); |
| 1171 break; |
| 1172 |
| 1173 default: |
| 1174 assert(configuration.compiler == Compiler.none); |
| 1156 } | 1175 } |
| 1157 | 1176 |
| 1158 if (configuration.compiler == Compiler.none) { | 1177 if (configuration.compiler == Compiler.none) { |
| 1159 // For the tests that require multiple input scripts but are not | 1178 // For the tests that require multiple input scripts but are not |
| 1160 // compiled, move the input scripts over with the script so they can | 1179 // compiled, move the input scripts over with the script so they can |
| 1161 // be accessed. | 1180 // be accessed. |
| 1162 var result = new File(fromPath.toNativePath()).readAsStringSync(); | 1181 var result = new File(fromPath.toNativePath()).readAsStringSync(); |
| 1163 new File('$tempDir/${namePath.filename}').writeAsStringSync(result); | 1182 new File('$tempDir/${namePath.filename}').writeAsStringSync(result); |
| 1164 } | 1183 } |
| 1165 } | 1184 } |
| 1166 | 1185 |
| 1167 // Variables for browser multi-tests. | 1186 // Variables for browser multi-tests. |
| 1168 var multitest = info.optionsFromFile['isMultiHtmlTest'] as bool; | 1187 var isMultitest = info.optionsFromFile['isMultiHtmlTest'] as bool; |
| 1169 var subtestNames = multitest | 1188 var subtestNames = isMultitest |
| 1170 ? (info.optionsFromFile['subtestNames'] as List<String>) | 1189 ? (info.optionsFromFile['subtestNames'] as List<String>) |
| 1171 : <String>[null]; | 1190 : <String>[null]; |
| 1172 for (var subtestName in subtestNames) { | 1191 for (var subtestName in subtestNames) { |
| 1173 // Construct the command that executes the browser test | 1192 // Construct the command that executes the browser test |
| 1174 var commandSet = commands.toList(); | 1193 var commandSet = commands.toList(); |
| 1175 | 1194 |
| 1176 var htmlPath_subtest = _createUrlPathFromFile(new Path(htmlPath)); | 1195 var htmlPath_subtest = _createUrlPathFromFile(new Path(htmlPath)); |
| 1177 var fullHtmlPath = | 1196 var fullHtmlPath = |
| 1178 _getUriForBrowserTest(htmlPath_subtest, subtestName).toString(); | 1197 _getUriForBrowserTest(htmlPath_subtest, subtestName).toString(); |
| 1179 | 1198 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1202 } | 1221 } |
| 1203 | 1222 |
| 1204 commandSet.add(Command.contentShell(contentShellFilename, fullHtmlPath, | 1223 commandSet.add(Command.contentShell(contentShellFilename, fullHtmlPath, |
| 1205 contentShellOptions, dartFlags, environmentOverrides)); | 1224 contentShellOptions, dartFlags, environmentOverrides)); |
| 1206 } else { | 1225 } else { |
| 1207 commandSet.add(Command.browserTest(fullHtmlPath, configuration, | 1226 commandSet.add(Command.browserTest(fullHtmlPath, configuration, |
| 1208 retry: !isNegative(info))); | 1227 retry: !isNegative(info))); |
| 1209 } | 1228 } |
| 1210 | 1229 |
| 1211 // Create BrowserTestCase and queue it. | 1230 // Create BrowserTestCase and queue it. |
| 1212 var fullTestName = multitest ? '$testName/$subtestName' : testName; | 1231 var fullTestName = isMultitest ? '$testName/$subtestName' : testName; |
| 1213 var expectation = (multitest ? expectations[fullTestName] : expectations) | 1232 var expectation = expectations[fullTestName]; |
| 1214 as Set<Expectation>; | |
| 1215 var testCase = new BrowserTestCase('$suiteName/$fullTestName', commandSet, | 1233 var testCase = new BrowserTestCase('$suiteName/$fullTestName', commandSet, |
| 1216 configuration, expectation, info, isNegative(info), fullHtmlPath); | 1234 configuration, expectation, info, isNegative(info), fullHtmlPath); |
| 1217 | 1235 |
| 1218 enqueueNewTestCase(testCase); | 1236 enqueueNewTestCase(testCase); |
| 1219 } | 1237 } |
| 1220 } | 1238 } |
| 1221 | 1239 |
| 1222 void enqueueHtmlTest(HtmlTestInformation info, String testName, | 1240 void enqueueHtmlTest(HtmlTestInformation info, String testName, |
| 1223 Set<Expectation> expectations) { | 1241 Set<Expectation> expectations) { |
| 1224 var compiler = configuration.compiler; | 1242 var compiler = configuration.compiler; |
| 1225 var runtime = configuration.runtime; | 1243 var runtime = configuration.runtime; |
| 1226 | 1244 |
| 1245 if (compiler == Compiler.dartdevc) { |
| 1246 // TODO(rnystrom): Support this for dartdevc (#29919). |
| 1247 print("Ignoring $testName on dartdevc since HTML tests are not " |
| 1248 "implemented for that compiler yet."); |
| 1249 return; |
| 1250 } |
| 1251 |
| 1227 // HTML tests work only with the browser controller. | 1252 // HTML tests work only with the browser controller. |
| 1228 if (!runtime.isBrowser || runtime == Runtime.drt) return; | 1253 if (!runtime.isBrowser || runtime == Runtime.drt) return; |
| 1229 | 1254 |
| 1230 var compileToJS = compiler == Compiler.dart2js; | 1255 var compileToJS = compiler == Compiler.dart2js; |
| 1231 | 1256 |
| 1232 var filePath = info.filePath; | 1257 var filePath = info.filePath; |
| 1233 var tempDir = createOutputDirectory(filePath, ''); | 1258 var tempDir = createOutputDirectory(filePath, ''); |
| 1234 var tempUri = new Uri.file('$tempDir/'); | 1259 var tempUri = new Uri.file('$tempDir/'); |
| 1235 var contents = html_test.getContents(info, compileToJS); | 1260 var contents = html_test.getContents(info, compileToJS); |
| 1236 var commands = <Command>[]; | 1261 var commands = <Command>[]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1266 new File.fromUri(copiedScript) | 1291 new File.fromUri(copiedScript) |
| 1267 .writeAsStringSync(new File.fromUri(script).readAsStringSync()); | 1292 .writeAsStringSync(new File.fromUri(script).readAsStringSync()); |
| 1268 } else { | 1293 } else { |
| 1269 var destination = copiedScript.toFilePath(); | 1294 var destination = copiedScript.toFilePath(); |
| 1270 if (compileToJS) { | 1295 if (compileToJS) { |
| 1271 destination = destination.replaceFirst(dartExtension, '.js'); | 1296 destination = destination.replaceFirst(dartExtension, '.js'); |
| 1272 } | 1297 } |
| 1273 | 1298 |
| 1274 assert(compiler == Compiler.dart2js); | 1299 assert(compiler == Compiler.dart2js); |
| 1275 | 1300 |
| 1276 commands.add(_compileCommand( | 1301 commands.add(_dart2jsCompileCommand( |
| 1277 script.toFilePath(), destination, tempDir, info.optionsFromFile)); | 1302 script.toFilePath(), destination, tempDir, info.optionsFromFile)); |
| 1278 } | 1303 } |
| 1279 } | 1304 } |
| 1280 } | 1305 } |
| 1281 | 1306 |
| 1282 var htmlFile = tempUri.resolve(filePath.filename); | 1307 var htmlFile = tempUri.resolve(filePath.filename); |
| 1283 new File.fromUri(htmlFile).writeAsStringSync(contents); | 1308 new File.fromUri(htmlFile).writeAsStringSync(contents); |
| 1284 | 1309 |
| 1285 var htmlPath = _createUrlPathFromFile(new Path(htmlFile.toFilePath())); | 1310 var htmlPath = _createUrlPathFromFile(new Path(htmlFile.toFilePath())); |
| 1286 var fullHtmlPath = _getUriForBrowserTest(htmlPath, null).toString(); | 1311 var fullHtmlPath = _getUriForBrowserTest(htmlPath, null).toString(); |
| 1287 commands.add(Command.browserHtmlTest( | 1312 commands.add(Command.browserHtmlTest( |
| 1288 fullHtmlPath, configuration, info.expectedMessages, | 1313 fullHtmlPath, configuration, info.expectedMessages, |
| 1289 retry: !isNegative(info))); | 1314 retry: !isNegative(info))); |
| 1290 var testDisplayName = '$suiteName/$testName'; | 1315 var testDisplayName = '$suiteName/$testName'; |
| 1291 var testCase = new BrowserTestCase(testDisplayName, commands, configuration, | 1316 var testCase = new BrowserTestCase(testDisplayName, commands, configuration, |
| 1292 expectations, info, isNegative(info), fullHtmlPath); | 1317 expectations, info, isNegative(info), fullHtmlPath); |
| 1293 enqueueNewTestCase(testCase); | 1318 enqueueNewTestCase(testCase); |
| 1294 } | 1319 } |
| 1295 | 1320 |
| 1296 /** Helper to create a compilation command for a single input file. */ | 1321 /// Creates a [Command] to compile a single .dart file using dart2js. |
| 1297 Command _compileCommand(String inputFile, String outputFile, String dir, | 1322 Command _dart2jsCompileCommand(String inputFile, String outputFile, |
| 1298 Map<String, dynamic> optionsFromFile) { | 1323 String dir, Map<String, dynamic> optionsFromFile) { |
| 1299 var args = <String>[]; | 1324 var args = <String>[]; |
| 1300 | 1325 |
| 1301 if (compilerPath.endsWith('.dart')) { | 1326 if (compilerPath.endsWith('.dart')) { |
| 1302 // Run the compiler script via the Dart VM. | 1327 // Run the compiler script via the Dart VM. |
| 1303 args.add(compilerPath); | 1328 args.add(compilerPath); |
| 1304 } | 1329 } |
| 1305 | 1330 |
| 1306 args.addAll(configuration.standardOptions); | 1331 args.addAll(configuration.standardOptions); |
| 1307 | 1332 |
| 1308 var packages = packagesArgument(optionsFromFile['packageRoot'] as String, | 1333 var packages = packagesArgument(optionsFromFile['packageRoot'] as String, |
| 1309 optionsFromFile['packages'] as String); | 1334 optionsFromFile['packages'] as String); |
| 1310 if (packages != null) args.add(packages); | 1335 if (packages != null) args.add(packages); |
| 1311 | 1336 |
| 1312 args.add('--out=$outputFile'); | 1337 args.add('--out=$outputFile'); |
| 1313 args.add(inputFile); | 1338 args.add(inputFile); |
| 1314 | 1339 |
| 1315 var options = optionsFromFile['sharedOptions'] as List<String>; | 1340 var options = optionsFromFile['sharedOptions'] as List<String>; |
| 1316 if (options != null) args.addAll(options); | 1341 if (options != null) args.addAll(options); |
| 1317 | 1342 |
| 1318 return Command.compilation(Compiler.dart2js.name, outputFile, !useSdk, | 1343 return Command.compilation(Compiler.dart2js.name, outputFile, |
| 1319 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides); | 1344 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides, |
| 1345 alwaysCompile: !useSdk); |
| 1346 } |
| 1347 |
| 1348 /// Creates a [Command] to compile a single .dart file using dartdevc. |
| 1349 Command _dartdevcCompileCommand(String inputFile, String outputFile, |
| 1350 Map<String, dynamic> optionsFromFile) { |
| 1351 var args = [ |
| 1352 "--dart-sdk", |
| 1353 "$buildDir/dart-sdk", |
| 1354 "--library-root", |
| 1355 new Path(inputFile).directoryPath.toString(), |
| 1356 "-o", |
| 1357 outputFile, |
| 1358 inputFile |
| 1359 ]; |
| 1360 |
| 1361 // TODO(29923): This compiles everything imported by the test into the |
| 1362 // same generated JS module, including other packages like expect, |
| 1363 // stack_trace, etc. Those should be compiled as separate JS modules (by |
| 1364 // build.py) and loaded dynamically by the test. |
| 1365 |
| 1366 return Command.compilation( |
| 1367 Compiler.dartdevc.name, |
| 1368 outputFile, |
| 1369 configuration.compilerConfiguration.bootstrapDependencies(buildDir), |
| 1370 compilerPath, |
| 1371 args, |
| 1372 environmentOverrides); |
| 1320 } | 1373 } |
| 1321 | 1374 |
| 1322 /** Helper to create a Polymer deploy command for a single HTML file. */ | 1375 /** Helper to create a Polymer deploy command for a single HTML file. */ |
| 1323 Command _polymerDeployCommand(String inputFile, String outputDir, | 1376 Command _polymerDeployCommand(String inputFile, String outputDir, |
| 1324 Map<String, dynamic> optionsFromFile) { | 1377 Map<String, dynamic> optionsFromFile) { |
| 1325 var args = <String>[]; | 1378 var args = <String>[]; |
| 1326 var packages = packagesArgument(optionsFromFile['packageRoot'] as String, | 1379 var packages = packagesArgument(optionsFromFile['packageRoot'] as String, |
| 1327 optionsFromFile['packages'] as String); | 1380 optionsFromFile['packages'] as String); |
| 1328 if (packages != null) args.add(packages); | 1381 if (packages != null) args.add(packages); |
| 1329 args | 1382 args |
| 1330 ..add('package:polymer/deploy.dart') | 1383 ..add('package:polymer/deploy.dart') |
| 1331 ..add('--test') | 1384 ..add('--test') |
| 1332 ..add(inputFile) | 1385 ..add(inputFile) |
| 1333 ..add('--out') | 1386 ..add('--out') |
| 1334 ..add(outputDir) | 1387 ..add(outputDir) |
| 1335 ..add('--file-filter') | 1388 ..add('--file-filter') |
| 1336 ..add('.svn'); | 1389 ..add('.svn'); |
| 1337 if (configuration.isCsp) args.add('--csp'); | 1390 if (configuration.isCsp) args.add('--csp'); |
| 1338 | 1391 |
| 1339 return Command.process( | 1392 return Command.process( |
| 1340 'polymer_deploy', dartVmBinaryFileName, args, environmentOverrides); | 1393 'polymer_deploy', dartVmBinaryFileName, args, environmentOverrides); |
| 1341 } | 1394 } |
| 1342 | 1395 |
| 1343 String get scriptType { | 1396 String get scriptType { |
| 1344 switch (configuration.compiler) { | 1397 switch (configuration.compiler) { |
| 1345 case Compiler.none: | 1398 case Compiler.none: |
| 1346 return 'application/dart'; | 1399 return 'application/dart'; |
| 1347 case Compiler.dart2js: | 1400 case Compiler.dart2js: |
| 1348 case Compiler.dart2analyzer: | 1401 case Compiler.dart2analyzer: |
| 1402 case Compiler.dartdevc: |
| 1349 return 'text/javascript'; | 1403 return 'text/javascript'; |
| 1350 default: | 1404 default: |
| 1351 print('Non-web runtime, so no scriptType for: ' | 1405 print('Non-web runtime, so no scriptType for: ' |
| 1352 '${configuration.compiler.name}'); | 1406 '${configuration.compiler.name}'); |
| 1353 exit(1); | 1407 exit(1); |
| 1354 return null; | 1408 return null; |
| 1355 } | 1409 } |
| 1356 } | 1410 } |
| 1357 | 1411 |
| 1358 bool get hasRuntime => configuration.runtime != Runtime.none; | 1412 bool get hasRuntime => configuration.runtime != Runtime.none; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 | 1747 |
| 1694 /// Used for testing packages in on off settings, i.e., we pass in the actual | 1748 /// Used for testing packages in on off settings, i.e., we pass in the actual |
| 1695 /// directory that we want to test. | 1749 /// directory that we want to test. |
| 1696 class PKGTestSuite extends StandardTestSuite { | 1750 class PKGTestSuite extends StandardTestSuite { |
| 1697 PKGTestSuite(Configuration configuration, Path directoryPath) | 1751 PKGTestSuite(Configuration configuration, Path directoryPath) |
| 1698 : super(configuration, directoryPath.filename, directoryPath, | 1752 : super(configuration, directoryPath.filename, directoryPath, |
| 1699 ["$directoryPath/.status"], | 1753 ["$directoryPath/.status"], |
| 1700 isTestFilePredicate: (f) => f.endsWith('_test.dart'), | 1754 isTestFilePredicate: (f) => f.endsWith('_test.dart'), |
| 1701 recursive: true); | 1755 recursive: true); |
| 1702 | 1756 |
| 1703 void enqueueBrowserTest( | 1757 void enqueueBrowserTest(Path packageRoot, packages, TestInformation info, |
| 1704 Path packageRoot, | 1758 String testName, Map<String, Set<Expectation>> expectations) { |
| 1705 packages, | |
| 1706 TestInformation info, | |
| 1707 String testName, | |
| 1708 /* Set<Expectation> | Map<String, Set<Expectation>> */ dynamic | |
| 1709 expectations) { | |
| 1710 var filePath = info.filePath; | 1759 var filePath = info.filePath; |
| 1711 var dir = filePath.directoryPath; | 1760 var dir = filePath.directoryPath; |
| 1712 var nameNoExt = filePath.filenameWithoutExtension; | 1761 var nameNoExt = filePath.filenameWithoutExtension; |
| 1713 var customHtmlPath = dir.append('$nameNoExt.html'); | 1762 var customHtmlPath = dir.append('$nameNoExt.html'); |
| 1714 var customHtml = new File(customHtmlPath.toNativePath()); | 1763 var customHtml = new File(customHtmlPath.toNativePath()); |
| 1715 if (!customHtml.existsSync()) { | 1764 if (!customHtml.existsSync()) { |
| 1716 super.enqueueBrowserTest( | 1765 super.enqueueBrowserTest( |
| 1717 packageRoot, packages, info, testName, expectations); | 1766 packageRoot, packages, info, testName, expectations); |
| 1718 } else { | 1767 } else { |
| 1719 var relativeHtml = customHtmlPath.relativeTo(TestUtils.dartDir); | 1768 var relativeHtml = customHtmlPath.relativeTo(TestUtils.dartDir); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 | 1833 |
| 1785 bool isTestFile(String filename) { | 1834 bool isTestFile(String filename) { |
| 1786 // NOTE: We exclude tests and patch files for now. | 1835 // NOTE: We exclude tests and patch files for now. |
| 1787 return filename.endsWith(".dart") && | 1836 return filename.endsWith(".dart") && |
| 1788 !filename.endsWith("_test.dart") && | 1837 !filename.endsWith("_test.dart") && |
| 1789 !filename.contains("_internal/js_runtime/lib"); | 1838 !filename.contains("_internal/js_runtime/lib"); |
| 1790 } | 1839 } |
| 1791 | 1840 |
| 1792 bool get listRecursively => true; | 1841 bool get listRecursively => true; |
| 1793 } | 1842 } |
| OLD | NEW |