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

Side by Side Diff: lib/src/runner/parse_metadata.dart

Issue 1405633004: feature: tag tests; choose tags on command line Base URL: git@github.com:yjbanov/test.git@tags
Patch Set: address comments 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/runner/configuration.dart ('k') | lib/src/utils.dart » ('j') | 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 library test.runner.parse_metadata; 5 library test.runner.parse_metadata;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return directive.prefix.name; 48 return directive.prefix.name;
49 }).where((prefix) => prefix != null).toSet(); 49 }).where((prefix) => prefix != null).toSet();
50 } 50 }
51 51
52 /// Parses the metadata. 52 /// Parses the metadata.
53 Metadata parse() { 53 Metadata parse() {
54 var timeout; 54 var timeout;
55 var testOn; 55 var testOn;
56 var skip; 56 var skip;
57 var onPlatform; 57 var onPlatform;
58 var tags;
58 59
59 for (var annotation in _annotations) { 60 for (var annotation in _annotations) {
60 var pair = _resolveConstructor( 61 var pair = _resolveConstructor(
61 annotation.name, annotation.constructorName); 62 annotation.name, annotation.constructorName);
62 var name = pair.first; 63 var name = pair.first;
63 var constructorName = pair.last; 64 var constructorName = pair.last;
64 65
65 if (name == 'TestOn') { 66 if (name == 'TestOn') {
66 _assertSingle(testOn, 'TestOn', annotation); 67 _assertSingle(testOn, 'TestOn', annotation);
67 testOn = _parseTestOn(annotation, constructorName); 68 testOn = _parseTestOn(annotation, constructorName);
68 } else if (name == 'Timeout') { 69 } else if (name == 'Timeout') {
69 _assertSingle(timeout, 'Timeout', annotation); 70 _assertSingle(timeout, 'Timeout', annotation);
70 timeout = _parseTimeout(annotation, constructorName); 71 timeout = _parseTimeout(annotation, constructorName);
71 } else if (name == 'Skip') { 72 } else if (name == 'Skip') {
72 _assertSingle(skip, 'Skip', annotation); 73 _assertSingle(skip, 'Skip', annotation);
73 skip = _parseSkip(annotation, constructorName); 74 skip = _parseSkip(annotation, constructorName);
74 } else if (name == 'OnPlatform') { 75 } else if (name == 'OnPlatform') {
75 _assertSingle(onPlatform, 'OnPlatform', annotation); 76 _assertSingle(onPlatform, 'OnPlatform', annotation);
76 onPlatform = _parseOnPlatform(annotation, constructorName); 77 onPlatform = _parseOnPlatform(annotation, constructorName);
78 } else if (name == 'Tags') {
79 _assertSingle(tags, 'Tags', annotation);
80 tags = _parseTags(annotation, constructorName);
77 } 81 }
78 } 82 }
79 83
80 return new Metadata( 84 return new Metadata(
81 testOn: testOn, 85 testOn: testOn,
82 timeout: timeout, 86 timeout: timeout,
83 skip: skip != null, 87 skip: skip != null,
84 skipReason: skip is String ? skip : null, 88 skipReason: skip is String ? skip : null,
85 onPlatform: onPlatform); 89 onPlatform: onPlatform,
90 tags: tags);
86 } 91 }
87 92
88 /// Parses a `@TestOn` annotation. 93 /// Parses a `@TestOn` annotation.
89 /// 94 ///
90 /// [annotation] is the annotation. [constructorName] is the name of the named 95 /// [annotation] is the annotation. [constructorName] is the name of the named
91 /// constructor for the annotation, if any. 96 /// constructor for the annotation, if any.
92 PlatformSelector _parseTestOn(Annotation annotation, String constructorName) { 97 PlatformSelector _parseTestOn(Annotation annotation, String constructorName) {
93 _assertConstructorName(constructorName, 'TestOn', annotation); 98 _assertConstructorName(constructorName, 'TestOn', annotation);
94 _assertArguments(annotation.arguments, 'TestOn', annotation, positional: 1); 99 _assertArguments(annotation.arguments, 'TestOn', annotation, positional: 1);
95 var literal = _parseString(annotation.arguments.arguments.first); 100 var literal = _parseString(annotation.arguments.arguments.first);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 /// Returns either `true` or a reason string. 161 /// Returns either `true` or a reason string.
157 _parseSkipConstructor(InstanceCreationExpression constructor) { 162 _parseSkipConstructor(InstanceCreationExpression constructor) {
158 _parseConstructor(constructor, 'Skip'); 163 _parseConstructor(constructor, 'Skip');
159 _assertArguments(constructor.argumentList, 'Skip', constructor, 164 _assertArguments(constructor.argumentList, 'Skip', constructor,
160 optional: 1); 165 optional: 1);
161 166
162 var args = constructor.argumentList.arguments; 167 var args = constructor.argumentList.arguments;
163 return args.isEmpty ? true : _parseString(args.first).stringValue; 168 return args.isEmpty ? true : _parseString(args.first).stringValue;
164 } 169 }
165 170
171 /// Parses a `@Tags` annotation.
172 ///
173 /// [annotation] is the annotation. [constructorName] is the name of the named
174 /// constructor for the annotation, if any.
175 Set<String> _parseTags(Annotation annotation, String constructorName) {
176 _assertConstructorName(constructorName, 'Tags', annotation);
177 _assertArguments(annotation.arguments, 'Tags', annotation, positional: 1);
178 var arg = annotation.arguments.arguments.first;
179 if (arg is ListLiteral) {
180 var tagExpressions = _parseList(arg);
181 return new Set<String>.from(
182 tagExpressions.map((tagExpr) => _parseString(tagExpr).stringValue));
183 } else if (arg is StringLiteral) {
184 return new Set<String>.from([_parseString(arg).stringValue]);
185 } else {
186 throw new SourceSpanFormatException(
187 'Only String or List literal allowed as @Tags argument',
188 _spanFor(arg));
189 }
190 }
191
166 /// Parses an `@OnPlatform` annotation. 192 /// Parses an `@OnPlatform` annotation.
167 /// 193 ///
168 /// [annotation] is the annotation. [constructorName] is the name of the named 194 /// [annotation] is the annotation. [constructorName] is the name of the named
169 /// constructor for the annotation, if any. 195 /// constructor for the annotation, if any.
170 Map<PlatformSelector, Metadata> _parseOnPlatform(Annotation annotation, 196 Map<PlatformSelector, Metadata> _parseOnPlatform(Annotation annotation,
171 String constructorName) { 197 String constructorName) {
172 _assertConstructorName(constructorName, 'OnPlatform', annotation); 198 _assertConstructorName(constructorName, 'OnPlatform', annotation);
173 _assertArguments(annotation.arguments, 'OnPlatform', annotation, 199 _assertArguments(annotation.arguments, 'OnPlatform', annotation,
174 positional: 1); 200 positional: 1);
175 201
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return fn(); 537 return fn();
512 } on SourceSpanFormatException catch (error) { 538 } on SourceSpanFormatException catch (error) {
513 var file = new SourceFile(new File(_path).readAsStringSync(), 539 var file = new SourceFile(new File(_path).readAsStringSync(),
514 url: p.toUri(_path)); 540 url: p.toUri(_path));
515 var span = contextualizeSpan(error.span, literal, file); 541 var span = contextualizeSpan(error.span, literal, file);
516 if (span == null) rethrow; 542 if (span == null) rethrow;
517 throw new SourceSpanFormatException(error.message, span); 543 throw new SourceSpanFormatException(error.message, span);
518 } 544 }
519 } 545 }
520 } 546 }
OLDNEW
« no previous file with comments | « lib/src/runner/configuration.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698