| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 | 172 |
| 173 class TestInformation { | 173 class TestInformation { |
| 174 String filename; | 174 String filename; |
| 175 Map optionsFromFile; | 175 Map optionsFromFile; |
| 176 bool isNegative; | 176 bool isNegative; |
| 177 bool isNegativeIfChecked; | 177 bool isNegativeIfChecked; |
| 178 bool hasFatalTypeErrors; | 178 bool hasFatalTypeErrors; |
| 179 bool hasRuntimeErrors; | 179 bool hasRuntimeErrors; |
| 180 // expected outcome from multi-test "static type error", "compile-time error"
, etc | |
| 181 String multitestOutcome; | 180 String multitestOutcome; |
| 182 | 181 |
| 183 TestInformation(this.filename, this.optionsFromFile, this.isNegative, | 182 TestInformation(this.filename, this.optionsFromFile, this.isNegative, |
| 184 this.isNegativeIfChecked, this.hasFatalTypeErrors, | 183 this.isNegativeIfChecked, this.hasFatalTypeErrors, |
| 185 this.hasRuntimeErrors, this.multitestOutcome); | 184 this.hasRuntimeErrors, this.multitestOutcome); |
| 186 } | 185 } |
| 187 | 186 |
| 188 /** | 187 /** |
| 189 * A standard [TestSuite] implementation that searches for tests in a | 188 * A standard [TestSuite] implementation that searches for tests in a |
| 190 * directory, and creates [TestCase]s that compile and/or run them. | 189 * directory, and creates [TestCase]s that compile and/or run them. |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 633 |
| 635 // Create '[build dir]/generated_tests/$component/$testUniqueName', | 634 // Create '[build dir]/generated_tests/$component/$testUniqueName', |
| 636 // including any intermediate directories that don't exist. | 635 // including any intermediate directories that don't exist. |
| 637 var generatedTestPath = ['generated_tests', | 636 var generatedTestPath = ['generated_tests', |
| 638 configuration['component'], | 637 configuration['component'], |
| 639 testUniqueName]; | 638 testUniqueName]; |
| 640 | 639 |
| 641 String tempDirPath = TestUtils.buildDir(configuration); | 640 String tempDirPath = TestUtils.buildDir(configuration); |
| 642 if (requiresCleanTemporaryDirectory) { | 641 if (requiresCleanTemporaryDirectory) { |
| 643 tempDirPath = globalTemporaryDirectory(); | 642 tempDirPath = globalTemporaryDirectory(); |
| 644 String debugMode = | 643 String debugMode = |
| 645 (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; | 644 (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; |
| 646 generatedTestPath = ['${debugMode}_${configuration["arch"]}'] | 645 generatedTestPath = ['${debugMode}_${configuration["arch"]}'] |
| 647 .addAll(generatedTestPath); | 646 .addAll(generatedTestPath); |
| 648 } | 647 } |
| 649 Directory tempDir = new Directory(tempDirPath); | 648 Directory tempDir = new Directory(tempDirPath); |
| 650 if (!tempDir.existsSync()) { | 649 if (!tempDir.existsSync()) { |
| 651 // Dartium tests can be run with no build step, with no output directory. | 650 // Dartium tests can be run with no build step, with no output directory. |
| 652 // This special case builds the build directory that should be there. | 651 // This special case builds the build directory that should be there. |
| 653 var buildPath = tempDirPath.split('/'); | 652 var buildPath = tempDirPath.split('/'); |
| 654 tempDirPath = buildPath[0]; | 653 tempDirPath = buildPath[0]; |
| 655 if (tempDirPath == '') { | 654 if (tempDirPath == '') { |
| 656 throw new Exception( | 655 throw new Exception( |
| 657 'Non-relative path to build directory in test_suite.dart'); | 656 'Non-relative path to build directory in test_suite.dart'); |
| 658 } | 657 } |
| 659 buildPath.removeRange(0, 1); | 658 buildPath.removeRange(0, 1); |
| 660 if (buildPath.last() == '') buildPath.removeLast(); | 659 if (buildPath.last() == '') buildPath.removeLast(); |
| 661 buildPath.addAll(generatedTestPath); | 660 buildPath.addAll(generatedTestPath); |
| 662 generatedTestPath = buildPath; | 661 generatedTestPath = buildPath; |
| 663 tempDir = new Directory(tempDirPath); | 662 tempDir = new Directory(tempDirPath); |
| 664 if (!tempDir.existsSync()) { | 663 if (!tempDir.existsSync()) { |
| 665 tempDir.createSync(); | 664 tempDir.createSync(); |
| 666 } | 665 } |
| 667 } | 666 } |
| 668 tempDirPath = new File(tempDirPath).fullPathSync().replaceAll('\\', '/'); | 667 tempDirPath = new File(tempDirPath).fullPathSync().replaceAll('\\', '/'); |
| 669 return TestUtils.mkdirRecursive(tempDirPath, | 668 return TestUtils.mkdirRecursive(tempDirPath, |
| 670 Strings.join(generatedTestPath, '/')); | 669 Strings.join(generatedTestPath, '/')); |
| 671 } | 670 } |
| 672 | 671 |
| 673 String get scriptType() { | 672 String get scriptType() { |
| 674 switch (configuration['component']) { | 673 switch (configuration['component']) { |
| 675 case 'dartium': | 674 case 'dartium': |
| 676 return 'application/dart'; | 675 return 'application/dart'; |
| 677 case 'chromium': | 676 case 'chromium': |
| 678 case 'frogium': | 677 case 'frogium': |
| 679 case 'legium': | 678 case 'legium': |
| 680 case 'webdriver': | 679 case 'webdriver': |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 } | 757 } |
| 759 | 758 |
| 760 return result; | 759 return result; |
| 761 } | 760 } |
| 762 | 761 |
| 763 Map readOptionsFromFile(String filename) { | 762 Map readOptionsFromFile(String filename) { |
| 764 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); | 763 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); |
| 765 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); | 764 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); |
| 766 RegExp otherScriptsRegExp = const RegExp(@"// OtherScripts=(.*)"); | 765 RegExp otherScriptsRegExp = const RegExp(@"// OtherScripts=(.*)"); |
| 767 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)"); | 766 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)"); |
| 768 RegExp staticTypeRegExp = const RegExp(@"/// ([0-9][0-9]:){0,1}\s*static typ
e error"); | 767 RegExp staticTypeRegExp = |
| 769 RegExp compileTimeRegExp = const RegExp(@"/// ([0-9][0-9]:){0,1}\s*compile-t
ime error"); | 768 const RegExp(@"/// ([0-9][0-9]:){0,1}\s*static type error"); |
| 769 RegExp compileTimeRegExp = |
| 770 const RegExp(@"/// ([0-9][0-9]:){0,1}\s*compile-time error"); |
| 770 RegExp staticCleanRegExp = const RegExp(@"// @static-clean"); | 771 RegExp staticCleanRegExp = const RegExp(@"// @static-clean"); |
| 771 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true); | 772 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true); |
| 772 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)"); | 773 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)"); |
| 773 RegExp domImportRegExp = | 774 RegExp domImportRegExp = |
| 774 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)", | 775 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)", |
| 775 multiLine: true); | 776 multiLine: true); |
| 776 RegExp libraryDefinitionRegExp = | 777 RegExp libraryDefinitionRegExp = |
| 777 const RegExp(@"^#library\(", multiLine: true); | 778 const RegExp(@"^#library\(", multiLine: true); |
| 778 RegExp sourceOrImportRegExp = | 779 RegExp sourceOrImportRegExp = |
| 779 const RegExp(@"^#(source|import)\(", multiLine: true); | 780 const RegExp(@"^#(source|import)\(", multiLine: true); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 814 } |
| 814 | 815 |
| 815 matches = staticCleanRegExp.allMatches(contents); | 816 matches = staticCleanRegExp.allMatches(contents); |
| 816 for (var match in matches) { | 817 for (var match in matches) { |
| 817 if (isStaticClean) { | 818 if (isStaticClean) { |
| 818 throw new Exception( | 819 throw new Exception( |
| 819 'More than one "// @static-clean=" line in test $filename'); | 820 'More than one "// @static-clean=" line in test $filename'); |
| 820 } | 821 } |
| 821 isStaticClean = true; | 822 isStaticClean = true; |
| 822 } | 823 } |
| 823 | 824 |
| 824 List<String> otherScripts = new List<String>(); | 825 List<String> otherScripts = new List<String>(); |
| 825 matches = otherScriptsRegExp.allMatches(contents); | 826 matches = otherScriptsRegExp.allMatches(contents); |
| 826 for (var match in matches) { | 827 for (var match in matches) { |
| 827 otherScripts.addAll(match[1].split(' ').filter((e) => e != '')); | 828 otherScripts.addAll(match[1].split(' ').filter((e) => e != '')); |
| 828 } | 829 } |
| 829 | 830 |
| 830 if (contents.contains("@compile-error") || | 831 if (contents.contains("@compile-error") || |
| 831 contents.contains("@runtime-error")) { | 832 contents.contains("@runtime-error")) { |
| 832 isNegative = true; | 833 isNegative = true; |
| 833 } | 834 } |
| 834 | 835 |
| 835 bool isMultitest = multiTestRegExp.hasMatch(contents); | 836 bool isMultitest = multiTestRegExp.hasMatch(contents); |
| 836 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents); | 837 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents); |
| 837 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); | 838 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); |
| 838 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; | 839 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; |
| 839 bool containsDomImport = domImportRegExp.hasMatch(contents); | 840 bool containsDomImport = domImportRegExp.hasMatch(contents); |
| 840 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); | 841 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); |
| 841 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); | 842 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); |
| 842 int numStaticTypeAnnotations = 0; | 843 int numStaticTypeAnnotations = 0; |
| 843 for (var i in staticTypeRegExp.allMatches(contents)) { | 844 for (var i in staticTypeRegExp.allMatches(contents)) { |
| 844 numStaticTypeAnnotations++; | 845 numStaticTypeAnnotations++; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar', | 1028 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar', |
| 1028 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar', | 1029 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar', |
| 1029 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', | 1030 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', |
| 1030 '$dartDir/third_party/junit/v4_8_2/junit.jar'], | 1031 '$dartDir/third_party/junit/v4_8_2/junit.jar'], |
| 1031 ':'); // Path separator. | 1032 ':'); // Path separator. |
| 1032 } | 1033 } |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 | 1036 |
| 1036 class TestUtils { | 1037 class TestUtils { |
| 1037 | 1038 /** |
| 1038 /** | 1039 * Creates a directory using a [relativePath] to an existing |
| 1039 * Creates a directory using a [relativePath] to an existing | |
| 1040 * [base] directory if that [relativePath] does not already exist. | 1040 * [base] directory if that [relativePath] does not already exist. |
| 1041 */ | 1041 */ |
| 1042 static Directory mkdirRecursive(String base, String relativePath) { | 1042 static Directory mkdirRecursive(String base, String relativePath) { |
| 1043 Directory baseDir = new Directory(base); | 1043 Directory baseDir = new Directory(base); |
| 1044 Expect.isTrue(baseDir.existsSync(), | 1044 Expect.isTrue(baseDir.existsSync(), |
| 1045 "Expected ${base} to already exist"); | 1045 "Expected ${base} to already exist"); |
| 1046 var tempDir = new Directory(base); | 1046 var tempDir = new Directory(base); |
| 1047 for (String dir in relativePath.split('/')) { | 1047 for (String dir in relativePath.split('/')) { |
| 1048 base = "$base/$dir"; | 1048 base = "$base/$dir"; |
| 1049 tempDir = new Directory(base); | 1049 tempDir = new Directory(base); |
| 1050 if (!tempDir.existsSync()) { | 1050 if (!tempDir.existsSync()) { |
| 1051 tempDir.createSync(); | 1051 tempDir.createSync(); |
| 1052 } | 1052 } |
| 1053 Expect.isTrue(tempDir.existsSync(), "Failed to create ${tempDir.path}"); | 1053 Expect.isTrue(tempDir.existsSync(), "Failed to create ${tempDir.path}"); |
| 1054 } | 1054 } |
| 1055 return tempDir; | 1055 return tempDir; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 /** | 1058 /** |
| 1059 * Copy a [source] file to a new place. | 1059 * Copy a [source] file to a new place. |
| 1060 * Assumes that the directory for [dest] already exists. | 1060 * Assumes that the directory for [dest] already exists. |
| 1061 */ | 1061 */ |
| 1062 static void copyFile(File source, File dest) { | 1062 static void copyFile(File source, File dest) { |
| 1063 List contents = source.readAsBytesSync(); | 1063 List contents = source.readAsBytesSync(); |
| 1064 RandomAccessFile handle = dest.openSync(FileMode.WRITE); | 1064 RandomAccessFile handle = dest.openSync(FileMode.WRITE); |
| 1065 handle.writeListSync(contents, 0, contents.length); | 1065 handle.writeListSync(contents, 0, contents.length); |
| 1066 handle.closeSync(); | 1066 handle.closeSync(); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 static String executableSuffix(String component) { | 1069 static String executableSuffix(String component) { |
| 1070 if (new Platform().operatingSystem() == 'windows') { | 1070 if (new Platform().operatingSystem() == 'windows') { |
| 1071 if (component != 'frogium' | 1071 if (component != 'frogium' |
| 1072 && component != 'legium' | 1072 && component != 'legium' |
| 1073 && component != 'webdriver') { | 1073 && component != 'webdriver') { |
| 1074 return '.exe'; | 1074 return '.exe'; |
| 1075 } else { | 1075 } else { |
| 1076 return '.bat'; | 1076 return '.bat'; |
| 1077 } | 1077 } |
| 1078 } | 1078 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 * $noCrash tests are expected to be flaky but not crash | 1216 * $noCrash tests are expected to be flaky but not crash |
| 1217 * $pass tests are expected to pass | 1217 * $pass tests are expected to pass |
| 1218 * $failOk tests are expected to fail that we won't fix | 1218 * $failOk tests are expected to fail that we won't fix |
| 1219 * $fail tests are expected to fail that we should fix | 1219 * $fail tests are expected to fail that we should fix |
| 1220 * $crash tests are expected to crash that we should fix | 1220 * $crash tests are expected to crash that we should fix |
| 1221 * $timeout tests are allowed to timeout | 1221 * $timeout tests are allowed to timeout |
| 1222 """; | 1222 """; |
| 1223 print(report); | 1223 print(report); |
| 1224 } | 1224 } |
| 1225 } | 1225 } |
| OLD | NEW |