OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 @TestOn("vm") |
| 6 |
| 7 import 'package:scheduled_test/descriptor.dart' as d; |
| 8 import 'package:scheduled_test/scheduled_stream.dart'; |
| 9 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 |
| 11 import '../io.dart'; |
| 12 |
| 13 void main() { |
| 14 useSandbox(); |
| 15 |
| 16 var testRun; |
| 17 |
| 18 /// [warnings] contains pairs, each containing a comma-separated list of |
| 19 /// tags the warning is about and the test name. |
| 20 expectTagWarnings(List<List<String>> warnings) { |
| 21 for (var warning in warnings) { |
| 22 testRun.stderr.expect(consumeThrough(contains( |
| 23 "WARNING: unrecognized tags {${warning[0]}}" |
| 24 " in test '${warning[1]}'"))); |
| 25 } |
| 26 testRun.stderr.expect(isDone); |
| 27 } |
| 28 |
| 29 group("--tags", () { |
| 30 setUp(() { |
| 31 d.file("test.dart", """ |
| 32 import 'package:test/test.dart'; |
| 33 |
| 34 void main() { |
| 35 test("no tags", () {}); |
| 36 test("a", () {}, tags: "a"); |
| 37 test("b", () {}, tags: "b"); |
| 38 test("bc", () {}, tags: "b,c"); |
| 39 } |
| 40 """).create(); |
| 41 }); |
| 42 |
| 43 test("runs all tests when no tags are specified", () { |
| 44 testRun = runTest(["test.dart"]); |
| 45 testRun.stdout.expect(consumeThrough(contains("+4: All tests passed!"))); |
| 46 expectTagWarnings([ |
| 47 ['a', 'a'], |
| 48 ['b', 'b'], |
| 49 ['b, c', 'bc'], |
| 50 ]); |
| 51 testRun.shouldExit(0); |
| 52 }); |
| 53 |
| 54 test("runs only tests containing specified tags", () { |
| 55 testRun = runTest(["--tags=a", "test.dart"]); |
| 56 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 57 expectTagWarnings([ |
| 58 ['b', 'b'], |
| 59 ['b, c', 'bc'], |
| 60 ]); |
| 61 testRun.shouldExit(0); |
| 62 }); |
| 63 |
| 64 test("runs tests with tags intersecting command-line tags", () { |
| 65 testRun = runTest(["--tags=c", "test.dart"]); |
| 66 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 67 expectTagWarnings([ |
| 68 ['a', 'a'], |
| 69 ['b', 'b'], |
| 70 ['b', 'bc'], |
| 71 ]); |
| 72 testRun.shouldExit(0); |
| 73 }); |
| 74 |
| 75 test("ignores tag set difference", () { |
| 76 testRun = runTest(["--tags=b,z", "test.dart"]); |
| 77 testRun.stdout.expect(consumeThrough(contains("+2: All tests passed!"))); |
| 78 expectTagWarnings([ |
| 79 ['a', 'a'], |
| 80 ['c', 'bc'], |
| 81 ]); |
| 82 testRun.shouldExit(0); |
| 83 }); |
| 84 |
| 85 test("prints no warnings when all tags are specified", () { |
| 86 testRun = runTest(["--tags=a,b,c", "test.dart"]); |
| 87 testRun.stdout.expect(consumeThrough(contains("+3: All tests passed!"))); |
| 88 expectTagWarnings([]); |
| 89 testRun.shouldExit(0); |
| 90 }); |
| 91 }); |
| 92 |
| 93 group("--tag aliases", () { |
| 94 setUp(() { |
| 95 d.file("test.dart", """ |
| 96 import 'package:test/test.dart'; |
| 97 |
| 98 void main() { |
| 99 test("no tags", () {}); |
| 100 test("a", () {}, tags: "a"); |
| 101 } |
| 102 """).create(); |
| 103 }); |
| 104 |
| 105 test("takes -t abbreviation", () { |
| 106 testRun = runTest(["-t", "a", "test.dart"]); |
| 107 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 108 testRun.shouldExit(0); |
| 109 }); |
| 110 |
| 111 test("takes --tag typo", () { |
| 112 testRun = runTest(["--tag=a", "test.dart"]); |
| 113 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 114 testRun.shouldExit(0); |
| 115 }); |
| 116 }); |
| 117 |
| 118 group("--exclude-tags", () { |
| 119 setUp(() { |
| 120 d.file("test.dart", """ |
| 121 import 'package:test/test.dart'; |
| 122 |
| 123 void main() { |
| 124 test("no tags", () {}); |
| 125 test("a", () {}, tags: "a"); |
| 126 test("b", () {}, tags: "b"); |
| 127 test("bc", () {}, tags: "b,c"); |
| 128 } |
| 129 """).create(); |
| 130 }); |
| 131 |
| 132 test("excludes tests containing excluded tags", () { |
| 133 testRun = runTest(["--exclude-tags=a", "test.dart"]); |
| 134 testRun.stdout.expect(consumeThrough(contains("+3: All tests passed!"))); |
| 135 expectTagWarnings([ |
| 136 ['b', 'b'], |
| 137 ['b, c', 'bc'], |
| 138 ]); |
| 139 testRun.shouldExit(0); |
| 140 }); |
| 141 |
| 142 test("ignores tag set difference", () { |
| 143 testRun = runTest(["--exclude-tags=b,z", "test.dart"]); |
| 144 testRun.stdout.expect(consumeThrough(contains("+2: All tests passed!"))); |
| 145 expectTagWarnings([ |
| 146 ['a', 'a'], |
| 147 ['c', 'bc'], |
| 148 ]); |
| 149 testRun.shouldExit(0); |
| 150 }); |
| 151 |
| 152 test("excludes tests that intersect excluded tags", () { |
| 153 testRun = runTest(["--exclude-tags=c", "test.dart"]); |
| 154 testRun.stdout.expect(consumeThrough(contains("+3: All tests passed!"))); |
| 155 expectTagWarnings([ |
| 156 ['a', 'a'], |
| 157 ['b', 'b'], |
| 158 ['b', 'bc'], |
| 159 ]); |
| 160 testRun.shouldExit(0); |
| 161 }); |
| 162 |
| 163 test("prints no warnings when all tags are specified", () { |
| 164 testRun = runTest(["--exclude-tags=a,b,c", "test.dart"]); |
| 165 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 166 expectTagWarnings([]); |
| 167 testRun.shouldExit(0); |
| 168 }); |
| 169 }); |
| 170 |
| 171 group("tagged groups", () { |
| 172 setUp(() { |
| 173 d.file("test.dart", """ |
| 174 import 'package:test/test.dart'; |
| 175 |
| 176 void main() { |
| 177 group("a", () { |
| 178 test("foo", () {}); |
| 179 }, tags: "a"); |
| 180 } |
| 181 """).create(); |
| 182 }); |
| 183 |
| 184 test("excludes tags specified on the group", () { |
| 185 testRun = runTest(["-x", "a", "test.dart"]); |
| 186 testRun.stdout.expect(consumeThrough(contains("No tests ran"))); |
| 187 testRun.shouldExit(0); |
| 188 }); |
| 189 }); |
| 190 |
| 191 group("--exclude-tags aliases", () { |
| 192 setUp(() { |
| 193 d.file("test.dart", """ |
| 194 import 'package:test/test.dart'; |
| 195 |
| 196 void main() { |
| 197 test("no tags", () {}); |
| 198 test("a", () {}, tags: "a"); |
| 199 } |
| 200 """).create(); |
| 201 }); |
| 202 |
| 203 test("takes -x abbreviation", () { |
| 204 testRun = runTest(["-x", "a", "test.dart"]); |
| 205 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 206 testRun.shouldExit(0); |
| 207 }); |
| 208 |
| 209 test("takes --exclude-tag typo", () { |
| 210 testRun = runTest(["--exclude-tag=a", "test.dart"]); |
| 211 testRun.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); |
| 212 testRun.shouldExit(0); |
| 213 }); |
| 214 }); |
| 215 |
| 216 group('interaction between --tags and --exclude-tags', () { |
| 217 test('refuses include and exclude the same tag simultaneously', () { |
| 218 d.file("test.dart", """ |
| 219 import 'package:test/test.dart'; |
| 220 |
| 221 void main() { |
| 222 test("foo", () {}); |
| 223 } |
| 224 """).create(); |
| 225 |
| 226 testRun = runTest(["-t", "a,b", "-x", "a,b,c", "test.dart"]); |
| 227 testRun.stderr.expect(consumeThrough( |
| 228 contains("Included and excluded tag sets may not intersect. " |
| 229 "Found intersection: a, b"))); |
| 230 testRun.stderr.expect(consumeThrough(contains("Usage:"))); |
| 231 testRun.shouldExit(64); |
| 232 }); |
| 233 |
| 234 test("--exclude-tags takes precedence over --tags", () { |
| 235 d.file("test.dart", """ |
| 236 import 'package:test/test.dart'; |
| 237 |
| 238 void main() { |
| 239 test("ab", () {}, tags: ["a", "b"]); |
| 240 } |
| 241 """).create(); |
| 242 |
| 243 testRun = runTest(["-t", "a", "-x", "b", "test.dart"]); |
| 244 testRun.stdout.expect(consumeThrough(contains("No tests ran"))); |
| 245 testRun.shouldExit(0); |
| 246 }); |
| 247 }); |
| 248 |
| 249 group('@Tags annotation', () { |
| 250 test('applies tags to the suite', () { |
| 251 d.file("test.dart", """ |
| 252 @Tags(const ['a']) |
| 253 import 'package:test/test.dart'; |
| 254 |
| 255 void main() { |
| 256 test("foo", () {}, tags: "b"); |
| 257 } |
| 258 """).create(); |
| 259 |
| 260 testRun = runTest(["-x", "a", "test.dart"]); |
| 261 testRun.stdout.expect(consumeThrough(contains("No tests ran"))); |
| 262 testRun.shouldExit(0); |
| 263 }); |
| 264 |
| 265 test('parses a string into a tag', () { |
| 266 d.file("test.dart", """ |
| 267 @Tags('a') |
| 268 import 'package:test/test.dart'; |
| 269 |
| 270 void main() { |
| 271 test("foo", () {}, tags: "b"); |
| 272 } |
| 273 """).create(); |
| 274 |
| 275 testRun = runTest(["-x", "a", "test.dart"]); |
| 276 testRun.stdout.expect(consumeThrough(contains("No tests ran"))); |
| 277 testRun.shouldExit(0); |
| 278 }); |
| 279 |
| 280 test('refuses bad arguments', () { |
| 281 d.file("test.dart", """ |
| 282 @Tags(1) |
| 283 import 'package:test/test.dart'; |
| 284 |
| 285 void main() {} |
| 286 """).create(); |
| 287 |
| 288 testRun = runTest(["test.dart"]); |
| 289 testRun.stdout.expect(consumeThrough( |
| 290 contains("Only String or List literal allowed as @Tags argument"))); |
| 291 testRun.shouldExit(1); |
| 292 }); |
| 293 }); |
| 294 } |
OLD | NEW |