|
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | 5 | import 'package:file/file.dart'; |
| 6 | +import 'package:yaml/yaml.dart'; |
6 | 7 |
|
7 | 8 | import 'common/core.dart'; |
8 | 9 | import 'common/file_filters.dart'; |
@@ -177,33 +178,33 @@ class DartTestCommand extends PackageLoopingCommand { |
177 | 178 | if (!testConfig.existsSync()) { |
178 | 179 | return null; |
179 | 180 | } |
180 | | - final testOnRegex = RegExp(r'^test_on:\s*([a-z].*[a-z])\s*$'); |
181 | | - for (final String line in testConfig.readAsLinesSync()) { |
182 | | - final RegExpMatch? match = testOnRegex.firstMatch(line); |
183 | | - if (match != null) { |
184 | | - final String targetFilter = match.group(1)!; |
185 | | - // test_on lines can be very complex, but in pratice the packages in |
186 | | - // this repo currently only need the ability to require vm or not, so a |
187 | | - // simple one-target directive is all that's supported currently. |
188 | | - // Making it deliberately strict avoids the possibility of accidentally |
189 | | - // skipping vm coverage due to a complex expression that's not handled |
190 | | - // correctly. |
191 | | - switch (targetFilter) { |
192 | | - case 'vm': |
193 | | - return _TestPlatform.vm; |
194 | | - case 'browser': |
195 | | - return _TestPlatform.browser; |
196 | | - default: |
197 | | - printError( |
198 | | - 'Unknown "test_on" value: "$targetFilter"\n' |
199 | | - "If this value needs to be supported for this package's tests, " |
200 | | - 'please update the repository tooling to support more test_on ' |
201 | | - 'modes.', |
202 | | - ); |
203 | | - throw ToolExit(_exitUnknownTestPlatform); |
204 | | - } |
205 | | - } |
| 181 | + final Object? root = loadYaml(testConfig.readAsStringSync()); |
| 182 | + if (root is! YamlMap) { |
| 183 | + return null; |
| 184 | + } |
| 185 | + final Object? targetFilter = root['test_on']; |
| 186 | + if (targetFilter == null || targetFilter is! String) { |
| 187 | + return null; |
| 188 | + } |
| 189 | + // test_on lines can be very complex, but in pratice the packages in |
| 190 | + // this repo currently only need the ability to require vm or not, so a |
| 191 | + // simple one-target directive is all that's supported currently. |
| 192 | + // Making it deliberately strict avoids the possibility of accidentally |
| 193 | + // skipping vm coverage due to a complex expression that's not handled |
| 194 | + // correctly. |
| 195 | + switch (targetFilter) { |
| 196 | + case 'vm': |
| 197 | + return _TestPlatform.vm; |
| 198 | + case 'browser': |
| 199 | + return _TestPlatform.browser; |
| 200 | + default: |
| 201 | + printError( |
| 202 | + 'Unknown "test_on" value: "$targetFilter"\n' |
| 203 | + "If this value needs to be supported for this package's tests, " |
| 204 | + 'please update the repository tooling to support more test_on ' |
| 205 | + 'modes.', |
| 206 | + ); |
| 207 | + throw ToolExit(_exitUnknownTestPlatform); |
206 | 208 | } |
207 | | - return null; |
208 | 209 | } |
209 | 210 | } |
0 commit comments