Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: test/runner/tag_test.dart

Issue 1491383003: Disallow non-hyphenated-identifier tag names. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/utils.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'package:scheduled_test/descriptor.dart' as d; 7 import 'package:scheduled_test/descriptor.dart' as d;
8 import 'package:scheduled_test/scheduled_stream.dart'; 8 import 'package:scheduled_test/scheduled_stream.dart';
9 import 'package:scheduled_test/scheduled_test.dart'; 9 import 'package:scheduled_test/scheduled_test.dart';
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 var test = runTest(["-p", "vm,content-shell", "test.dart"]); 258 var test = runTest(["-p", "vm,content-shell", "test.dart"]);
259 test.stdout.expect(consumeThrough(lines( 259 test.stdout.expect(consumeThrough(lines(
260 'Warning: A tag was used that wasn\'t specified on the command ' 260 'Warning: A tag was used that wasn\'t specified on the command '
261 'line.\n' 261 'line.\n'
262 ' a was used in the test "foo"'))); 262 ' a was used in the test "foo"')));
263 test.stdout.expect(never(startsWith("Warning:"))); 263 test.stdout.expect(never(startsWith("Warning:")));
264 test.shouldExit(0); 264 test.shouldExit(0);
265 }); 265 });
266 }); 266 });
267
268 group("invalid tags", () {
269 test("are disallowed by test()", () {
270 d.file("test.dart", """
271 import 'package:test/test.dart';
272
273 void main() {
274 test("foo", () {}, tags: "a b");
275 }
276 """).create();
277
278 var test = runTest(["test.dart"]);
279 test.stdout.expect(consumeThrough(
280 ' Failed to load "test.dart": Invalid argument(s): Invalid tag "a '
281 'b". Tags must be (optionally hyphenated) Dart identifiers.'));
282 test.shouldExit(1);
283 });
284
285 test("are disallowed by group()", () {
286 d.file("test.dart", """
287 import 'package:test/test.dart';
288
289 void main() {
290 group("group", () {
291 test("foo", () {});
292 }, tags: "a b");
293 }
294 """).create();
295
296 var test = runTest(["test.dart"]);
297 test.stdout.expect(consumeThrough(
298 ' Failed to load "test.dart": Invalid argument(s): Invalid tag "a '
299 'b". Tags must be (optionally hyphenated) Dart identifiers.'));
300 test.shouldExit(1);
301 });
302
303 test("are disallowed by @Tags()", () {
304 d.file("test.dart", """
305 @Tags(const ["a b"])
306
307 import 'package:test/test.dart';
308
309 void main() {
310 test("foo", () {});
311 }
312 """).create();
313
314 var test = runTest(["test.dart"]);
315 test.stdout.expect(consumeThrough(lines(
316 ' Failed to load "test.dart":\n'
317 ' Error on line 1, column 22: Invalid tag name. Tags must be '
318 '(optionally hyphenated) Dart identifiers.')));
319 test.shouldExit(1);
320 });
321 });
267 } 322 }
268 323
269 /// Returns a [StreamMatcher] that asserts that a test emits warnings for [tags] 324 /// Returns a [StreamMatcher] that asserts that a test emits warnings for [tags]
270 /// in order. 325 /// in order.
271 StreamMatcher tagWarnings(List<String> tags) => inOrder(() sync* { 326 StreamMatcher tagWarnings(List<String> tags) => inOrder(() sync* {
272 yield consumeThrough( 327 yield consumeThrough(
273 "Warning: ${tags.length == 1 ? 'A tag was' : 'Tags were'} used that " 328 "Warning: ${tags.length == 1 ? 'A tag was' : 'Tags were'} used that "
274 "${tags.length == 1 ? "wasn't" : "weren't"} specified on the command " 329 "${tags.length == 1 ? "wasn't" : "weren't"} specified on the command "
275 "line."); 330 "line.");
276 331
277 for (var tag in tags) { 332 for (var tag in tags) {
278 yield consumeWhile(isNot(contains(" was used in"))); 333 yield consumeWhile(isNot(contains(" was used in")));
279 yield consumeThrough(startsWith(" $tag was used in")); 334 yield consumeThrough(startsWith(" $tag was used in"));
280 } 335 }
281 336
282 // Consume until the end of the warning block, and assert that it has no 337 // Consume until the end of the warning block, and assert that it has no
283 // further tags than the ones we specified. 338 // further tags than the ones we specified.
284 yield consumeWhile(isNot(anyOf([contains(" was used in"), isEmpty]))); 339 yield consumeWhile(isNot(anyOf([contains(" was used in"), isEmpty])));
285 yield isEmpty; 340 yield isEmpty;
286 }()); 341 }());
287 342
288 /// Returns a [StreamMatcher] that matches the lines of [string] in order. 343 /// Returns a [StreamMatcher] that matches the lines of [string] in order.
289 StreamMatcher lines(String string) => inOrder(string.split("\n")); 344 StreamMatcher lines(String string) => inOrder(string.split("\n"));
OLDNEW
« no previous file with comments | « lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698