| 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 #library("multitest"); | 5 #library("multitest"); |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("test_suite.dart"); | 8 #import("test_suite.dart"); |
| 9 | 9 |
| 10 // Multitests are Dart test scripts containing lines of the form | 10 // Multitests are Dart test scripts containing lines of the form |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // time we see a multitest line with a new key. | 84 // time we see a multitest line with a new key. |
| 85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); | 85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); |
| 86 | 86 |
| 87 int lineCount = 0; | 87 int lineCount = 0; |
| 88 for (String line in lines) { | 88 for (String line in lines) { |
| 89 lineCount++; | 89 lineCount++; |
| 90 var annotation = new _Annotation.from(line); | 90 var annotation = new _Annotation.from(line); |
| 91 if (annotation != null) { | 91 if (annotation != null) { |
| 92 testsAsLines.putIfAbsent(annotation.key, | 92 testsAsLines.putIfAbsent(annotation.key, |
| 93 () => new List<String>.from(testTemplate)).add(line); | 93 () => new List<String>.from(testTemplate)).add(line); |
| 94 outcomes.putIfAbsent(annotation.key, | 94 outcomes.putIfAbsent(annotation.key, |
| 95 () => new Set<String>()); | 95 () => new Set<String>()); |
| 96 if (annotation.rest == 'continued') { | 96 if (annotation.rest == 'continued') { |
| 97 continue; | 97 continue; |
| 98 } else { | 98 } else { |
| 99 for (String nextOutcome in annotation.outcomesList) { | 99 for (String nextOutcome in annotation.outcomesList) { |
| 100 outcomes[annotation.key].add(nextOutcome); | 100 outcomes[annotation.key].add(nextOutcome); |
| 101 if (!validMultitestOutcomes.contains(nextOutcome)) { | 101 if (!validMultitestOutcomes.contains(nextOutcome)) { |
| 102 // TODO(zundel): fix long line | 102 // TODO(zundel): fix long line |
| 103 Expect.fail( | 103 Expect.fail( |
| 104 "Invalid test directive '$nextOutcome' on line ${lineCount}: ${ann
otation.rest} "); | 104 "Invalid test directive '$nextOutcome' on line ${lineCount}: ${ann
otation.rest} "); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } else { | 108 } else { |
| 109 testTemplate.add(line); | 109 testTemplate.add(line); |
| 110 for (var test in testsAsLines.getValues()) test.add(line); | 110 for (var test in testsAsLines.getValues()) test.add(line); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Check that every key (other than the none case) has at least one outcome | 114 // Check that every key (other than the none case) has at least one outcome |
| 115 for (var outcomeKey in outcomes.getKeys()) { | 115 for (var outcomeKey in outcomes.getKeys()) { |
| 116 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty()) { | 116 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty()) { |
| 117 // TODO(zundel): fix long line | 117 // TODO(zundel): fix long line |
| 118 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes. Expected
one of: ${validMultitestOutcomes.toString()}"); | 118 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes. Expected
one of: ${validMultitestOutcomes.toString()}"); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Add the template, with no multitest lines, as a test with key 'none'. | 122 // Add the template, with no multitest lines, as a test with key 'none'. |
| 123 testsAsLines['none'] = testTemplate; | 123 testsAsLines['none'] = testTemplate; |
| 124 outcomes['none'] = new Set<String>(); | 124 outcomes['none'] = new Set<String>(); |
| 125 | 125 |
| 126 // Copy all the tests into the output map tests, as multiline strings. | 126 // Copy all the tests into the output map tests, as multiline strings. |
| 127 for (String key in testsAsLines.getKeys()) { | 127 for (String key in testsAsLines.getKeys()) { |
| 128 tests[key] = | 128 tests[key] = |
| 129 Strings.join(testsAsLines[key], line_separator) + line_separator; | 129 Strings.join(testsAsLines[key], line_separator).concat(line_separator); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Represents a mutlitest annotation in the special /// comment. | 133 // Represents a mutlitest annotation in the special /// comment. |
| 134 class _Annotation { | 134 class _Annotation { |
| 135 String key; | 135 String key; |
| 136 String rest; | 136 String rest; |
| 137 List<String> outcomesList; | 137 List<String> outcomesList; |
| 138 _Annotation() {} | 138 _Annotation() {} |
| 139 factory _Annotation.from(String line) { | 139 factory _Annotation.from(String line) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // TestSuite.forDirectory. | 268 // TestSuite.forDirectory. |
| 269 split.removeLast(); | 269 split.removeLast(); |
| 270 } | 270 } |
| 271 String path = '${generatedTestDir.path}/${split.last()}'; | 271 String path = '${generatedTestDir.path}/${split.last()}'; |
| 272 Directory dir = new Directory(path); | 272 Directory dir = new Directory(path); |
| 273 if (!dir.existsSync()) { | 273 if (!dir.existsSync()) { |
| 274 dir.createSync(); | 274 dir.createSync(); |
| 275 } | 275 } |
| 276 return path; | 276 return path; |
| 277 } | 277 } |
| OLD | NEW |