Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 12223074: Create generated tests inside the build directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: dromaeo fixes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
11 * and creating [TestCase]s for those files that meet the relevant criteria. 11 * and creating [TestCase]s for those files that meet the relevant criteria.
12 * - Preparing tests, including copying files and frameworks to temporary 12 * - Preparing tests, including copying files and frameworks to temporary
13 * directories, and computing the command line and arguments to be run. 13 * directories, and computing the command line and arguments to be run.
14 */ 14 */
15 library test_suite; 15 library test_suite;
16 16
17 import "dart:async"; 17 import "dart:async";
18 import "dart:io"; 18 import "dart:io";
19 import "dart:isolate"; 19 import "dart:isolate";
20 import "dart:uri"; 20 import "dart:uri";
21 import "drt_updater.dart"; 21 import "drt_updater.dart";
22 import "multitest.dart"; 22 import "multitest.dart";
23 import "status_file_parser.dart"; 23 import "status_file_parser.dart";
24 import "test_runner.dart"; 24 import "test_runner.dart";
25 import "utils.dart"; 25 import "utils.dart";
26 import "http_server.dart" show PREFIX_BUILDDIR, PREFIX_DARTDIR;
26 27
27 // TODO(efortuna,whess): Remove this import. 28 // TODO(efortuna,whess): Remove this import.
28 import 'vendored_pkg/path/path.dart' as pathLib; 29 import 'vendored_pkg/path/path.dart' as pathLib;
Emily Fortuna 2013/02/16 02:22:01 this isn't an "external dependency" if it's used o
kustermann 2013/02/18 09:27:02 I removed it completely.
29 30
30 part "browser_test.dart"; 31 part "browser_test.dart";
31 32
32 33
33 // TODO(rnystrom): Add to dart:core? 34 // TODO(rnystrom): Add to dart:core?
34 /** 35 /**
35 * A simple function that tests [arg] and returns `true` or `false`. 36 * A simple function that tests [arg] and returns `true` or `false`.
36 */ 37 */
37 typedef bool Predicate<T>(T arg); 38 typedef bool Predicate<T>(T arg);
38 39
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 hasCompileError, 806 hasCompileError,
806 hasRuntimeError, 807 hasRuntimeError,
807 isNegativeIfChecked, 808 isNegativeIfChecked,
808 hasFatalTypeErrors, 809 hasFatalTypeErrors,
809 multitestOutcome); 810 multitestOutcome);
810 cachedTests.add(info); 811 cachedTests.add(info);
811 enqueueTestCaseFromTestInformation(info); 812 enqueueTestCaseFromTestInformation(info);
812 }; 813 };
813 } 814 }
814 815
815 /** 816
817 /**
818 * _createUrlPathFromFile takes a [file], which is either located in the dart
819 * or in the build directory, and will return a String representing
820 * the relative path to either the dart or the build directory.
821 * Thus, the returned [String] will be the path component of the URL
822 * corresponding to [file] (the http server serves files relative to the
823 * dart/build directories).
824 */
825 String _createUrlPathFromFile(Path file) {
826 file = TestUtils.absolutePath(file);
827
828 var relativeBuildDir = new Path(TestUtils.buildDir(configuration));
829 var buildDir = TestUtils.absolutePath(relativeBuildDir);
830 var dartDir = TestUtils.absolutePath(TestUtils.dartDir());
831
832 var fileString = file.toString();
833 if (fileString.startsWith(buildDir.toString())) {
834 var fileRelativeToBuildDir = file.relativeTo(buildDir);
835 return "/$PREFIX_BUILDDIR/$fileRelativeToBuildDir";
836 } else if (fileString.startsWith(dartDir.toString())) {
837 var fileRelativeToDartDir = file.relativeTo(dartDir);
838 return "/$PREFIX_DARTDIR/$fileRelativeToDartDir";
839 }
840 // Unreachable
841 Except.fail('This should be unreachable.');
842 }
843
844 void _getUriForBrowserTest(TestInformation info,
845 String pathComponent,
846 subtestNames,
847 subtestIndex) {
848 // Note: If we run test.py with the "--list" option, no http servers
849 // will be started. Therefore serverList is an empty list in this
850 // case. So we use PORT/CROSS_ORIGIN_PORT instead of real ports.
851 var serverPort = "PORT";
852 var crossOriginPort = "CROSS_ORIGIN_PORT";
853 if (!configuration['list']) {
854 serverPort = serverList[0].port.toString();
855 crossOriginPort = serverList[1].port.toString();
856 }
857
858 var url= 'http://127.0.0.1:$serverPort$pathComponent'
859 '?crossOriginPort=$crossOriginPort';
860 if (info.optionsFromFile['isMultiHtmlTest'] && subtestNames.length > 0) {
861 url= '${url}&group=${subtestNames[subtestIndex]}';
862 }
863 return url;
864 }
865
866 void _createWrapperFile(String dartWrapperFilename, dartLibraryFilename) {
867 File file = new File(dartWrapperFilename);
868 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE);
869
870 var usePackageImport = dartLibraryFilename.segments().contains("pkg");
871 var libraryPathComponent = _createUrlPathFromFile(dartLibraryFilename);
872 dartWrapper.writeStringSync(dartTestWrapper(usePackageImport,
873 libraryPathComponent));
874 dartWrapper.closeSync();
875 }
876
877 void _createLibraryWrapperFile(Path dartLibraryFilename, filePath) {
878 File file = new File(dartLibraryFilename.toNativePath());
879 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE);
880 var requestPath = new Path(PREFIX_DARTDIR)
881 .join(filePath.relativeTo(TestUtils.dartDir()));
882 dartLibrary.writeStringSync(wrapDartTestInLibrary(requestPath));
883 dartLibrary.closeSync();
884 }
885
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
825 * subTestName, Set<String>> if we are running a browser multi-test (one 896 * subTestName, Set<String>> if we are running a browser multi-test (one
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/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));
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
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);
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
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
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
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 }
OLDNEW
« tools/testing/dart/http_server.dart ('K') | « tools/testing/dart/http_server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698