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