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

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

Issue 118783003: Command class hieracy refactoring, environmentOverride extraction (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years 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 | « dart/tools/testing/dart/test_runner.dart ('k') | dart/tools/testing/dart/utils.dart » ('j') | 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 * 103 *
104 * Most TestSuites represent a directory or directory tree containing tests, 104 * Most TestSuites represent a directory or directory tree containing tests,
105 * and a status file containing the expected results when these tests are run. 105 * and a status file containing the expected results when these tests are run.
106 */ 106 */
107 abstract class TestSuite { 107 abstract class TestSuite {
108 final Map configuration; 108 final Map configuration;
109 final String suiteName; 109 final String suiteName;
110 110
111 TestSuite(this.configuration, this.suiteName); 111 TestSuite(this.configuration, this.suiteName);
112 112
113 String get configurationDir { 113 Map<String, String> get environmentOverrides {
114 return TestUtils.configurationDir(configuration); 114 return {
115 'DART_CONFIGURATION' : TestUtils.configurationDir(configuration),
116 };
115 } 117 }
116 118
117 /** 119 /**
118 * Whether or not binaries should be found in the root build directory or 120 * Whether or not binaries should be found in the root build directory or
119 * in the built SDK. 121 * in the built SDK.
120 */ 122 */
121 bool get useSdk { 123 bool get useSdk {
122 // The pub suite always uses the SDK. 124 // The pub suite always uses the SDK.
123 // TODO(rnystrom): Eventually, all test suites should run out of the SDK 125 // TODO(rnystrom): Eventually, all test suites should run out of the SDK
124 // and this check should go away. 126 // and this check should go away.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Only run the tests that match the pattern. Use the name 383 // Only run the tests that match the pattern. Use the name
382 // "suiteName/testName" for cc tests. 384 // "suiteName/testName" for cc tests.
383 String constructedName = '$suiteName/$testPrefix$testName'; 385 String constructedName = '$suiteName/$testPrefix$testName';
384 386
385 var expectations = testExpectations.expectations( 387 var expectations = testExpectations.expectations(
386 '$testPrefix$testName'); 388 '$testPrefix$testName');
387 389
388 var args = TestUtils.standardOptions(configuration); 390 var args = TestUtils.standardOptions(configuration);
389 args.add(testName); 391 args.add(testName);
390 392
391 var command = CommandBuilder.instance.getCommand( 393 var command = CommandBuilder.instance.getProcessCommand(
392 'run_vm_unittest', targetRunnerPath, args, configurationDir); 394 'run_vm_unittest', targetRunnerPath, args, environmentOverrides);
393 enqueueNewTestCase( 395 enqueueNewTestCase(
394 new TestCase(constructedName, [command], configuration, expectations)); 396 new TestCase(constructedName, [command], configuration, expectations));
395 } 397 }
396 398
397 void forEachTest(Function onTest, Map testCache, [VoidFunction onDone]) { 399 void forEachTest(Function onTest, Map testCache, [VoidFunction onDone]) {
398 doTest = onTest; 400 doTest = onTest;
399 doDone = onDone; 401 doDone = onDone;
400 402
401 var filesRead = 0; 403 var filesRead = 0;
402 void statusFileRead() { 404 void statusFileRead() {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 List<String> sharedOptions = info.optionsFromFile['sharedOptions']; 733 List<String> sharedOptions = info.optionsFromFile['sharedOptions'];
732 switch (compiler) { 734 switch (compiler) {
733 case 'dart2js': 735 case 'dart2js':
734 args = new List.from(args); 736 args = new List.from(args);
735 String tempDir = createCompilationOutputDirectory(info.filePath); 737 String tempDir = createCompilationOutputDirectory(info.filePath);
736 args.addAll(sharedOptions); 738 args.addAll(sharedOptions);
737 args.add('--out=$tempDir/out.js'); 739 args.add('--out=$tempDir/out.js');
738 740
739 var command = CommandBuilder.instance.getCompilationCommand( 741 var command = CommandBuilder.instance.getCompilationCommand(
740 compiler, "$tempDir/out.js", !useSdk, 742 compiler, "$tempDir/out.js", !useSdk,
741 dart2JsBootstrapDependencies, compilerPath, args, configurationDir); 743 dart2JsBootstrapDependencies, compilerPath, args,
744 environmentOverrides);
742 745
743 List<Command> commands = <Command>[command]; 746 List<Command> commands = <Command>[command];
744 if (info.hasCompileError) { 747 if (info.hasCompileError) {
745 // Do not attempt to run the compiled result. A compilation 748 // Do not attempt to run the compiled result. A compilation
746 // error should be reported by the compilation command. 749 // error should be reported by the compilation command.
747 } else if (configuration['runtime'] == 'd8') { 750 } else if (configuration['runtime'] == 'd8') {
748 commands.add(CommandBuilder.instance.getJSCommandlineCommand( 751 commands.add(CommandBuilder.instance.getJSCommandlineCommand(
749 "d8", d8FileName, ['$tempDir/out.js'], configurationDir)); 752 "d8", d8FileName, ['$tempDir/out.js'], environmentOverrides));
750 } else if (configuration['runtime'] == 'jsshell') { 753 } else if (configuration['runtime'] == 'jsshell') {
751 commands.add(CommandBuilder.instance.getJSCommandlineCommand( 754 commands.add(CommandBuilder.instance.getJSCommandlineCommand(
752 "jsshell", jsShellFileName, ['$tempDir/out.js'], configurationDir)); 755 "jsshell", jsShellFileName, ['$tempDir/out.js'],
756 environmentOverrides));
753 } 757 }
754 return commands; 758 return commands;
755 case 'dart2dart': 759 case 'dart2dart':
756 args = new List.from(args); 760 args = new List.from(args);
757 args.addAll(sharedOptions); 761 args.addAll(sharedOptions);
758 args.add('--output-type=dart'); 762 args.add('--output-type=dart');
759 String tempDir = createCompilationOutputDirectory(info.filePath); 763 String tempDir = createCompilationOutputDirectory(info.filePath);
760 args.add('--out=$tempDir/out.dart'); 764 args.add('--out=$tempDir/out.dart');
761 765
762 List<Command> commands = 766 List<Command> commands =
763 <Command>[CommandBuilder.instance.getCompilationCommand( 767 <Command>[CommandBuilder.instance.getCompilationCommand(
764 compiler, "$tempDir/out.dart", !useSdk, 768 compiler, "$tempDir/out.dart", !useSdk,
765 dart2JsBootstrapDependencies, compilerPath, args, 769 dart2JsBootstrapDependencies, compilerPath, args,
766 configurationDir)]; 770 environmentOverrides)];
767 if (info.hasCompileError) { 771 if (info.hasCompileError) {
768 // Do not attempt to run the compiled result. A compilation 772 // Do not attempt to run the compiled result. A compilation
769 // error should be reported by the compilation command. 773 // error should be reported by the compilation command.
770 } else if (configuration['runtime'] == 'vm') { 774 } else if (configuration['runtime'] == 'vm') {
771 // TODO(antonm): support checked. 775 // TODO(antonm): support checked.
772 var vmArguments = new List.from(vmOptions); 776 var vmArguments = new List.from(vmOptions);
773 vmArguments.addAll([ 777 vmArguments.addAll([
774 '--ignore-unrecognized-flags', '$tempDir/out.dart']); 778 '--ignore-unrecognized-flags', '$tempDir/out.dart']);
775 commands.add(CommandBuilder.instance.getVmCommand( 779 commands.add(CommandBuilder.instance.getVmCommand(
776 vmFileName, vmArguments, configurationDir)); 780 vmFileName, vmArguments, environmentOverrides));
777 } else { 781 } else {
778 throw 'Unsupported runtime ${configuration["runtime"]} for dart2dart'; 782 throw 'Unsupported runtime ${configuration["runtime"]} for dart2dart';
779 } 783 }
780 return commands; 784 return commands;
781 785
782 case 'none': 786 case 'none':
783 var arguments = new List.from(vmOptions); 787 var arguments = new List.from(vmOptions);
784 arguments.addAll(sharedOptions); 788 arguments.addAll(sharedOptions);
785 arguments.addAll(args); 789 arguments.addAll(args);
786 return <Command>[CommandBuilder.instance.getVmCommand( 790 return <Command>[CommandBuilder.instance.getVmCommand(
787 dartShellFileName, arguments, configurationDir)]; 791 dartShellFileName, arguments, environmentOverrides)];
788 792
789 case 'dartanalyzer': 793 case 'dartanalyzer':
790 case 'dart2analyzer': 794 case 'dart2analyzer':
791 return <Command>[makeAnalysisCommand(info, args)]; 795 return <Command>[makeAnalysisCommand(info, args)];
792 796
793 default: 797 default:
794 throw 'Unknown compiler ${configuration["compiler"]}'; 798 throw 'Unknown compiler ${configuration["compiler"]}';
795 } 799 }
796 } 800 }
797 801
798 AnalysisCommand makeAnalysisCommand(TestInformation info, 802 AnalysisCommand makeAnalysisCommand(TestInformation info,
799 List<String> arguments) { 803 List<String> arguments) {
800 return CommandBuilder.instance.getAnalysisCommand( 804 return CommandBuilder.instance.getAnalysisCommand(
801 configuration['compiler'], dartShellFileName, arguments, 805 configuration['compiler'], dartShellFileName, arguments,
802 configurationDir, flavor: configuration['compiler']); 806 environmentOverrides,
807 flavor: configuration['compiler']);
803 } 808 }
804 809
805 CreateTest makeTestCaseCreator(Map optionsFromFile) { 810 CreateTest makeTestCaseCreator(Map optionsFromFile) {
806 return (Path filePath, 811 return (Path filePath,
807 bool hasCompileError, 812 bool hasCompileError,
808 bool hasRuntimeError, 813 bool hasRuntimeError,
809 {bool isNegativeIfChecked: false, 814 {bool isNegativeIfChecked: false,
810 bool hasStaticWarning: false, 815 bool hasStaticWarning: false,
811 Set<String> multitestOutcome: null, 816 Set<String> multitestOutcome: null,
812 String multitestKey, 817 String multitestKey,
813 Path originTestPath}) { 818 Path originTestPath}) {
814 // Cache the test information for each test case. 819 // Cache the test information for each test case.
815 var info = new TestInformation(filePath, 820 var info = new TestInformation(filePath,
816 optionsFromFile, 821 optionsFromFile,
817 hasCompileError, 822 hasCompileError,
818 hasRuntimeError, 823 hasRuntimeError,
819 isNegativeIfChecked, 824 isNegativeIfChecked,
820 hasStaticWarning, 825 hasStaticWarning,
821 multitestOutcome, 826 multitestOutcome,
822 multitestKey: multitestKey, 827 multitestKey: multitestKey,
823 originTestPath: originTestPath); 828 originTestPath: originTestPath);
824 cachedTests.add(info); 829 cachedTests.add(info);
825 enqueueTestCaseFromTestInformation(info); 830 enqueueTestCaseFromTestInformation(info);
826 }; 831 };
827 } 832 }
828 833
829
830 /** 834 /**
831 * _createUrlPathFromFile takes a [file], which is either located in the dart 835 * _createUrlPathFromFile takes a [file], which is either located in the dart
832 * or in the build directory, and will return a String representing 836 * or in the build directory, and will return a String representing
833 * the relative path to either the dart or the build directory. 837 * the relative path to either the dart or the build directory.
834 * Thus, the returned [String] will be the path component of the URL 838 * Thus, the returned [String] will be the path component of the URL
835 * corresponding to [file] (the http server serves files relative to the 839 * corresponding to [file] (the http server serves files relative to the
836 * dart/build directories). 840 * dart/build directories).
837 */ 841 */
838 String _createUrlPathFromFile(Path file) { 842 String _createUrlPathFromFile(Path file) {
839 file = TestUtils.absolutePath(file); 843 file = TestUtils.absolutePath(file);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 dartFlags.add('--ignore-unrecognized-flags'); 1069 dartFlags.add('--ignore-unrecognized-flags');
1066 if (configuration["checked"]) { 1070 if (configuration["checked"]) {
1067 dartFlags.add('--enable_asserts'); 1071 dartFlags.add('--enable_asserts');
1068 dartFlags.add("--enable_type_checks"); 1072 dartFlags.add("--enable_type_checks");
1069 } 1073 }
1070 dartFlags.addAll(vmOptions); 1074 dartFlags.addAll(vmOptions);
1071 } 1075 }
1072 1076
1073 commandSet.add(CommandBuilder.instance.getContentShellCommand( 1077 commandSet.add(CommandBuilder.instance.getContentShellCommand(
1074 contentShellFilename, fullHtmlPath, contentShellOptions, 1078 contentShellFilename, fullHtmlPath, contentShellOptions,
1075 dartFlags, configurationDir)); 1079 dartFlags, environmentOverrides));
1076 } else { 1080 } else {
1077 // This command is not actually run, it is used for reproducing
1078 // the failure.
1079 args = ['tools/testing/dart/launch_browser.dart',
1080 runtime,
1081 fullHtmlPath];
1082 commandSet.add(CommandBuilder.instance.getBrowserTestCommand( 1081 commandSet.add(CommandBuilder.instance.getBrowserTestCommand(
1083 runtime, fullHtmlPath, TestUtils.dartTestExecutable.toString(), 1082 runtime, fullHtmlPath, checkedMode: configuration['checked']));
1084 args, configurationDir, checkedMode: configuration['checked']));
1085 } 1083 }
1086 1084
1087 // Create BrowserTestCase and queue it. 1085 // Create BrowserTestCase and queue it.
1088 String testDisplayName = '$suiteName/$testName'; 1086 String testDisplayName = '$suiteName/$testName';
1089 var testCase; 1087 var testCase;
1090 if (info.optionsFromFile['isMultiHtmlTest']) { 1088 if (info.optionsFromFile['isMultiHtmlTest']) {
1091 testDisplayName = '$testDisplayName/${subtestNames[subtestIndex]}'; 1089 testDisplayName = '$testDisplayName/${subtestNames[subtestIndex]}';
1092 testCase = new BrowserTestCase(testDisplayName, 1090 testCase = new BrowserTestCase(testDisplayName,
1093 commandSet, configuration, 1091 commandSet, configuration,
1094 expectations['$testName/${subtestNames[subtestIndex]}'], 1092 expectations['$testName/${subtestNames[subtestIndex]}'],
(...skipping 24 matching lines...) Expand all
1119 args.add('--out=$outputFile'); 1117 args.add('--out=$outputFile');
1120 args.add(inputFile); 1118 args.add(inputFile);
1121 args.addAll(optionsFromFile['sharedOptions']); 1119 args.addAll(optionsFromFile['sharedOptions']);
1122 if (executable.endsWith('.dart')) { 1120 if (executable.endsWith('.dart')) {
1123 // Run the compiler script via the Dart VM. 1121 // Run the compiler script via the Dart VM.
1124 args.insert(0, executable); 1122 args.insert(0, executable);
1125 executable = dartShellFileName; 1123 executable = dartShellFileName;
1126 } 1124 }
1127 return CommandBuilder.instance.getCompilationCommand( 1125 return CommandBuilder.instance.getCompilationCommand(
1128 compiler, outputFile, !useSdk, 1126 compiler, outputFile, !useSdk,
1129 dart2JsBootstrapDependencies, compilerPath, args, configurationDir); 1127 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides);
1130 } 1128 }
1131 1129
1132 /** Helper to create a Polymer deploy command for a single HTML file. */ 1130 /** Helper to create a Polymer deploy command for a single HTML file. */
1133 Command _polymerDeployCommand(String inputFile, String outputDir, 1131 Command _polymerDeployCommand(String inputFile, String outputDir,
1134 optionsFromFile) { 1132 optionsFromFile) {
1135 List<String> args = []; 1133 List<String> args = [];
1136 String packageRoot = packageRootArgument(optionsFromFile['packageRoot']); 1134 String packageRoot = packageRootArgument(optionsFromFile['packageRoot']);
1137 if (packageRoot != null) args.add(packageRoot); 1135 if (packageRoot != null) args.add(packageRoot);
1138 args..add('package:polymer/deploy.dart') 1136 args..add('package:polymer/deploy.dart')
1139 ..add('--test')..add(inputFile) 1137 ..add('--test')..add(inputFile)
1140 ..add('--out')..add(outputDir); 1138 ..add('--out')..add(outputDir);
1141 if (configuration['csp']) args.add('--csp'); 1139 if (configuration['csp']) args.add('--csp');
1142 1140
1143 return CommandBuilder.instance.getCommand( 1141 return CommandBuilder.instance.getProcessCommand(
1144 'polymer_deploy', vmFileName, args, configurationDir); 1142 'polymer_deploy', vmFileName, args, environmentOverrides);
1145 } 1143 }
1146 1144
1147 /** 1145 /**
1148 * Create a directory for the generated test. If a Dart language test 1146 * Create a directory for the generated test. If a Dart language test
1149 * needs to be run in a browser, the Dart test needs to be embedded in 1147 * needs to be run in a browser, the Dart test needs to be embedded in
1150 * an HTML page, with a testing framework based on scripting and DOM events. 1148 * an HTML page, with a testing framework based on scripting and DOM events.
1151 * These scripts and pages are written to a generated_test directory 1149 * These scripts and pages are written to a generated_test directory
1152 * inside the build directory of the checkout. 1150 * inside the build directory of the checkout.
1153 * 1151 *
1154 * Those tests which are already HTML web applications (web tests), with 1152 * Those tests which are already HTML web applications (web tests), with
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 // NOTE: We exclude tests and patch files for now. 1569 // NOTE: We exclude tests and patch files for now.
1572 return filename.endsWith(".dart") && 1570 return filename.endsWith(".dart") &&
1573 !filename.endsWith("_test.dart") && 1571 !filename.endsWith("_test.dart") &&
1574 !filename.contains("_internal/lib"); 1572 !filename.contains("_internal/lib");
1575 } 1573 }
1576 1574
1577 AnalysisCommand makeAnalysisCommand(TestInformation info, 1575 AnalysisCommand makeAnalysisCommand(TestInformation info,
1578 List<String> arguments) { 1576 List<String> arguments) {
1579 return CommandBuilder.instance.getAnalysisCommand( 1577 return CommandBuilder.instance.getAnalysisCommand(
1580 configuration['compiler'], dartShellFileName, arguments, 1578 configuration['compiler'], dartShellFileName, arguments,
1581 configurationDir, flavor: configuration['compiler']); 1579 environmentOverrides, flavor: configuration['compiler']);
1582 } 1580 }
1583 1581
1584 bool get listRecursively => true; 1582 bool get listRecursively => true;
1585 } 1583 }
1586 1584
1587 class LastModifiedCache { 1585 class LastModifiedCache {
1588 Map<String, DateTime> _cache = <String, DateTime>{}; 1586 Map<String, DateTime> _cache = <String, DateTime>{};
1589 1587
1590 /** 1588 /**
1591 * Returns the last modified date of the given [uri]. 1589 * Returns the last modified date of the given [uri].
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 * $pass tests are expected to pass 1879 * $pass tests are expected to pass
1882 * $failOk tests are expected to fail that we won't fix 1880 * $failOk tests are expected to fail that we won't fix
1883 * $fail tests are expected to fail that we should fix 1881 * $fail tests are expected to fail that we should fix
1884 * $crash tests are expected to crash that we should fix 1882 * $crash tests are expected to crash that we should fix
1885 * $timeout tests are allowed to timeout 1883 * $timeout tests are allowed to timeout
1886 * $compileErrorSkip tests are skipped on browsers due to compile-time error 1884 * $compileErrorSkip tests are skipped on browsers due to compile-time error
1887 """; 1885 """;
1888 print(report); 1886 print(report);
1889 } 1887 }
1890 } 1888 }
OLDNEW
« no previous file with comments | « dart/tools/testing/dart/test_runner.dart ('k') | dart/tools/testing/dart/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698