Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library("corelib_test_config"); | 5 #library("co19_test_config"); |
| 6 | 6 |
| 7 #import("../../tools/testing/dart/test_runner.dart"); | 7 #import("../../tools/testing/dart/test_runner.dart"); |
| 8 #import("../../tools/testing/dart/status_file_parser.dart"); | 8 #import("../../tools/testing/dart/status_file_parser.dart"); |
| 9 | 9 |
| 10 class CorelibTestSuite { | 10 class Co19TestSuite { |
| 11 String directoryPath = "tests/corelib/src"; | 11 String directoryPath = "tests/co19/src"; |
| 12 final String statusFilePath = "tests/corelib/corelib.status"; | |
| 13 Function doTest; | 12 Function doTest; |
| 14 Function doDone; | 13 Function doDone; |
| 15 String shellPath; | 14 String shellPath; |
| 16 String pathSeparator; | 15 String pathSeparator; |
| 17 Map configuration; | 16 Map configuration; |
| 18 TestExpectationsMap testExpectationsMap; | 17 TestExpectations testExpectations; |
| 18 RegExp testRegExp; | |
| 19 | 19 |
| 20 CorelibTestSuite(Map this.configuration) { | 20 Co19TestSuite(Map this.configuration) { |
| 21 shellPath = getDartShellFileName(configuration) ; | 21 shellPath = getDartShellFileName(configuration) ; |
| 22 pathSeparator = new Platform().pathSeparator(); | 22 pathSeparator = new Platform().pathSeparator(); |
| 23 testRegExp = new RegExp(@"t[0-9]{2}.dart$"); | |
| 23 } | 24 } |
| 24 | 25 |
| 25 void forEachTest(Function onTest, [Function onDone = null]) { | 26 void forEachTest(Function onTest, [Function onDone = null]) { |
| 26 doTest = onTest; | 27 doTest = onTest; |
| 27 doDone = (ignore) => onDone(); | 28 doDone = (ignore) => onDone(); |
| 28 | 29 |
| 29 // Read test expectations from status file. | 30 // Read test expectations from status file. |
| 30 testExpectationsMap = ReadTestExpectations(statusFilePath, configuration); | 31 testExpectations = new TestExpectations(complexMatching: true); |
| 32 ReadTestExpectationsInto(testExpectations, | |
| 33 "tests/co19/co19-compiler.status", | |
| 34 configuration); | |
| 35 ReadTestExpectationsInto(testExpectations, | |
| 36 "tests/co19/co19-frog.status", | |
| 37 configuration); | |
| 38 ReadTestExpectationsInto(testExpectations, | |
| 39 "tests/co19/co19-runtime.status", | |
| 40 configuration); | |
| 31 | 41 |
| 32 processDirectory(); | 42 processDirectory(directoryPath); |
| 33 } | 43 } |
| 34 | 44 |
| 35 void processDirectory() { | 45 void processDirectory(String path) { |
| 36 directoryPath = getDirname(directoryPath); | 46 path = getDirname(path); |
| 37 Directory dir = new Directory(directoryPath); | 47 Directory dir = new Directory(path); |
| 38 dir.errorHandler = (s) { | 48 dir.errorHandler = (s) { |
| 39 throw s; | 49 throw s; |
| 40 }; | 50 }; |
| 41 dir.fileHandler = processFile; | 51 dir.fileHandler = processFile; |
| 42 dir.doneHandler = doDone; | 52 dir.doneHandler = doDone; |
| 43 dir.list(false); | 53 dir.list(recursive: true); |
| 44 } | 54 } |
| 45 | 55 |
| 46 void processFile(String filename) { | 56 void processFile(String filename) { |
| 47 if (!filename.endsWith("Test.dart")) return; | 57 if (!testRegExp.hasMatch(filename)) return; |
| 48 | 58 |
| 49 // If patterns are given only list the files that match one of the | 59 // If patterns are given only list the files that match one of the |
| 50 // patterns. | 60 // patterns. |
| 51 var patterns = configuration['patterns']; | 61 var patterns = configuration['patterns']; |
| 52 if (!patterns.isEmpty() && | 62 if (!patterns.isEmpty() && |
| 53 !patterns.some((re) => re.hasMatch(filename))) { | 63 !patterns.some((re) => re.hasMatch(filename))) { |
| 54 return; | 64 return; |
| 55 } | 65 } |
| 56 | 66 |
| 57 int start = filename.lastIndexOf(pathSeparator); | 67 int start = filename.lastIndexOf('src' + pathSeparator); |
| 58 String testName = filename.substring(start + 1, filename.length - 5); | 68 String testName = filename.substring(start + 4, filename.length - 5); |
| 59 Set<String> expectations = testExpectationsMap.expectations(testName); | 69 Set<String> expectations = testExpectations.expectations(testName); |
| 60 | 70 |
| 61 // TODO(whesse): Skip files with internal directives, and multipart files, | |
| 62 // until they are handled correctly. | |
| 63 if (expectations.contains(SKIP)) return; | 71 if (expectations.contains(SKIP)) return; |
| 64 | 72 |
| 65 List args = ["--ignore-unrecognized-flags"]; | 73 List args = ["--ignore-unrecognized-flags"]; |
| 66 if (configuration["checked"]) { | 74 if (configuration["checked"]) { |
| 67 args.add("--enable_type_checks"); | 75 args.add("--enable_type_checks"); |
| 68 } | 76 } |
| 69 if (configuration["component"] == "leg") { | 77 if (configuration["component"] == "leg") { |
| 70 args.add("--enable_leg"); | 78 args.add("--enable_leg"); |
| 71 } | 79 } |
| 72 | 80 |
| 73 var optionsFromFile = testOptions(filename); | 81 var optionsFromFile = testOptions(filename); |
| 74 List<List<String>> optionsList = optionsFromFile["vmOptions"]; | 82 List<List<String>> optionsList = optionsFromFile["vmOptions"]; |
| 75 List<String> dartOptions = optionsFromFile["dartOptions"]; | 83 List<String> dartOptions = optionsFromFile["dartOptions"]; |
| 76 args.addAll(dartOptions == null ? [filename] : dartOptions); | 84 args.addAll(dartOptions == null ? [filename] : dartOptions); |
| 85 if (optionsFromFile["isNegative"]) negateExpectations(expectations); | |
| 77 | 86 |
| 78 if (optionsList.isEmpty()) { | 87 if (optionsList.isEmpty()) { |
| 79 doTest(new TestCase(testName, | 88 doTest(new TestCase(testName, |
| 80 shellPath, | 89 shellPath, |
| 81 args, | 90 args, |
| 82 configuration["timeout"], | 91 configuration["timeout"], |
| 83 completeHandler, | 92 completeHandler, |
|
Bill Hesse
2011/11/16 11:44:27
Insert "isNegative" argument to constructor, and p
| |
| 84 expectations)); | 93 expectations)); |
| 85 } else { | 94 } else { |
| 86 for (var options in optionsList) { | 95 for (var options in optionsList) { |
| 87 options.addAll(args); | 96 options.addAll(args); |
| 88 doTest(new TestCase(testName, | 97 doTest(new TestCase(testName, |
| 89 shellPath, | 98 shellPath, |
| 90 options, | 99 options, |
| 91 configuration["timeout"], | 100 configuration["timeout"], |
| 92 completeHandler, | 101 completeHandler, |
| 93 expectations)); | 102 expectations)); |
| 94 } | 103 } |
| 95 } | 104 } |
| 96 } | 105 } |
| 97 | 106 |
| 107 | |
|
Bill Hesse
2011/11/16 11:44:27
We have handling for this in the test runner alrea
Mads Ager (google)
2011/11/16 12:26:38
Good point. Done.
| |
| 108 void negateExpectations(Set<String> expectations) { | |
| 109 if (expectations.remove(PASS)) { | |
| 110 expectations.add(FAIL); | |
| 111 } else if (expectations.remove(FAIL)) { | |
| 112 expectations.add(PASS); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 | |
| 98 Map testOptions(String filename) { | 117 Map testOptions(String filename) { |
| 99 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); | 118 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); |
| 100 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); | 119 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); |
| 101 File file = new File(filename); | 120 File file = new File(filename); |
| 102 FileInputStream fileStream = file.openInputStream(); | 121 FileInputStream fileStream = file.openInputStream(); |
| 103 StringInputStream lines = new StringInputStream(fileStream); | 122 StringInputStream lines = new StringInputStream(fileStream); |
| 104 | 123 |
| 105 List<List> result = new List<List>(); | 124 List<List> result = new List<List>(); |
| 106 List<String> dartOptions; | 125 List<String> dartOptions; |
| 126 bool isNegative = false; | |
| 107 String line; | 127 String line; |
| 108 while ((line = lines.readLine()) != null) { | 128 while ((line = lines.readLine()) != null) { |
| 109 Match match = testOptionsRegExp.firstMatch(line); | 129 Match match = testOptionsRegExp.firstMatch(line); |
| 110 if (match != null) { | 130 if (match != null) { |
| 111 result.add(match[1].split(' ').filter((e) => e != '')); | 131 result.add(match[1].split(' ').filter((e) => e != '')); |
| 112 } | 132 } |
| 113 | 133 |
| 114 match = dartOptionsRegExp.firstMatch(line); | 134 match = dartOptionsRegExp.firstMatch(line); |
| 115 if (match != null) { | 135 if (match != null) { |
| 116 if (dartOptions != null) { | 136 if (dartOptions != null) { |
| 117 throw new Exception( | 137 throw new Exception( |
| 118 'More than one "// DartOptions=" line in test $filename'); | 138 'More than one "// DartOptions=" line in test $filename'); |
| 119 } | 139 } |
| 120 dartOptions = match[1].split(' ').filter((e) => e != ''); | 140 dartOptions = match[1].split(' ').filter((e) => e != ''); |
| 121 } | 141 } |
| 142 | |
| 143 if (line.contains("@compile-error") || line.contains("@runtime-error")) { | |
| 144 isNegative = true; | |
| 145 } else if (line.contains("@dynamic-type-error") && | |
| 146 configuration['checked']) { | |
| 147 isNegative = true; | |
| 148 } | |
| 122 } | 149 } |
| 123 return {"vmOptions": result, "dartOptions": dartOptions}; | 150 return {"vmOptions": result, |
| 151 "dartOptions": dartOptions, | |
| 152 "isNegative" : isNegative }; | |
| 124 } | 153 } |
| 125 | 154 |
| 126 void completeHandler(TestCase testCase) { | 155 void completeHandler(TestCase testCase) { |
| 127 } | 156 } |
| 128 } | 157 } |
| OLD | NEW |