Chromium Code Reviews| 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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 hasCompileError, | 805 hasCompileError, |
| 806 hasRuntimeError, | 806 hasRuntimeError, |
| 807 isNegativeIfChecked, | 807 isNegativeIfChecked, |
| 808 hasFatalTypeErrors, | 808 hasFatalTypeErrors, |
| 809 multitestOutcome); | 809 multitestOutcome); |
| 810 cachedTests.add(info); | 810 cachedTests.add(info); |
| 811 enqueueTestCaseFromTestInformation(info); | 811 enqueueTestCaseFromTestInformation(info); |
| 812 }; | 812 }; |
| 813 } | 813 } |
| 814 | 814 |
| 815 | |
| 816 /** | |
| 817 * _createUrlPathFromFile takes a [file], which is either located in the dart | |
| 818 * or in the build directory, and will return a String representing | |
| 819 * the relative path to either the dart or the build directory. | |
| 820 * Thus, the returned [String] will be the path component of the URL | |
| 821 * corresponding to [file] (the http server serves files relative to the | |
| 822 * dart/build directories). | |
| 823 */ | |
| 824 String _createUrlPathFromFile(Path file) { | |
| 825 file = TestUtils.absolutePath(file); | |
| 826 var fileString = file.toString(); | |
| 827 | |
| 828 var relativeBuildDir = TestUtils.buildDir(configuration); | |
| 829 var buildDir = TestUtils.absolutePath(new Path(relativeBuildDir)); | |
| 830 var dartDir = TestUtils.dartDir(); | |
| 831 | |
| 832 var pathComponent; | |
| 833 if (fileString.startsWith(buildDir.toString())) { | |
| 834 var fileRelativeToBuildDir = file.relativeTo(buildDir); | |
| 835 pathComponent = "$relativeBuildDir/$fileRelativeToBuildDir"; | |
| 836 } else if (fileString.startsWith(dartDir.toString())) { | |
| 837 pathComponent = file.relativeTo(dartDir); | |
| 838 } else { | |
| 839 // Unreachable | |
| 840 Except.isTrue(false); | |
| 841 } | |
| 842 return "/$pathComponent"; | |
| 843 } | |
| 844 | |
| 845 void _getUriForBrowserTest(TestInformation info, | |
| 846 String pathComponent, | |
| 847 subtestNames, | |
| 848 subtestIndex) { | |
| 849 // Note: If we run test.py with the "--list" option, no http servers | |
| 850 // will be started. Therefore serverList is an empty list in this | |
| 851 // case. So we use PORT/CROSS_ORIGIN_PORT instead of real ports. | |
| 852 var serverPort = "PORT"; | |
| 853 var crossOriginPort = "CROSS_ORIGIN_PORT"; | |
| 854 if (!configuration['list']) { | |
| 855 serverPort = serverList[0].port.toString(); | |
| 856 crossOriginPort = serverList[1].port.toString(); | |
| 857 } | |
| 858 | |
| 859 var url= 'http://127.0.0.1:$serverPort$pathComponent' | |
| 860 '?crossOriginPort=$crossOriginPort'; | |
| 861 if (info.optionsFromFile['isMultiHtmlTest'] && subtestNames.length > 0) { | |
| 862 url= '${url}&group=${subtestNames[subtestIndex]}'; | |
| 863 } | |
| 864 return url; | |
| 865 } | |
| 866 | |
| 867 void _createWrapperFile(String dartWrapperFilename, dartLibraryFilename) { | |
| 868 File file = new File(dartWrapperFilename); | |
| 869 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE); | |
| 870 | |
| 871 var usePackageImport = dartLibraryFilename.segments().contains("pkg"); | |
| 872 var libraryPathComponent = _createUrlPathFromFile(dartLibraryFilename); | |
| 873 dartWrapper.writeStringSync(dartTestWrapper(usePackageImport, | |
| 874 libraryPathComponent)); | |
| 875 dartWrapper.closeSync(); | |
| 876 } | |
| 877 | |
| 878 void _createLibraryWrapperFile(Path dartLibraryFilename, filePath) { | |
| 879 File file = new File(dartLibraryFilename.toNativePath()); | |
| 880 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE); | |
| 881 dartLibrary.writeStringSync( | |
| 882 wrapDartTestInLibrary(filePath.relativeTo(TestUtils.dartDir()))); | |
| 883 dartLibrary.closeSync(); | |
| 884 } | |
| 885 | |
| 815 /** | 886 /** |
| 816 * The [StandardTestSuite] has support for tests that | 887 * The [StandardTestSuite] has support for tests that |
| 817 * compile a test from Dart to JavaScript, and then run the resulting | 888 * compile a test from Dart to JavaScript, and then run the resulting |
| 818 * JavaScript. This function creates a working directory to hold the | 889 * JavaScript. This function creates a working directory to hold the |
| 819 * JavaScript version of the test, and copies the appropriate framework | 890 * JavaScript version of the test, and copies the appropriate framework |
| 820 * files to that directory. It creates a [BrowserTestCase], which has | 891 * files to that directory. It creates a [BrowserTestCase], which has |
| 821 * two sequential steps to be run by the [ProcessQueue] when the test is | 892 * two sequential steps to be run by the [ProcessQueue] when the test is |
| 822 * executed: a compilation step and an execution step, both with the | 893 * executed: a compilation step and an execution step, both with the |
| 823 * appropriate executable and arguments. The [expectations] object can be | 894 * appropriate executable and arguments. The [expectations] object can be |
| 824 * either a Set<String> if the test is a regular test, or a Map<String | 895 * either a Set<String> if the test is a regular test, or a Map<String |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 String compiledDartWrapperFilename = '$tempDir/test.js'; | 931 String compiledDartWrapperFilename = '$tempDir/test.js'; |
| 861 | 932 |
| 862 String htmlPath = '$tempDir/test.html'; | 933 String htmlPath = '$tempDir/test.html'; |
| 863 if (isWrappingRequired && !isWebTest) { | 934 if (isWrappingRequired && !isWebTest) { |
| 864 // test.dart will import the dart test directly, if it is a library, | 935 // test.dart will import the dart test directly, if it is a library, |
| 865 // or indirectly through test_as_library.dart, if it is not. | 936 // or indirectly through test_as_library.dart, if it is not. |
| 866 Path dartLibraryFilename = filePath; | 937 Path dartLibraryFilename = filePath; |
| 867 if (!isLibraryDefinition) { | 938 if (!isLibraryDefinition) { |
| 868 dartLibraryFilename = new Path(tempDir).append( | 939 dartLibraryFilename = new Path(tempDir).append( |
| 869 'test_as_library.dart'); | 940 'test_as_library.dart'); |
| 870 File file = new File(dartLibraryFilename.toNativePath()); | 941 _createLibraryWrapperFile(dartLibraryFilename, filePath); |
| 871 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE); | |
| 872 dartLibrary.writeStringSync( | |
| 873 wrapDartTestInLibrary(filePath, file.name)); | |
| 874 dartLibrary.closeSync(); | |
| 875 } | 942 } |
| 876 | 943 _createWrapperFile(dartWrapperFilename, dartLibraryFilename); |
| 877 File file = new File(dartWrapperFilename); | |
| 878 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE); | |
| 879 dartWrapper.writeStringSync( | |
| 880 dartTestWrapper(dartDir, file.name, dartLibraryFilename)); | |
| 881 dartWrapper.closeSync(); | |
| 882 } else { | 944 } else { |
| 883 dartWrapperFilename = filename; | 945 dartWrapperFilename = filename; |
| 884 // TODO(whesse): Once test.py is retired, adjust the relative path in | 946 // TODO(whesse): Once test.py is retired, adjust the relative path in |
| 885 // the client/samples/dartcombat test to its css file, remove the | 947 // the client/samples/dartcombat test to its css file, remove the |
| 886 // "../../" from this path, and move this out of the isWebTest guard. | 948 // "../../" from this path, and move this out of the isWebTest guard. |
| 887 // Also remove getHtmlName, and just use test.html. | 949 // Also remove getHtmlName, and just use test.html. |
| 888 // TODO(efortuna): this shortening of htmlFilename is a band-aid until | 950 // TODO(efortuna): this shortening of htmlFilename is a band-aid until |
| 889 // the above TODO gets fixed. Windows cannot have paths that are longer | 951 // the above TODO gets fixed. Windows cannot have paths that are longer |
| 890 // than 260 characters, and without this hack, we were running past the | 952 // than 260 characters, and without this hack, we were running past the |
| 891 // the limit. | 953 // the limit. |
| 892 String htmlFilename = getHtmlName(filename); | 954 String htmlFilename = getHtmlName(filename); |
| 893 while ('$tempDir/../$htmlFilename'.length >= 260) { | 955 while ('$tempDir/../$htmlFilename'.length >= 260) { |
| 894 htmlFilename = htmlFilename.substring(htmlFilename.length~/2); | 956 htmlFilename = htmlFilename.substring(htmlFilename.length~/2); |
| 895 } | 957 } |
| 896 htmlPath = '$tempDir/../$htmlFilename'; | 958 htmlPath = '$tempDir/../$htmlFilename'; |
| 897 } | 959 } |
| 898 final String scriptPath = (compiler == 'none') ? | 960 String scriptPath = (compiler == 'none') ? |
| 899 dartWrapperFilename : compiledDartWrapperFilename; | 961 dartWrapperFilename : compiledDartWrapperFilename; |
| 962 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); | |
| 963 | |
| 900 // Create the HTML file for the test. | 964 // Create the HTML file for the test. |
| 901 RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE); | 965 RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE); |
| 902 String content = null; | 966 String content = null; |
| 903 Path dir = filePath.directoryPath; | 967 Path dir = filePath.directoryPath; |
| 904 String nameNoExt = filePath.filenameWithoutExtension; | 968 String nameNoExt = filePath.filenameWithoutExtension; |
| 905 Path pngPath = dir.append('$nameNoExt.png'); | 969 Path pngPath = dir.append('$nameNoExt.png'); |
| 906 Path txtPath = dir.append('$nameNoExt.txt'); | 970 Path txtPath = dir.append('$nameNoExt.txt'); |
| 907 Path expectedOutput = null; | 971 Path expectedOutput = null; |
| 908 if (new File.fromPath(pngPath).existsSync()) { | 972 if (new File.fromPath(pngPath).existsSync()) { |
| 909 expectedOutput = pngPath; | 973 expectedOutput = pngPath; |
| 910 // TODO(efortuna): Unify path libraries in test.dart. | 974 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| 911 content = getHtmlLayoutContents(scriptType, pathLib.relative(scriptPath, | |
| 912 from: pathLib.dirname(htmlPath))); | |
| 913 } else if (new File.fromPath(txtPath).existsSync()) { | 975 } else if (new File.fromPath(txtPath).existsSync()) { |
| 914 expectedOutput = txtPath; | 976 expectedOutput = txtPath; |
| 915 content = getHtmlLayoutContents(scriptType, pathLib.relative(scriptPath, | 977 content = getHtmlLayoutContents(scriptType, new Path("$scriptPath")); |
| 916 from: pathLib.dirname(htmlPath))); | |
| 917 } else { | 978 } else { |
| 918 final htmlLocation = new Path(htmlPath); | 979 content = getHtmlContents(filename, scriptType, |
| 919 content = getHtmlContents( | 980 new Path("$scriptPath")); |
| 920 filename, | |
| 921 dartDir.append('pkg/unittest/test_controller.js') | |
| 922 .relativeTo(htmlLocation), | |
| 923 dartDir.append('pkg/browser/lib/dart.js').relativeTo(htmlLocation), | |
| 924 scriptType, | |
| 925 new Path(scriptPath).relativeTo(htmlLocation)); | |
| 926 } | 981 } |
| 927 htmlTest.writeStringSync(content); | 982 htmlTest.writeStringSync(content); |
| 928 htmlTest.closeSync(); | 983 htmlTest.closeSync(); |
| 929 | 984 |
| 930 // Construct the command(s) that compile all the inputs needed by the | 985 // Construct the command(s) that compile all the inputs needed by the |
| 931 // browser test. For running Dart in DRT, this will be noop commands. | 986 // browser test. For running Dart in DRT, this will be noop commands. |
| 932 List<Command> commands = []; | 987 List<Command> commands = []; |
| 933 if (compiler != 'none') { | 988 if (compiler != 'none') { |
| 934 commands.add(_compileCommand( | 989 commands.add(_compileCommand( |
| 935 dartWrapperFilename, compiledDartWrapperFilename, | 990 dartWrapperFilename, compiledDartWrapperFilename, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 955 // Construct the command that executes the browser test | 1010 // Construct the command that executes the browser test |
| 956 do { | 1011 do { |
| 957 List<Command> commandSet = new List<Command>.from(commands); | 1012 List<Command> commandSet = new List<Command>.from(commands); |
| 958 if (subtestIndex != 0) { | 1013 if (subtestIndex != 0) { |
| 959 // NOTE: The first time we enter this loop, all the compilation | 1014 // NOTE: The first time we enter this loop, all the compilation |
| 960 // commands will be executed. On subsequent loop iterations, we | 1015 // commands will be executed. On subsequent loop iterations, we |
| 961 // don't need to do any compilations. Thus we set "commandSet = []". | 1016 // don't need to do any compilations. Thus we set "commandSet = []". |
| 962 commandSet = []; | 1017 commandSet = []; |
| 963 } | 1018 } |
| 964 | 1019 |
| 1020 var htmlPath_subtest = _createUrlPathFromFile(new Path(htmlPath)); | |
| 1021 var fullHtmlPath = _getUriForBrowserTest(info, htmlPath_subtest, | |
| 1022 subtestNames, subtestIndex); | |
|
ricow1
2013/02/06 08:13:28
indentation
kustermann
2013/02/06 16:33:51
Done.
| |
| 1023 | |
| 965 List<String> args = <String>[]; | 1024 List<String> args = <String>[]; |
| 966 var basePath = TestUtils.dartDir().toString(); | |
| 967 if (!htmlPath.startsWith('/') && !htmlPath.startsWith('http')) { | |
| 968 htmlPath = '/$htmlPath'; | |
| 969 } | |
| 970 htmlPath = htmlPath.startsWith(basePath) ? | |
| 971 htmlPath.substring(basePath.length) : htmlPath; | |
| 972 String fullHtmlPath = htmlPath; | |
| 973 var searchStr = '?'; | |
| 974 if (!htmlPath.startsWith('http')) { | |
| 975 // Note: If we run test.py with the "--list" option, no http servers | |
| 976 // will be started. Therefore serverList is an empty list in this | |
| 977 // case. So we use PORT/CROSS_ORIGIN_PORT instead of real ports. | |
| 978 var serverPort = "PORT"; | |
| 979 var crossOriginPort = "CROSS_ORIGIN_PORT"; | |
| 980 if (!configuration['list']) { | |
| 981 serverPort = serverList[0].port.toString(); | |
| 982 crossOriginPort = serverList[1].port.toString(); | |
| 983 } | |
| 984 fullHtmlPath = 'http://127.0.0.1:$serverPort$htmlPath${searchStr}' | |
| 985 'crossOriginPort=$crossOriginPort'; | |
| 986 searchStr = '&'; | |
| 987 } | |
| 988 if (info.optionsFromFile['isMultiHtmlTest'] | |
| 989 && subtestNames.length > 0) { | |
| 990 fullHtmlPath = '${fullHtmlPath}${searchStr}group=' | |
| 991 '${subtestNames[subtestIndex]}'; | |
| 992 } | |
| 993 | |
| 994 if (TestUtils.usesWebDriver(runtime)) { | 1025 if (TestUtils.usesWebDriver(runtime)) { |
| 995 args = [ | 1026 args = [ |
| 996 dartDir.append('tools/testing/run_selenium.py').toNativePath(), | 1027 dartDir.append('tools/testing/run_selenium.py').toNativePath(), |
| 997 '--browser=$runtime', | 1028 '--browser=$runtime', |
| 998 '--timeout=${configuration["timeout"] - 2}', | 1029 '--timeout=${configuration["timeout"] - 2}', |
| 999 '--out="$fullHtmlPath"']; | 1030 '--out="$fullHtmlPath"']; |
| 1000 if (runtime == 'dartium') { | 1031 if (runtime == 'dartium') { |
| 1001 args.add('--executable=$dartiumFilename'); | 1032 args.add('--executable=$dartiumFilename'); |
| 1002 } | 1033 } |
| 1003 if (subtestIndex != 0) { | 1034 if (subtestIndex != 0) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 } | 1149 } |
| 1119 | 1150 |
| 1120 // Create '[build dir]/generated_tests/$compiler-$runtime/$testUniqueName', | 1151 // Create '[build dir]/generated_tests/$compiler-$runtime/$testUniqueName', |
| 1121 // including any intermediate directories that don't exist. | 1152 // including any intermediate directories that don't exist. |
| 1122 // If the tests are run in checked or minified mode we add that to the | 1153 // If the tests are run in checked or minified mode we add that to the |
| 1123 // '$compile-$runtime' directory name. | 1154 // '$compile-$runtime' directory name. |
| 1124 var checked = configuration['checked'] ? '-checked' : ''; | 1155 var checked = configuration['checked'] ? '-checked' : ''; |
| 1125 var minified = configuration['minified'] ? '-minified' : ''; | 1156 var minified = configuration['minified'] ? '-minified' : ''; |
| 1126 var dirName = "${configuration['compiler']}-${configuration['runtime']}" | 1157 var dirName = "${configuration['compiler']}-${configuration['runtime']}" |
| 1127 "$checked$minified"; | 1158 "$checked$minified"; |
| 1128 Path generatedTestPath = new Path(dartDir.toNativePath()) | 1159 Path generatedTestPath = new Path(buildDir) |
| 1129 .append(buildDir) | |
| 1130 .append('generated_tests') | 1160 .append('generated_tests') |
| 1131 .append(dirName) | 1161 .append(dirName) |
| 1132 .append(testUniqueName); | 1162 .append(testUniqueName); |
| 1133 | 1163 |
| 1134 TestUtils.mkdirRecursive(new Path('.'), generatedTestPath); | 1164 TestUtils.mkdirRecursive(new Path('.'), generatedTestPath); |
| 1135 return new File.fromPath(generatedTestPath).fullPathSync() | 1165 return new File.fromPath(generatedTestPath).fullPathSync() |
| 1136 .replaceAll('\\', '/'); | 1166 .replaceAll('\\', '/'); |
| 1137 } | 1167 } |
| 1138 | 1168 |
| 1139 String get scriptType { | 1169 String get scriptType { |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1809 return BROWSERS.contains(runtime); | 1839 return BROWSERS.contains(runtime); |
| 1810 } | 1840 } |
| 1811 | 1841 |
| 1812 static bool isBrowserRuntime(String runtime) => | 1842 static bool isBrowserRuntime(String runtime) => |
| 1813 runtime == 'drt' || TestUtils.usesWebDriver(runtime); | 1843 runtime == 'drt' || TestUtils.usesWebDriver(runtime); |
| 1814 | 1844 |
| 1815 static bool isJsCommandLineRuntime(String runtime) => | 1845 static bool isJsCommandLineRuntime(String runtime) => |
| 1816 const ['d8', 'jsshell'].contains(runtime); | 1846 const ['d8', 'jsshell'].contains(runtime); |
| 1817 | 1847 |
| 1818 static String buildDir(Map configuration) { | 1848 static String buildDir(Map configuration) { |
| 1849 // FIXME(kustermann,ricow): Our code assumes that the returned 'buildDir' | |
| 1850 // is relative to the current working directory. | |
| 1851 // Thus, if we pass in an absolute path (e.g. '--build-directory=/tmp/out') | |
| 1852 // we get into trouble. | |
| 1819 if (configuration['build_directory'] != '') { | 1853 if (configuration['build_directory'] != '') { |
| 1820 return configuration['build_directory']; | 1854 return configuration['build_directory']; |
| 1821 } | 1855 } |
| 1822 var outputDir = ''; | 1856 var outputDir = ''; |
| 1823 var system = configuration['system']; | 1857 var system = configuration['system']; |
| 1824 if (system == 'linux') { | 1858 if (system == 'linux') { |
| 1825 outputDir = 'out/'; | 1859 outputDir = 'out/'; |
| 1826 } else if (system == 'macos') { | 1860 } else if (system == 'macos') { |
| 1827 outputDir = 'xcodebuild/'; | 1861 outputDir = 'xcodebuild/'; |
| 1828 } else if (system == 'windows') { | 1862 } else if (system == 'windows') { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1910 * $pass tests are expected to pass | 1944 * $pass tests are expected to pass |
| 1911 * $failOk tests are expected to fail that we won't fix | 1945 * $failOk tests are expected to fail that we won't fix |
| 1912 * $fail tests are expected to fail that we should fix | 1946 * $fail tests are expected to fail that we should fix |
| 1913 * $crash tests are expected to crash that we should fix | 1947 * $crash tests are expected to crash that we should fix |
| 1914 * $timeout tests are allowed to timeout | 1948 * $timeout tests are allowed to timeout |
| 1915 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 1949 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 1916 """; | 1950 """; |
| 1917 print(report); | 1951 print(report); |
| 1918 } | 1952 } |
| 1919 } | 1953 } |
| OLD | NEW |