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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, | 704 String testName = buildTestCaseDisplayName(suiteDir, info.originTestPath, |
705 multitestName: optionsFromFile['isMultitest'] ? info.multitestKey : ""); | 705 multitestName: optionsFromFile['isMultitest'] ? info.multitestKey : ""); |
706 | 706 |
707 Set<Expectation> expectations = testExpectations.expectations(testName); | 707 Set<Expectation> expectations = testExpectations.expectations(testName); |
708 if (configuration['compiler'] != 'none' && info.hasCompileError) { | 708 if (configuration['compiler'] != 'none' && info.hasCompileError) { |
709 // If a compile-time error is expected, and we're testing a | 709 // If a compile-time error is expected, and we're testing a |
710 // compiler, we never need to attempt to run the program (in a | 710 // compiler, we never need to attempt to run the program (in a |
711 // browser or otherwise). | 711 // browser or otherwise). |
712 enqueueStandardTest(info, testName, expectations); | 712 enqueueStandardTest(info, testName, expectations); |
713 } else if (TestUtils.isBrowserRuntime(configuration['runtime'])) { | 713 } else if (TestUtils.isBrowserRuntime(configuration['runtime'])) { |
714 bool isWrappingRequired = configuration['compiler'] != 'dart2js'; | |
715 | |
716 if (info.optionsFromFile['isMultiHtmlTest']) { | 714 if (info.optionsFromFile['isMultiHtmlTest']) { |
717 // A browser multi-test has multiple expectations for one test file. | 715 // A browser multi-test has multiple expectations for one test file. |
718 // Find all the different sub-test expecations for one entire test file. | 716 // Find all the different sub-test expecations for one entire test file. |
719 List<String> subtestNames = info.optionsFromFile['subtestNames']; | 717 List<String> subtestNames = info.optionsFromFile['subtestNames']; |
720 Map<String, Set<Expectation>> multiHtmlTestExpectations = {}; | 718 Map<String, Set<Expectation>> multiHtmlTestExpectations = {}; |
721 for (String name in subtestNames) { | 719 for (String name in subtestNames) { |
722 String fullTestName = '$testName/$name'; | 720 String fullTestName = '$testName/$name'; |
723 multiHtmlTestExpectations[fullTestName] = | 721 multiHtmlTestExpectations[fullTestName] = |
724 testExpectations.expectations(fullTestName); | 722 testExpectations.expectations(fullTestName); |
725 } | 723 } |
726 enqueueBrowserTest(info, testName, multiHtmlTestExpectations, | 724 enqueueBrowserTest(info, testName, multiHtmlTestExpectations); |
727 isWrappingRequired); | |
728 } else { | 725 } else { |
729 enqueueBrowserTest(info, testName, expectations, isWrappingRequired); | 726 enqueueBrowserTest(info, testName, expectations); |
730 } | 727 } |
731 } else { | 728 } else { |
732 enqueueStandardTest(info, testName, expectations); | 729 enqueueStandardTest(info, testName, expectations); |
733 } | 730 } |
734 } | 731 } |
735 | 732 |
736 void enqueueStandardTest(TestInformation info, | 733 void enqueueStandardTest(TestInformation info, |
737 String testName, | 734 String testName, |
738 Set<Expectation> expectations) { | 735 Set<Expectation> expectations) { |
739 var commonArguments = commonArgumentsFromFile(info.filePath, | 736 var commonArguments = commonArgumentsFromFile(info.filePath, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 var localIp = configuration['local_ip']; | 909 var localIp = configuration['local_ip']; |
913 var url= 'http://$localIp:$serverPort$pathComponent' | 910 var url= 'http://$localIp:$serverPort$pathComponent' |
914 '?crossOriginPort=$crossOriginPort'; | 911 '?crossOriginPort=$crossOriginPort'; |
915 if (info.optionsFromFile['isMultiHtmlTest'] && subtestNames.length > 0) { | 912 if (info.optionsFromFile['isMultiHtmlTest'] && subtestNames.length > 0) { |
916 url= '${url}&group=${subtestNames[subtestIndex]}'; | 913 url= '${url}&group=${subtestNames[subtestIndex]}'; |
917 } | 914 } |
918 return url; | 915 return url; |
919 } | 916 } |
920 | 917 |
921 void _createWrapperFile(String dartWrapperFilename, | 918 void _createWrapperFile(String dartWrapperFilename, |
922 Path dartLibraryFilename, | 919 Path dartLibraryFilename) { |
923 {bool useUnittestWrapper: false}) { | |
924 File file = new File(dartWrapperFilename); | 920 File file = new File(dartWrapperFilename); |
925 RandomAccessFile dartWrapper = file.openSync(mode: FileMode.WRITE); | 921 RandomAccessFile dartWrapper = file.openSync(mode: FileMode.WRITE); |
926 | 922 |
927 var usePackageImport = dartLibraryFilename.segments().contains("pkg"); | 923 var usePackageImport = dartLibraryFilename.segments().contains("pkg"); |
928 var libraryPathComponent = _createUrlPathFromFile(dartLibraryFilename); | 924 var libraryPathComponent = _createUrlPathFromFile(dartLibraryFilename); |
929 var generatedSource; | 925 var generatedSource = dartTestWrapper(libraryPathComponent); |
930 if (useUnittestWrapper) { | |
931 // FIXME(kustermann): This is broken, we can't do unittest-based wrapping | |
932 // of tests (e.g. async operations are not wrapped in expectAsync()). | |
933 generatedSource = dartUnittestWrapper(usePackageImport, | |
934 libraryPathComponent); | |
935 } else { | |
936 generatedSource = dartTestWrapper(libraryPathComponent); | |
937 } | |
938 | |
939 dartWrapper.writeStringSync(generatedSource); | 926 dartWrapper.writeStringSync(generatedSource); |
940 dartWrapper.closeSync(); | 927 dartWrapper.closeSync(); |
941 } | 928 } |
942 | 929 |
943 /** | 930 /** |
944 * The [StandardTestSuite] has support for tests that | 931 * The [StandardTestSuite] has support for tests that |
945 * compile a test from Dart to JavaScript, and then run the resulting | 932 * compile a test from Dart to JavaScript, and then run the resulting |
946 * JavaScript. This function creates a working directory to hold the | 933 * JavaScript. This function creates a working directory to hold the |
947 * JavaScript version of the test, and copies the appropriate framework | 934 * JavaScript version of the test, and copies the appropriate framework |
948 * files to that directory. It creates a [BrowserTestCase], which has | 935 * files to that directory. It creates a [BrowserTestCase], which has |
949 * two sequential steps to be run by the [ProcessQueue] when the test is | 936 * two sequential steps to be run by the [ProcessQueue] when the test is |
950 * executed: a compilation step and an execution step, both with the | 937 * executed: a compilation step and an execution step, both with the |
951 * appropriate executable and arguments. The [expectations] object can be | 938 * appropriate executable and arguments. The [expectations] object can be |
952 * either a Set<String> if the test is a regular test, or a Map<String | 939 * either a Set<String> if the test is a regular test, or a Map<String |
953 * subTestName, Set<String>> if we are running a browser multi-test (one | 940 * subTestName, Set<String>> if we are running a browser multi-test (one |
954 * compilation and many browser runs). | 941 * compilation and many browser runs). |
955 */ | 942 */ |
956 void enqueueBrowserTest(TestInformation info, | 943 void enqueueBrowserTest(TestInformation info, |
957 String testName, | 944 String testName, |
958 expectations, | 945 expectations) { |
959 bool isWrappingRequired) { | |
960 // TODO(kustermann/ricow): This method should be refactored. | 946 // TODO(kustermann/ricow): This method should be refactored. |
961 Map optionsFromFile = info.optionsFromFile; | 947 Map optionsFromFile = info.optionsFromFile; |
962 Path filePath = info.filePath; | 948 Path filePath = info.filePath; |
963 String filename = filePath.toString(); | 949 String filename = filePath.toString(); |
964 bool isWebTest = optionsFromFile['containsDomImport']; | |
965 | 950 |
966 final String compiler = configuration['compiler']; | 951 final String compiler = configuration['compiler']; |
967 final String runtime = configuration['runtime']; | 952 final String runtime = configuration['runtime']; |
968 | 953 |
969 for (var vmOptions in getVmOptions(optionsFromFile)) { | 954 for (var vmOptions in getVmOptions(optionsFromFile)) { |
970 // Create a unique temporary directory for each set of vmOptions. | 955 // Create a unique temporary directory for each set of vmOptions. |
971 // TODO(dart:429): Replace separate replaceAlls with a RegExp when | 956 // TODO(dart:429): Replace separate replaceAlls with a RegExp when |
972 // replaceAll(RegExp, String) is implemented. | 957 // replaceAll(RegExp, String) is implemented. |
973 String optionsName = ''; | 958 String optionsName = ''; |
974 if (getVmOptions(optionsFromFile).length > 1) { | 959 if (getVmOptions(optionsFromFile).length > 1) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 if (configuration['csp']) { | 1015 if (configuration['csp']) { |
1031 jsFile = '$nameNoExt.precompiled.js'; | 1016 jsFile = '$nameNoExt.precompiled.js'; |
1032 } | 1017 } |
1033 htmlContents = htmlContents.replaceAll('%TEST_SCRIPTS%', | 1018 htmlContents = htmlContents.replaceAll('%TEST_SCRIPTS%', |
1034 '<script src="$jsFile"></script>'); | 1019 '<script src="$jsFile"></script>'); |
1035 } | 1020 } |
1036 new File(htmlPath).writeAsStringSync(htmlContents); | 1021 new File(htmlPath).writeAsStringSync(htmlContents); |
1037 } | 1022 } |
1038 } else { | 1023 } else { |
1039 htmlPath = '$tempDir/test.html'; | 1024 htmlPath = '$tempDir/test.html'; |
1040 if (isWrappingRequired && !isWebTest) { | 1025 if (configuration['compiler'] != 'dart2js') { |
1041 // test.dart will import the dart test. | 1026 // test.dart will import the dart test. |
1042 if (configuration['use_browser_controller'] && | 1027 _createWrapperFile(dartWrapperFilename, filePath); |
1043 configuration['runtime'] == 'dartium') { | |
1044 _createWrapperFile(dartWrapperFilename, filePath); | |
1045 } else { | |
1046 _createWrapperFile( | |
1047 dartWrapperFilename, filePath, useUnittestWrapper: true); | |
1048 } | |
1049 } else { | 1028 } else { |
1050 dartWrapperFilename = filename; | 1029 dartWrapperFilename = filename; |
1051 } | 1030 } |
1052 | 1031 |
1053 // Create the HTML file for the test. | 1032 // Create the HTML file for the test. |
1054 RandomAccessFile htmlTest = | 1033 RandomAccessFile htmlTest = |
1055 new File(htmlPath).openSync(mode: FileMode.WRITE); | 1034 new File(htmlPath).openSync(mode: FileMode.WRITE); |
1056 | 1035 |
1057 String scriptPath = dartWrapperFilename; | 1036 String scriptPath = dartWrapperFilename; |
1058 if (compiler != 'none') { | 1037 if (compiler != 'none') { |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2060 * $pass tests are expected to pass | 2039 * $pass tests are expected to pass |
2061 * $failOk tests are expected to fail that we won't fix | 2040 * $failOk tests are expected to fail that we won't fix |
2062 * $fail tests are expected to fail that we should fix | 2041 * $fail tests are expected to fail that we should fix |
2063 * $crash tests are expected to crash that we should fix | 2042 * $crash tests are expected to crash that we should fix |
2064 * $timeout tests are allowed to timeout | 2043 * $timeout tests are allowed to timeout |
2065 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 2044 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
2066 """; | 2045 """; |
2067 print(report); | 2046 print(report); |
2068 } | 2047 } |
2069 } | 2048 } |
OLD | NEW |