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

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

Issue 11777003: Make the "pub" and "pkg" test suites run Dart from the built SDK. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comment. Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * Most TestSuites represent a directory or directory tree containing tests, 97 * Most TestSuites represent a directory or directory tree containing tests,
98 * and a status file containing the expected results when these tests are run. 98 * and a status file containing the expected results when these tests are run.
99 */ 99 */
100 abstract class TestSuite { 100 abstract class TestSuite {
101 final Map configuration; 101 final Map configuration;
102 final String suiteName; 102 final String suiteName;
103 103
104 TestSuite(this.configuration, this.suiteName); 104 TestSuite(this.configuration, this.suiteName);
105 105
106 /** 106 /**
107 * Whether or not binaries should be found in the root build directory or
108 * in the built SDK.
109 */
110 bool get useSdk {
111 // Some suites always use the SDK.
112 // TODO(rnystrom): Eventually, all tests should run out of the SDK and this
113 // check should go away.
114 if (['pkg', 'pub'].contains(suiteName)) return true;
115
116 return configuration['use_sdk'];
117 }
118
119 /**
107 * The output directory for this suite's configuration. 120 * The output directory for this suite's configuration.
108 */ 121 */
109 String get buildDir => TestUtils.buildDir(configuration); 122 String get buildDir => TestUtils.buildDir(configuration);
110 123
111 /** 124 /**
112 * The path to the compiler for this suite's configuration. Returns `null` if 125 * The path to the compiler for this suite's configuration. Returns `null` if
113 * no compiler should be used. 126 * no compiler should be used.
114 */ 127 */
115 String get compilerPath { 128 String get compilerPath {
116 if (configuration['compiler'] == 'none') { 129 if (configuration['compiler'] == 'none') {
117 return null; // No separate compiler for dartium tests. 130 return null; // No separate compiler for dartium tests.
118 } 131 }
119 var name; 132 var name;
120 switch (configuration['compiler']) { 133 switch (configuration['compiler']) {
121 case 'dartc': 134 case 'dartc':
122 name = '$buildDir/$executableName'; 135 name = executablePath;
123 case 'dart2js': 136 case 'dart2js':
124 case 'dart2dart': 137 case 'dart2dart':
125 var prefix = 'sdk/bin/'; 138 var prefix = 'sdk/bin/';
126 String suffix = getExecutableSuffix(configuration['compiler']); 139 String suffix = getExecutableSuffix(configuration['compiler']);
127 if (configuration['host_checked']) { 140 if (configuration['host_checked']) {
128 // The script dart2js_developer is not included in the 141 // The script dart2js_developer is not included in the
129 // shipped SDK, that is the script is not installed in 142 // shipped SDK, that is the script is not installed in
130 // "$buildDir/dart-sdk/bin/" 143 // "$buildDir/dart-sdk/bin/"
131 name = '$prefix/dart2js_developer$suffix'; 144 name = '$prefix/dart2js_developer$suffix';
132 } else { 145 } else {
133 if (configuration['use_sdk']) { 146 if (configuration['use_sdk']) {
134 prefix = '$buildDir/dart-sdk/bin/'; 147 prefix = '$buildDir/dart-sdk/bin/';
135 } 148 }
136 name = '${prefix}dart2js$suffix'; 149 name = '${prefix}dart2js$suffix';
137 } 150 }
138 break; 151 break;
139 default: 152 default:
140 throw "Unknown compiler for: ${configuration['compiler']}"; 153 throw "Unknown compiler for: ${configuration['compiler']}";
141 } 154 }
142 if (!(new File(name)).existsSync() && !configuration['list']) { 155 if (!(new File(name)).existsSync() && !configuration['list']) {
143 throw "Executable '$name' does not exist"; 156 throw "Executable '$name' does not exist";
144 } 157 }
145 return name; 158 return name;
146 } 159 }
147 160
148 /** 161 /**
149 * The file name of the executable used to run this suite's tests. 162 * The path to the executable used to run this suite's tests.
150 */ 163 */
151 String get executableName { 164 String get executablePath {
152 String suffix = getExecutableSuffix(configuration['compiler']); 165 var suffix = getExecutableSuffix(configuration['compiler']);
153 switch (configuration['compiler']) { 166 switch (configuration['compiler']) {
154 case 'none': 167 case 'none':
155 return 'dart$suffix'; 168 if (useSdk) {
169 return '$buildDir/dart-sdk/bin/dart$suffix';
170 }
171 return '$buildDir/dart$suffix';
156 case 'dartc': 172 case 'dartc':
157 return 'analyzer/bin/dart_analyzer$suffix'; 173 return '$buildDir/analyzer/bin/dart_analyzer$suffix';
158 default: 174 default:
159 throw "Unknown executable for: ${configuration['compiler']}"; 175 throw "Unknown executable for: ${configuration['compiler']}";
160 } 176 }
161 } 177 }
162 178
163 /** 179 /**
164 * The file name of the d8 executable. 180 * The file name of the d8 executable.
165 */ 181 */
166 String get d8FileName { 182 String get d8FileName {
167 var suffix = getExecutableSuffix('d8'); 183 var suffix = getExecutableSuffix('d8');
168 var d8 = '$buildDir/d8$suffix'; 184 var d8 = '$buildDir/d8$suffix';
169 TestUtils.ensureExists(d8, configuration); 185 TestUtils.ensureExists(d8, configuration);
170 return d8; 186 return d8;
171 } 187 }
172 188
173 String get dartShellFileName { 189 String get dartShellFileName {
174 var name = configuration['dart']; 190 var name = configuration['dart'];
175 if (name == '') { 191 if (name == '') {
176 name = '$buildDir/$executableName'; 192 name = executablePath;
177 } 193 }
194
178 TestUtils.ensureExists(name, configuration); 195 TestUtils.ensureExists(name, configuration);
179 return name; 196 return name;
180 } 197 }
181 198
182 String get jsShellFileName { 199 String get jsShellFileName {
183 var executableSuffix = getExecutableSuffix('jsshell'); 200 var executableSuffix = getExecutableSuffix('jsshell');
184 var executable = 'jsshell$executableSuffix'; 201 var executable = 'jsshell$executableSuffix';
185 var jsshellDir = '${TestUtils.dartDir()}/tools/testing/bin'; 202 var jsshellDir = '${TestUtils.dartDir()}/tools/testing/bin';
186 return '$jsshellDir/$executable'; 203 return '$jsshellDir/$executable';
187 } 204 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 final name = directory.filename; 445 final name = directory.filename;
429 446
430 return new StandardTestSuite(configuration, 447 return new StandardTestSuite(configuration,
431 name, directory, 448 name, directory,
432 ['$directory/$name.status', '$directory/${name}_dart2js.status'], 449 ['$directory/$name.status', '$directory/${name}_dart2js.status'],
433 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'), 450 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'),
434 recursive: true); 451 recursive: true);
435 } 452 }
436 453
437 Collection<Uri> get dart2JsBootstrapDependencies { 454 Collection<Uri> get dart2JsBootstrapDependencies {
438 if (!useDart2JsFromSdk) return []; 455 if (!useSdk) return [];
439 456
440 var snapshotPath = TestUtils.absolutePath(new Path(buildDir).join( 457 var snapshotPath = TestUtils.absolutePath(new Path(buildDir).join(
441 new Path('dart-sdk/lib/_internal/compiler/' 458 new Path('dart-sdk/lib/_internal/compiler/'
442 'implementation/dart2js.dart.snapshot'))).toString(); 459 'implementation/dart2js.dart.snapshot'))).toString();
443 return [new Uri.fromComponents(scheme: 'file', path: snapshotPath)]; 460 return [new Uri.fromComponents(scheme: 'file', path: snapshotPath)];
444 } 461 }
445 462
446 bool get useDart2JsFromSdk {
447 return configuration['use_sdk'];
448 }
449
450 /** 463 /**
451 * The default implementation assumes a file is a test if 464 * The default implementation assumes a file is a test if
452 * it ends in "Test.dart". 465 * it ends in "Test.dart".
453 */ 466 */
454 bool isTestFile(String filename) { 467 bool isTestFile(String filename) {
455 // Use the specified predicate, if provided. 468 // Use the specified predicate, if provided.
456 if (isTestFilePredicate != null) return isTestFilePredicate(filename); 469 if (isTestFilePredicate != null) return isTestFilePredicate(filename);
457 470
458 return filename.endsWith("Test.dart"); 471 return filename.endsWith("Test.dart");
459 } 472 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 710 }
698 } 711 }
699 712
700 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { 713 List<Command> makeCommands(TestInformation info, var vmOptions, var args) {
701 switch (configuration['compiler']) { 714 switch (configuration['compiler']) {
702 case 'dart2js': 715 case 'dart2js':
703 args = new List.from(args); 716 args = new List.from(args);
704 String tempDir = createOutputDirectory(info.filePath, ''); 717 String tempDir = createOutputDirectory(info.filePath, '');
705 args.add('--out=$tempDir/out.js'); 718 args.add('--out=$tempDir/out.js');
706 719
707 List<Command> commands = 720 List<Command> commands =
708 <Command>[new CompilationCommand("$tempDir/out.js", 721 <Command>[new CompilationCommand("$tempDir/out.js",
709 !useDart2JsFromSdk, 722 !useSdk,
710 dart2JsBootstrapDependencies, 723 dart2JsBootstrapDependencies,
711 compilerPath, 724 compilerPath,
712 args)]; 725 args)];
713 if (info.hasCompileError) { 726 if (info.hasCompileError) {
714 // Do not attempt to run the compiled result. A compilation 727 // Do not attempt to run the compiled result. A compilation
715 // error should be reported by the compilation command. 728 // error should be reported by the compilation command.
716 } else if (configuration['runtime'] == 'd8') { 729 } else if (configuration['runtime'] == 'd8') {
717 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); 730 commands.add(new Command(d8FileName, ['$tempDir/out.js']));
718 } else if (configuration['runtime'] == 'jsshell') { 731 } else if (configuration['runtime'] == 'jsshell') {
719 commands.add(new Command(jsShellFileName, ['$tempDir/out.js'])); 732 commands.add(new Command(jsShellFileName, ['$tempDir/out.js']));
720 } 733 }
721 return commands; 734 return commands;
722 735
723 case 'dart2dart': 736 case 'dart2dart':
724 args = new List.from(args); 737 args = new List.from(args);
725 args.add('--output-type=dart'); 738 args.add('--output-type=dart');
726 String tempDir = createOutputDirectory(info.filePath, ''); 739 String tempDir = createOutputDirectory(info.filePath, '');
727 args.add('--out=$tempDir/out.dart'); 740 args.add('--out=$tempDir/out.dart');
728 741
729 List<Command> commands = 742 List<Command> commands =
730 <Command>[new CompilationCommand("$tempDir/out.dart", 743 <Command>[new CompilationCommand("$tempDir/out.dart",
731 !useDart2JsFromSdk, 744 !useSdk,
732 dart2JsBootstrapDependencies, 745 dart2JsBootstrapDependencies,
733 compilerPath, 746 compilerPath,
734 args)]; 747 args)];
735 if (info.hasCompileError) { 748 if (info.hasCompileError) {
736 // Do not attempt to run the compiled result. A compilation 749 // Do not attempt to run the compiled result. A compilation
737 // error should be reported by the compilation command. 750 // error should be reported by the compilation command.
738 } else if (configuration['runtime'] == 'vm') { 751 } else if (configuration['runtime'] == 'vm') {
739 // TODO(antonm): support checked. 752 // TODO(antonm): support checked.
740 var vmArguments = new List.from(vmOptions); 753 var vmArguments = new List.from(vmOptions);
741 vmArguments.addAll([ 754 vmArguments.addAll([
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 } 928 }
916 929
917 // Variables for browser multi-tests. 930 // Variables for browser multi-tests.
918 List<String> subtestNames = info.optionsFromFile['subtestNames']; 931 List<String> subtestNames = info.optionsFromFile['subtestNames'];
919 TestCase multitestParentTest; 932 TestCase multitestParentTest;
920 int subtestIndex = 0; 933 int subtestIndex = 0;
921 // Construct the command that executes the browser test 934 // Construct the command that executes the browser test
922 do { 935 do {
923 List<Command> commandSet = new List<Command>.from(commands); 936 List<Command> commandSet = new List<Command>.from(commands);
924 if (subtestIndex != 0) { 937 if (subtestIndex != 0) {
925 // NOTE: The first time we enter this loop, all the compilation 938 // NOTE: The first time we enter this loop, all the compilation
926 // commands will be executed. On subsequent loop iterations, we 939 // commands will be executed. On subsequent loop iterations, we
927 // don't need to do any compilations. Thus we set "commandSet = []". 940 // don't need to do any compilations. Thus we set "commandSet = []".
928 commandSet = []; 941 commandSet = [];
929 } 942 }
930 943
931 List<String> args = <String>[]; 944 List<String> args = <String>[];
932 String fullHtmlPath = htmlPath.startsWith('http:') ? htmlPath : 945 String fullHtmlPath = htmlPath.startsWith('http:') ? htmlPath :
933 (htmlPath.startsWith('/') ? 946 (htmlPath.startsWith('/') ?
934 'file://$htmlPath' : 947 'file://$htmlPath' :
935 'file:///$htmlPath'); 948 'file:///$htmlPath');
936 if (info.optionsFromFile['isMultiHtmlTest'] 949 if (info.optionsFromFile['isMultiHtmlTest']
(...skipping 27 matching lines...) Expand all
964 dartFlags.add('--ignore-unrecognized-flags'); 977 dartFlags.add('--ignore-unrecognized-flags');
965 if (configuration["checked"]) { 978 if (configuration["checked"]) {
966 dartFlags.add('--enable_asserts'); 979 dartFlags.add('--enable_asserts');
967 dartFlags.add("--enable_type_checks"); 980 dartFlags.add("--enable_type_checks");
968 } 981 }
969 dartFlags.addAll(vmOptions); 982 dartFlags.addAll(vmOptions);
970 } 983 }
971 if (compiler == 'none') { 984 if (compiler == 'none') {
972 var packageRootPath = packageRoot(optionsFromFile['packageRoot']); 985 var packageRootPath = packageRoot(optionsFromFile['packageRoot']);
973 if (packageRootPath != null) { 986 if (packageRootPath != null) {
974 var absolutePath = 987 var absolutePath =
975 TestUtils.absolutePath(new Path(packageRootPath)); 988 TestUtils.absolutePath(new Path(packageRootPath));
976 packageRootUri = new Uri.fromComponents( 989 packageRootUri = new Uri.fromComponents(
977 scheme: 'file', 990 scheme: 'file',
978 path: absolutePath.toString()); 991 path: absolutePath.toString());
979 } 992 }
980 } 993 }
981 994
982 if (expectedOutput != null) { 995 if (expectedOutput != null) {
983 if (expectedOutput.toNativePath().endsWith('.png')) { 996 if (expectedOutput.toNativePath().endsWith('.png')) {
984 // pixel tests are specified by running DRT "foo.html'-p" 997 // pixel tests are specified by running DRT "foo.html'-p"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 default: 1053 default:
1041 Expect.fail('unimplemented compiler $compiler'); 1054 Expect.fail('unimplemented compiler $compiler');
1042 } 1055 }
1043 if (executable.endsWith('.dart')) { 1056 if (executable.endsWith('.dart')) {
1044 // Run the compiler script via the Dart VM. 1057 // Run the compiler script via the Dart VM.
1045 args.insertRange(0, 1, executable); 1058 args.insertRange(0, 1, executable);
1046 executable = dartShellFileName; 1059 executable = dartShellFileName;
1047 } 1060 }
1048 if (['dart2js', 'dart2dart'].contains(configuration['compiler'])) { 1061 if (['dart2js', 'dart2dart'].contains(configuration['compiler'])) {
1049 return new CompilationCommand(outputFile, 1062 return new CompilationCommand(outputFile,
1050 !useDart2JsFromSdk, 1063 !useSdk,
1051 dart2JsBootstrapDependencies, 1064 dart2JsBootstrapDependencies,
1052 compilerPath, 1065 compilerPath,
1053 args); 1066 args);
1054 } 1067 }
1055 return new Command(executable, args); 1068 return new Command(executable, args);
1056 } 1069 }
1057 1070
1058 /** 1071 /**
1059 * Create a directory for the generated test. If a Dart language test 1072 * Create a directory for the generated test. If a Dart language test
1060 * needs to be run in a browser, the Dart test needs to be embedded in 1073 * needs to be run in a browser, the Dart test needs to be embedded in
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 * $pass tests are expected to pass 1806 * $pass tests are expected to pass
1794 * $failOk tests are expected to fail that we won't fix 1807 * $failOk tests are expected to fail that we won't fix
1795 * $fail tests are expected to fail that we should fix 1808 * $fail tests are expected to fail that we should fix
1796 * $crash tests are expected to crash that we should fix 1809 * $crash tests are expected to crash that we should fix
1797 * $timeout tests are allowed to timeout 1810 * $timeout tests are allowed to timeout
1798 * $compileErrorSkip tests are skipped on browsers due to compile-time error 1811 * $compileErrorSkip tests are skipped on browsers due to compile-time error
1799 """; 1812 """;
1800 print(report); 1813 print(report);
1801 } 1814 }
1802 } 1815 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698