| 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 if (getVmOptions(optionsFromFile).length > 1) { | 941 if (getVmOptions(optionsFromFile).length > 1) { |
| 942 optionsName = vmOptions.join('-').replaceAll('-','') | 942 optionsName = vmOptions.join('-').replaceAll('-','') |
| 943 .replaceAll('=','') | 943 .replaceAll('=','') |
| 944 .replaceAll('/',''); | 944 .replaceAll('/',''); |
| 945 } | 945 } |
| 946 final String tempDir = createOutputDirectory(info.filePath, optionsName); | 946 final String tempDir = createOutputDirectory(info.filePath, optionsName); |
| 947 | 947 |
| 948 String dartWrapperFilename = '$tempDir/test.dart'; | 948 String dartWrapperFilename = '$tempDir/test.dart'; |
| 949 String compiledDartWrapperFilename = '$tempDir/test.js'; | 949 String compiledDartWrapperFilename = '$tempDir/test.js'; |
| 950 | 950 |
| 951 String htmlPath = '$tempDir/test.html'; | |
| 952 if (isWrappingRequired && !isWebTest) { | |
| 953 // test.dart will import the dart test. | |
| 954 _createWrapperFile(dartWrapperFilename, filePath); | |
| 955 } else { | |
| 956 dartWrapperFilename = filename; | |
| 957 } | |
| 958 String scriptPath = (compiler == 'none') ? | |
| 959 dartWrapperFilename : compiledDartWrapperFilename; | |
| 960 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); | |
| 961 | |
| 962 // Create the HTML file for the test. | |
| 963 RandomAccessFile htmlTest = | |
| 964 new File(htmlPath).openSync(mode: FileMode.WRITE); | |
| 965 String content = null; | 951 String content = null; |
| 966 Path dir = filePath.directoryPath; | 952 Path dir = filePath.directoryPath; |
| 967 String nameNoExt = filePath.filenameWithoutExtension; | 953 String nameNoExt = filePath.filenameWithoutExtension; |
| 968 | 954 |
| 969 Path pngPath = dir.append('$nameNoExt.png'); | 955 Path pngPath = dir.append('$nameNoExt.png'); |
| 970 Path txtPath = dir.append('$nameNoExt.txt'); | 956 Path txtPath = dir.append('$nameNoExt.txt'); |
| 971 Path customHtmlPath = dir.append('$nameNoExt.html'); | 957 String customHtmlPath = dir.append('$nameNoExt.html').toNativePath(); |
| 958 File customHtml = new File(customHtmlPath); |
| 972 Path expectedOutput = null; | 959 Path expectedOutput = null; |
| 973 | 960 |
| 974 if (new File(customHtmlPath.toNativePath()).existsSync()) { | 961 // Construct the command(s) that compile all the inputs needed by the |
| 975 // Use existing HTML document if available. | 962 // browser test. For running Dart in DRT, this will be noop commands. |
| 976 htmlPath = customHtmlPath.toNativePath(); | 963 List<Command> commands = []; |
| 964 |
| 965 // Use existing HTML document if available. |
| 966 String htmlPath; |
| 967 if (customHtml.existsSync()) { |
| 968 |
| 969 // If necessary, run the Polymer deploy steps. |
| 970 // TODO(jmesserly): this should be generalized for any tests that |
| 971 // require Pub deploy, not just polymer. |
| 972 if (compiler != 'none' && |
| 973 customHtml.readAsStringSync().contains('polymer/boot.js')) { |
| 974 |
| 975 commands.add(_polymerDeployCommand( |
| 976 customHtmlPath, tempDir, optionsFromFile)); |
| 977 |
| 978 htmlPath = '$tempDir/test/$nameNoExt.html'; |
| 979 dartWrapperFilename = '${htmlPath}_bootstrap.dart'; |
| 980 compiledDartWrapperFilename = '$dartWrapperFilename.js'; |
| 981 } else { |
| 982 htmlPath = customHtmlPath; |
| 983 } |
| 977 } else { | 984 } else { |
| 985 htmlPath = '$tempDir/test.html'; |
| 986 if (isWrappingRequired && !isWebTest) { |
| 987 // test.dart will import the dart test. |
| 988 _createWrapperFile(dartWrapperFilename, filePath); |
| 989 } else { |
| 990 dartWrapperFilename = filename; |
| 991 } |
| 992 |
| 993 // Create the HTML file for the test. |
| 994 RandomAccessFile htmlTest = |
| 995 new File(htmlPath).openSync(mode: FileMode.WRITE); |
| 996 |
| 997 String scriptPath = (compiler == 'none') ? |
| 998 dartWrapperFilename : compiledDartWrapperFilename; |
| 999 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); |
| 1000 |
| 978 if (new File(pngPath.toNativePath()).existsSync()) { | 1001 if (new File(pngPath.toNativePath()).existsSync()) { |
| 979 expectedOutput = pngPath; | 1002 expectedOutput = pngPath; |
| 980 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); | 1003 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| 981 } else if (new File(txtPath.toNativePath()).existsSync()) { | 1004 } else if (new File(txtPath.toNativePath()).existsSync()) { |
| 982 expectedOutput = txtPath; | 1005 expectedOutput = txtPath; |
| 983 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); | 1006 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| 984 } else { | 1007 } else { |
| 985 content = getHtmlContents(filename, scriptType, | 1008 content = getHtmlContents(filename, scriptType, |
| 986 new Path("$scriptPath")); | 1009 new Path("$scriptPath")); |
| 987 } | 1010 } |
| 988 htmlTest.writeStringSync(content); | 1011 htmlTest.writeStringSync(content); |
| 989 htmlTest.closeSync(); | 1012 htmlTest.closeSync(); |
| 990 } | 1013 } |
| 991 | 1014 |
| 992 // Construct the command(s) that compile all the inputs needed by the | |
| 993 // browser test. For running Dart in DRT, this will be noop commands. | |
| 994 List<Command> commands = []; | |
| 995 if (compiler != 'none') { | 1015 if (compiler != 'none') { |
| 996 commands.add(_compileCommand( | 1016 commands.add(_compileCommand( |
| 997 dartWrapperFilename, compiledDartWrapperFilename, | 1017 dartWrapperFilename, compiledDartWrapperFilename, |
| 998 compiler, tempDir, vmOptions, optionsFromFile)); | 1018 compiler, tempDir, vmOptions, optionsFromFile)); |
| 999 } | 1019 } |
| 1000 | 1020 |
| 1001 // some tests require compiling multiple input scripts. | 1021 // some tests require compiling multiple input scripts. |
| 1002 List<String> otherScripts = optionsFromFile['otherScripts']; | 1022 List<String> otherScripts = optionsFromFile['otherScripts']; |
| 1003 for (String name in otherScripts) { | 1023 for (String name in otherScripts) { |
| 1004 Path namePath = new Path(name); | 1024 Path namePath = new Path(name); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 if (executable.endsWith('.dart')) { | 1144 if (executable.endsWith('.dart')) { |
| 1125 // Run the compiler script via the Dart VM. | 1145 // Run the compiler script via the Dart VM. |
| 1126 args.insert(0, executable); | 1146 args.insert(0, executable); |
| 1127 executable = dartShellFileName; | 1147 executable = dartShellFileName; |
| 1128 } | 1148 } |
| 1129 return CommandBuilder.instance.getCompilationCommand( | 1149 return CommandBuilder.instance.getCompilationCommand( |
| 1130 compiler, outputFile, !useSdk, | 1150 compiler, outputFile, !useSdk, |
| 1131 dart2JsBootstrapDependencies, compilerPath, args, configurationDir); | 1151 dart2JsBootstrapDependencies, compilerPath, args, configurationDir); |
| 1132 } | 1152 } |
| 1133 | 1153 |
| 1154 /** Helper to create a Polymer deploy command for a single HTML file. */ |
| 1155 Command _polymerDeployCommand(String inputFile, String outputDir, |
| 1156 optionsFromFile) { |
| 1157 List<String> args = []; |
| 1158 String packageRoot = packageRootArgument(optionsFromFile['packageRoot']); |
| 1159 if (packageRoot != null) args.add(packageRoot); |
| 1160 args..add('package:polymer/deploy.dart') |
| 1161 ..add('--test')..add(inputFile) |
| 1162 ..add('--out')..add(outputDir); |
| 1163 |
| 1164 return CommandBuilder.instance.getCommand( |
| 1165 'polymer_deploy', vmFileName, args, configurationDir); |
| 1166 } |
| 1167 |
| 1134 /** | 1168 /** |
| 1135 * Create a directory for the generated test. If a Dart language test | 1169 * Create a directory for the generated test. If a Dart language test |
| 1136 * needs to be run in a browser, the Dart test needs to be embedded in | 1170 * needs to be run in a browser, the Dart test needs to be embedded in |
| 1137 * an HTML page, with a testing framework based on scripting and DOM events. | 1171 * an HTML page, with a testing framework based on scripting and DOM events. |
| 1138 * These scripts and pages are written to a generated_test directory | 1172 * These scripts and pages are written to a generated_test directory |
| 1139 * inside the build directory of the checkout. | 1173 * inside the build directory of the checkout. |
| 1140 * | 1174 * |
| 1141 * Those tests which are already HTML web applications (web tests), with | 1175 * Those tests which are already HTML web applications (web tests), with |
| 1142 * resources including CSS files and HTML files, need to be compiled into | 1176 * resources including CSS files and HTML files, need to be compiled into |
| 1143 * a work directory where the relative URLS to the resources work. | 1177 * a work directory where the relative URLS to the resources work. |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 * $pass tests are expected to pass | 2006 * $pass tests are expected to pass |
| 1973 * $failOk tests are expected to fail that we won't fix | 2007 * $failOk tests are expected to fail that we won't fix |
| 1974 * $fail tests are expected to fail that we should fix | 2008 * $fail tests are expected to fail that we should fix |
| 1975 * $crash tests are expected to crash that we should fix | 2009 * $crash tests are expected to crash that we should fix |
| 1976 * $timeout tests are allowed to timeout | 2010 * $timeout tests are allowed to timeout |
| 1977 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 2011 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 1978 """; | 2012 """; |
| 1979 print(report); | 2013 print(report); |
| 1980 } | 2014 } |
| 1981 } | 2015 } |
| OLD | NEW |