| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * A simple function that tests [arg] and returns `true` or `false`. | 30 * A simple function that tests [arg] and returns `true` or `false`. |
| 31 */ | 31 */ |
| 32 typedef bool Predicate<T>(T arg); | 32 typedef bool Predicate<T>(T arg); |
| 33 | 33 |
| 34 typedef void CreateTest(Path filePath, | 34 typedef void CreateTest(Path filePath, |
| 35 bool hasCompileError, | 35 bool hasCompileError, |
| 36 bool hasRuntimeError, | 36 bool hasRuntimeError, |
| 37 {bool isNegativeIfChecked, | 37 {bool isNegativeIfChecked, |
| 38 bool hasCompileErrorIfChecked, |
| 38 bool hasStaticWarning, | 39 bool hasStaticWarning, |
| 39 Set<String> multitestOutcome, | 40 Set<String> multitestOutcome, |
| 40 String multitestKey, | 41 String multitestKey, |
| 41 Path originTestPath}); | 42 Path originTestPath}); |
| 42 | 43 |
| 43 typedef void VoidFunction(); | 44 typedef void VoidFunction(); |
| 44 | 45 |
| 45 /** | 46 /** |
| 46 * Calls [function] asynchronously. Returns a future that completes with the | 47 * Calls [function] asynchronously. Returns a future that completes with the |
| 47 * result of the function. If the function is `null`, returns a future that | 48 * result of the function. If the function is `null`, returns a future that |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Test if the selector includes this test. | 309 // Test if the selector includes this test. |
| 309 RegExp pattern = configuration['selectors'][suiteName]; | 310 RegExp pattern = configuration['selectors'][suiteName]; |
| 310 if (!pattern.hasMatch(testCase.displayName)) { | 311 if (!pattern.hasMatch(testCase.displayName)) { |
| 311 return; | 312 return; |
| 312 } | 313 } |
| 313 | 314 |
| 314 // Update Summary report | 315 // Update Summary report |
| 315 if (configuration['report']) { | 316 if (configuration['report']) { |
| 316 SummaryReport.add(expectations); | 317 SummaryReport.add(expectations); |
| 317 if (testCase.info != null && | 318 if (testCase.info != null && |
| 318 testCase.info.hasCompileError && | 319 testCase.expectCompileError && |
| 319 TestUtils.isBrowserRuntime(configuration['runtime']) && | 320 TestUtils.isBrowserRuntime(configuration['runtime']) && |
| 320 configuration['compiler'] != 'none') { | 321 configuration['compiler'] != 'none') { |
| 321 SummaryReport.addCompileErrorSkipTest(); | 322 SummaryReport.addCompileErrorSkipTest(); |
| 322 return; | 323 return; |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 | 326 |
| 326 // Handle skipped tests | 327 // Handle skipped tests |
| 327 if (expectations.contains(Expectation.SKIP) || | 328 if (expectations.contains(Expectation.SKIP) || |
| 328 expectations.contains(Expectation.SKIP_BY_DESIGN)) { | 329 expectations.contains(Expectation.SKIP_BY_DESIGN)) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 601 } |
| 601 | 602 |
| 602 | 603 |
| 603 class TestInformation { | 604 class TestInformation { |
| 604 Path originTestPath; | 605 Path originTestPath; |
| 605 Path filePath; | 606 Path filePath; |
| 606 Map optionsFromFile; | 607 Map optionsFromFile; |
| 607 bool hasCompileError; | 608 bool hasCompileError; |
| 608 bool hasRuntimeError; | 609 bool hasRuntimeError; |
| 609 bool isNegativeIfChecked; | 610 bool isNegativeIfChecked; |
| 611 bool hasCompileErrorIfChecked; |
| 610 bool hasStaticWarning; | 612 bool hasStaticWarning; |
| 611 Set<String> multitestOutcome; | 613 Set<String> multitestOutcome; |
| 612 String multitestKey; | 614 String multitestKey; |
| 613 | 615 |
| 614 TestInformation(this.filePath, this.optionsFromFile, | 616 TestInformation(this.filePath, this.optionsFromFile, |
| 615 this.hasCompileError, this.hasRuntimeError, | 617 this.hasCompileError, this.hasRuntimeError, |
| 616 this.isNegativeIfChecked, this.hasStaticWarning, | 618 this.isNegativeIfChecked, this.hasCompileErrorIfChecked, |
| 619 this.hasStaticWarning, |
| 617 this.multitestOutcome, | 620 this.multitestOutcome, |
| 618 {this.multitestKey, this.originTestPath}) { | 621 {this.multitestKey, this.originTestPath}) { |
| 619 assert(filePath.isAbsolute); | 622 assert(filePath.isAbsolute); |
| 620 if (originTestPath == null) originTestPath = filePath; | 623 if (originTestPath == null) originTestPath = filePath; |
| 621 } | 624 } |
| 622 } | 625 } |
| 623 | 626 |
| 624 /** | 627 /** |
| 625 * A standard [TestSuite] implementation that searches for tests in a | 628 * A standard [TestSuite] implementation that searches for tests in a |
| 626 * directory, and creates [TestCase]s that compile and/or run them. | 629 * directory, and creates [TestCase]s that compile and/or run them. |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 if (optionsFromFile['packageRoot'] == null || | 926 if (optionsFromFile['packageRoot'] == null || |
| 924 optionsFromFile['packageRoot'] == "") { | 927 optionsFromFile['packageRoot'] == "") { |
| 925 optionsFromFile['packageRoot'] = packageRoot.toNativePath(); | 928 optionsFromFile['packageRoot'] = packageRoot.toNativePath(); |
| 926 } | 929 } |
| 927 } | 930 } |
| 928 } | 931 } |
| 929 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, | 932 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, |
| 930 multitestName: optionsFromFile['isMultitest'] ? info.multitestKey : ""); | 933 multitestName: optionsFromFile['isMultitest'] ? info.multitestKey : ""); |
| 931 | 934 |
| 932 Set<Expectation> expectations = testExpectations.expectations(testName); | 935 Set<Expectation> expectations = testExpectations.expectations(testName); |
| 933 if (configuration['compiler'] != 'none' && info.hasCompileError) { | 936 if (configuration['compiler'] != 'none' && expectCompileError(info)) { |
| 934 // If a compile-time error is expected, and we're testing a | 937 // If a compile-time error is expected, and we're testing a |
| 935 // compiler, we never need to attempt to run the program (in a | 938 // compiler, we never need to attempt to run the program (in a |
| 936 // browser or otherwise). | 939 // browser or otherwise). |
| 937 enqueueStandardTest(baseCommands, info, testName, expectations); | 940 enqueueStandardTest(baseCommands, info, testName, expectations); |
| 938 } else if (TestUtils.isBrowserRuntime(configuration['runtime'])) { | 941 } else if (TestUtils.isBrowserRuntime(configuration['runtime'])) { |
| 939 if (info.optionsFromFile['isMultiHtmlTest']) { | 942 if (info.optionsFromFile['isMultiHtmlTest']) { |
| 940 // A browser multi-test has multiple expectations for one test file. | 943 // A browser multi-test has multiple expectations for one test file. |
| 941 // Find all the different sub-test expecations for one entire test file. | 944 // Find all the different sub-test expecations for one entire test file. |
| 942 List<String> subtestNames = info.optionsFromFile['subtestNames']; | 945 List<String> subtestNames = info.optionsFromFile['subtestNames']; |
| 943 Map<String, Set<Expectation>> multiHtmlTestExpectations = {}; | 946 Map<String, Set<Expectation>> multiHtmlTestExpectations = {}; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 enqueueNewTestCase( | 982 enqueueNewTestCase( |
| 980 new TestCase('$suiteName/$testName', | 983 new TestCase('$suiteName/$testName', |
| 981 commands, | 984 commands, |
| 982 configuration, | 985 configuration, |
| 983 expectations, | 986 expectations, |
| 984 isNegative: isNegative(info), | 987 isNegative: isNegative(info), |
| 985 info: info)); | 988 info: info)); |
| 986 } | 989 } |
| 987 } | 990 } |
| 988 | 991 |
| 992 bool expectCompileError(TestInformation info) { |
| 993 return info.hasCompileError || |
| 994 (configuration['checked'] && info.hasCompileErrorIfChecked); |
| 995 } |
| 996 |
| 989 bool isNegative(TestInformation info) { | 997 bool isNegative(TestInformation info) { |
| 990 bool negative = info.hasCompileError || | 998 bool negative = expectCompileError(info) || |
| 991 (configuration['checked'] && info.isNegativeIfChecked); | 999 (configuration['checked'] && info.isNegativeIfChecked); |
| 992 if (info.hasRuntimeError && hasRuntime) { | 1000 if (info.hasRuntimeError && hasRuntime) { |
| 993 negative = true; | 1001 negative = true; |
| 994 } | 1002 } |
| 995 return negative; | 1003 return negative; |
| 996 } | 1004 } |
| 997 | 1005 |
| 998 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { | 1006 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { |
| 999 var compiler = configuration['compiler']; | 1007 var compiler = configuration['compiler']; |
| 1000 List<String> sharedOptions = info.optionsFromFile['sharedOptions']; | 1008 List<String> sharedOptions = info.optionsFromFile['sharedOptions']; |
| 1001 switch (compiler) { | 1009 switch (compiler) { |
| 1002 case 'dart2js': | 1010 case 'dart2js': |
| 1003 args = new List.from(args); | 1011 args = new List.from(args); |
| 1004 String tempDir = createCompilationOutputDirectory(info.filePath); | 1012 String tempDir = createCompilationOutputDirectory(info.filePath); |
| 1005 args.addAll(sharedOptions); | 1013 args.addAll(sharedOptions); |
| 1006 args.add('--out=$tempDir/out.js'); | 1014 args.add('--out=$tempDir/out.js'); |
| 1007 | 1015 |
| 1008 var command = CommandBuilder.instance.getCompilationCommand( | 1016 var command = CommandBuilder.instance.getCompilationCommand( |
| 1009 compiler, "$tempDir/out.js", !useSdk, | 1017 compiler, "$tempDir/out.js", !useSdk, |
| 1010 dart2JsBootstrapDependencies, compilerPath, args, | 1018 dart2JsBootstrapDependencies, compilerPath, args, |
| 1011 environmentOverrides); | 1019 environmentOverrides); |
| 1012 | 1020 |
| 1013 var javascriptFile = '$tempDir/out.js'; | 1021 var javascriptFile = '$tempDir/out.js'; |
| 1014 if (configuration['csp']) { | 1022 if (configuration['csp']) { |
| 1015 javascriptFile = '$tempDir/out.precompiled.js'; | 1023 javascriptFile = '$tempDir/out.precompiled.js'; |
| 1016 } | 1024 } |
| 1017 | 1025 |
| 1018 List<Command> commands = <Command>[command]; | 1026 List<Command> commands = <Command>[command]; |
| 1019 if (info.hasCompileError) { | 1027 if (expectCompileError(info)) { |
| 1020 // Do not attempt to run the compiled result. A compilation | 1028 // Do not attempt to run the compiled result. A compilation |
| 1021 // error should be reported by the compilation command. | 1029 // error should be reported by the compilation command. |
| 1022 } else if (configuration['runtime'] == 'd8') { | 1030 } else if (configuration['runtime'] == 'd8') { |
| 1023 commands.add(CommandBuilder.instance.getJSCommandlineCommand( | 1031 commands.add(CommandBuilder.instance.getJSCommandlineCommand( |
| 1024 "d8", d8FileName, [javascriptFile], environmentOverrides)); | 1032 "d8", d8FileName, [javascriptFile], environmentOverrides)); |
| 1025 } else if (configuration['runtime'] == 'jsshell') { | 1033 } else if (configuration['runtime'] == 'jsshell') { |
| 1026 commands.add(CommandBuilder.instance.getJSCommandlineCommand( | 1034 commands.add(CommandBuilder.instance.getJSCommandlineCommand( |
| 1027 "jsshell", jsShellFileName, [javascriptFile], | 1035 "jsshell", jsShellFileName, [javascriptFile], |
| 1028 environmentOverrides)); | 1036 environmentOverrides)); |
| 1029 } | 1037 } |
| 1030 return commands; | 1038 return commands; |
| 1031 case 'dart2dart': | 1039 case 'dart2dart': |
| 1032 args = new List.from(args); | 1040 args = new List.from(args); |
| 1033 args.addAll(sharedOptions); | 1041 args.addAll(sharedOptions); |
| 1034 args.add('--output-type=dart'); | 1042 args.add('--output-type=dart'); |
| 1035 String tempDir = createCompilationOutputDirectory(info.filePath); | 1043 String tempDir = createCompilationOutputDirectory(info.filePath); |
| 1036 args.add('--out=$tempDir/out.dart'); | 1044 args.add('--out=$tempDir/out.dart'); |
| 1037 | 1045 |
| 1038 List<Command> commands = | 1046 List<Command> commands = |
| 1039 <Command>[CommandBuilder.instance.getCompilationCommand( | 1047 <Command>[CommandBuilder.instance.getCompilationCommand( |
| 1040 compiler, "$tempDir/out.dart", !useSdk, | 1048 compiler, "$tempDir/out.dart", !useSdk, |
| 1041 dart2JsBootstrapDependencies, compilerPath, args, | 1049 dart2JsBootstrapDependencies, compilerPath, args, |
| 1042 environmentOverrides)]; | 1050 environmentOverrides)]; |
| 1043 if (info.hasCompileError) { | 1051 if (expectCompileError(info)) { |
| 1044 // Do not attempt to run the compiled result. A compilation | 1052 // Do not attempt to run the compiled result. A compilation |
| 1045 // error should be reported by the compilation command. | 1053 // error should be reported by the compilation command. |
| 1046 } else if (configuration['runtime'] == 'vm') { | 1054 } else if (configuration['runtime'] == 'vm') { |
| 1047 // TODO(antonm): support checked. | 1055 // TODO(antonm): support checked. |
| 1048 var vmArguments = new List.from(vmOptions); | 1056 var vmArguments = new List.from(vmOptions); |
| 1049 vmArguments.addAll([ | 1057 vmArguments.addAll([ |
| 1050 '--ignore-unrecognized-flags', '$tempDir/out.dart']); | 1058 '--ignore-unrecognized-flags', '$tempDir/out.dart']); |
| 1051 commands.add(CommandBuilder.instance.getVmCommand( | 1059 commands.add(CommandBuilder.instance.getVmCommand( |
| 1052 vmFileName, vmArguments, environmentOverrides)); | 1060 vmFileName, vmArguments, environmentOverrides)); |
| 1053 } else { | 1061 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1077 configuration['compiler'], dartShellFileName, arguments, | 1085 configuration['compiler'], dartShellFileName, arguments, |
| 1078 environmentOverrides, | 1086 environmentOverrides, |
| 1079 flavor: configuration['compiler']); | 1087 flavor: configuration['compiler']); |
| 1080 } | 1088 } |
| 1081 | 1089 |
| 1082 CreateTest makeTestCaseCreator(Map optionsFromFile) { | 1090 CreateTest makeTestCaseCreator(Map optionsFromFile) { |
| 1083 return (Path filePath, | 1091 return (Path filePath, |
| 1084 bool hasCompileError, | 1092 bool hasCompileError, |
| 1085 bool hasRuntimeError, | 1093 bool hasRuntimeError, |
| 1086 {bool isNegativeIfChecked: false, | 1094 {bool isNegativeIfChecked: false, |
| 1095 bool hasCompileErrorIfChecked: false, |
| 1087 bool hasStaticWarning: false, | 1096 bool hasStaticWarning: false, |
| 1088 Set<String> multitestOutcome: null, | 1097 Set<String> multitestOutcome: null, |
| 1089 String multitestKey, | 1098 String multitestKey, |
| 1090 Path originTestPath}) { | 1099 Path originTestPath}) { |
| 1091 // Cache the test information for each test case. | 1100 // Cache the test information for each test case. |
| 1092 var info = new TestInformation(filePath, | 1101 var info = new TestInformation(filePath, |
| 1093 optionsFromFile, | 1102 optionsFromFile, |
| 1094 hasCompileError, | 1103 hasCompileError, |
| 1095 hasRuntimeError, | 1104 hasRuntimeError, |
| 1096 isNegativeIfChecked, | 1105 isNegativeIfChecked, |
| 1106 hasCompileErrorIfChecked, |
| 1097 hasStaticWarning, | 1107 hasStaticWarning, |
| 1098 multitestOutcome, | 1108 multitestOutcome, |
| 1099 multitestKey: multitestKey, | 1109 multitestKey: multitestKey, |
| 1100 originTestPath: originTestPath); | 1110 originTestPath: originTestPath); |
| 1101 cachedTests.add(info); | 1111 cachedTests.add(info); |
| 1102 enqueueTestCaseFromTestInformation(info); | 1112 enqueueTestCaseFromTestInformation(info); |
| 1103 }; | 1113 }; |
| 1104 } | 1114 } |
| 1105 | 1115 |
| 1106 /** | 1116 /** |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2264 * $pass tests are expected to pass | 2274 * $pass tests are expected to pass |
| 2265 * $failOk tests are expected to fail that we won't fix | 2275 * $failOk tests are expected to fail that we won't fix |
| 2266 * $fail tests are expected to fail that we should fix | 2276 * $fail tests are expected to fail that we should fix |
| 2267 * $crash tests are expected to crash that we should fix | 2277 * $crash tests are expected to crash that we should fix |
| 2268 * $timeout tests are allowed to timeout | 2278 * $timeout tests are allowed to timeout |
| 2269 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 2279 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 2270 """; | 2280 """; |
| 2271 print(report); | 2281 print(report); |
| 2272 } | 2282 } |
| 2273 } | 2283 } |
| OLD | NEW |