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

Side by Side Diff: tools/testing/dart/environment.dart

Issue 2984203002: Move the status file parser into its own package. (Closed)
Patch Set: Created 3 years, 4 months 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 | « tools/testing/dart/command_output.dart ('k') | tools/testing/dart/expectation.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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:status_file/environment.dart';
6
5 import 'configuration.dart'; 7 import 'configuration.dart';
6 8
7 typedef String _LookUpFunction(Configuration configuration); 9 typedef String _LookUpFunction(Configuration configuration);
8 typedef bool _BoolLookUpFunction(Configuration configuration); 10 typedef bool _BoolLookUpFunction(Configuration configuration);
9 11
10 // TODO(29756): Instead of synthesized negated variables like "unchecked", 12 // TODO(29756): Instead of synthesized negated variables like "unchecked",
11 // consider adding support for "!" to status expressions. 13 // consider adding support for "!" to status expressions.
12 final _variables = { 14 final _variables = {
13 "analyzer": new _Variable.bool((c) => c.compiler == Compiler.dart2analyzer), 15 "analyzer": new _Variable.bool((c) => c.compiler == Compiler.dart2analyzer),
14 "arch": new _Variable((c) => c.architecture.name, Architecture.names), 16 "arch": new _Variable((c) => c.architecture.name, Architecture.names),
(...skipping 29 matching lines...) Expand all
44 if (configuration.runtime == Runtime.firefox) return 'ff'; 46 if (configuration.runtime == Runtime.firefox) return 'ff';
45 47
46 return configuration.runtime.name; 48 return configuration.runtime.name;
47 } 49 }
48 50
49 /// Defines the variables that are available for use inside a status file 51 /// Defines the variables that are available for use inside a status file
50 /// section header. 52 /// section header.
51 /// 53 ///
52 /// These mostly map to command line arguments with the same name, though this 54 /// These mostly map to command line arguments with the same name, though this
53 /// is only a subset of the full set of command line arguments. 55 /// is only a subset of the full set of command line arguments.
54 class Environment { 56 class ConfigurationEnvironment implements Environment {
57 /// The configuration where variable data is found.
58 final Configuration _configuration;
59
60 ConfigurationEnvironment(this._configuration);
61
55 /// Validates that the variable with [name] exists and can be compared 62 /// Validates that the variable with [name] exists and can be compared
56 /// against [value]. 63 /// against [value].
57 /// 64 ///
58 /// If any errors are found, adds them to [errors]. 65 /// If any errors are found, adds them to [errors].
59 static void validate(String name, String value, List<String> errors) { 66 void validate(String name, String value, List<String> errors) {
60 var variable = _variables[name]; 67 var variable = _variables[name];
61 if (variable == null) { 68 if (variable == null) {
62 errors.add('Unknown variable "$name".'); 69 errors.add('Unknown variable "$name".');
63 return; 70 return;
64 } 71 }
65 72
66 // The "builder_tag" variable doesn't have an enumerated set of values. 73 // The "builder_tag" variable doesn't have an enumerated set of values.
67 if (variable.allowedValues.isEmpty) return; 74 if (variable.allowedValues.isEmpty) return;
68 75
69 if (!variable.allowedValues.contains(value)) { 76 if (!variable.allowedValues.contains(value)) {
70 errors.add( 77 errors.add(
71 'Variable "$name" cannot have value "$value". Allowed values are:\n' + 78 'Variable "$name" cannot have value "$value". Allowed values are:\n' +
72 variable.allowedValues.join(', ') + 79 variable.allowedValues.join(', ') +
73 '.'); 80 '.');
74 } 81 }
75 } 82 }
76 83
77 /// The configuration where variable data is found.
78 final Configuration _configuration;
79
80 Environment(this._configuration);
81
82 /// Looks up the value of the variable with [name]. 84 /// Looks up the value of the variable with [name].
83 String lookUp(String name) { 85 String lookUp(String name) {
84 var variable = _variables[name]; 86 var variable = _variables[name];
85 if (variable == null) { 87 if (variable == null) {
86 // This shouldn't happen since we validate variables before evaluating 88 // This shouldn't happen since we validate variables before evaluating
87 // expressions. 89 // expressions.
88 throw new ArgumentError('Unknown variable "$variable".'); 90 throw new ArgumentError('Unknown variable "$variable".');
89 } 91 }
90 92
91 return variable.lookUp(_configuration); 93 return variable.lookUp(_configuration);
(...skipping 15 matching lines...) Expand all
107 _Variable(this._lookUp, Iterable<String> allowed) 109 _Variable(this._lookUp, Iterable<String> allowed)
108 : allowedValues = allowed.toList(); 110 : allowedValues = allowed.toList();
109 111
110 /// Creates a Boolean variable with allowed values "true" and "false". 112 /// Creates a Boolean variable with allowed values "true" and "false".
111 _Variable.bool(_BoolLookUpFunction lookUp) 113 _Variable.bool(_BoolLookUpFunction lookUp)
112 : _lookUp = ((configuration) => lookUp(configuration).toString()), 114 : _lookUp = ((configuration) => lookUp(configuration).toString()),
113 allowedValues = const ["true", "false"]; 115 allowedValues = const ["true", "false"];
114 116
115 String lookUp(Configuration configuration) => _lookUp(configuration); 117 String lookUp(Configuration configuration) => _lookUp(configuration);
116 } 118 }
OLDNEW
« no previous file with comments | « tools/testing/dart/command_output.dart ('k') | tools/testing/dart/expectation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698