| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_options_parser; | 5 library test_options_parser; |
| 6 | 6 |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 import "drt_updater.dart"; | 8 import "drt_updater.dart"; |
| 9 import "test_suite.dart"; | 9 import "test_suite.dart"; |
| 10 import "path.dart"; | 10 import "path.dart"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 * the Map returned from the [TestOptionParser] parse method. | 36 * the Map returned from the [TestOptionParser] parse method. |
| 37 */ | 37 */ |
| 38 class _TestOptionSpecification { | 38 class _TestOptionSpecification { |
| 39 _TestOptionSpecification( | 39 _TestOptionSpecification( |
| 40 this.name, this.description, this.keys, this.values, this.defaultValue, | 40 this.name, this.description, this.keys, this.values, this.defaultValue, |
| 41 {this.type: 'string'}); | 41 {this.type: 'string'}); |
| 42 String name; | 42 String name; |
| 43 String description; | 43 String description; |
| 44 List<String> keys; | 44 List<String> keys; |
| 45 List<String> values; | 45 List<String> values; |
| 46 var defaultValue; | 46 Object defaultValue; |
| 47 String type; | 47 String type; |
| 48 } | 48 } |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * Parser of test options. | 51 * Parser of test options. |
| 52 */ | 52 */ |
| 53 class TestOptionsParser { | 53 class TestOptionsParser { |
| 54 /** | 54 /** |
| 55 * Creates a test options parser initialized with the known options. | 55 * Creates a test options parser initialized with the known options. |
| 56 */ | 56 */ |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 print('No value supplied for option $name'); | 553 print('No value supplied for option $name'); |
| 554 return null; | 554 return null; |
| 555 } | 555 } |
| 556 value = arguments[++i]; | 556 value = arguments[++i]; |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 } else { | 559 } else { |
| 560 // The argument does not start with '-' or '--' and is | 560 // The argument does not start with '-' or '--' and is |
| 561 // therefore not an option. We use it as a test selection | 561 // therefore not an option. We use it as a test selection |
| 562 // pattern. | 562 // pattern. |
| 563 configuration.putIfAbsent('selectors', () => []); | 563 var patterns = configuration.putIfAbsent('selectors', () => <String>[]); |
| 564 var patterns = configuration['selectors']; | |
| 565 patterns.add(arg); | 564 patterns.add(arg); |
| 566 continue; | 565 continue; |
| 567 } | 566 } |
| 568 | 567 |
| 569 // Multiple uses of a flag are an error, because there is no | 568 // Multiple uses of a flag are an error, because there is no |
| 570 // naturally correct way to handle conflicting options. | 569 // naturally correct way to handle conflicting options. |
| 571 if (configuration.containsKey(spec.name)) { | 570 if (configuration.containsKey(spec.name)) { |
| 572 print('Error: test.dart disallows multiple "--${spec.name}" flags'); | 571 print('Error: test.dart disallows multiple "--${spec.name}" flags'); |
| 573 exit(1); | 572 exit(1); |
| 574 } | 573 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 List<Map> result = expandedConfigs.where(_isValidConfig).toList(); | 610 List<Map> result = expandedConfigs.where(_isValidConfig).toList(); |
| 612 for (var config in result) { | 611 for (var config in result) { |
| 613 config['_reproducing_arguments_'] = | 612 config['_reproducing_arguments_'] = |
| 614 _constructReproducingCommandArguments(config); | 613 _constructReproducingCommandArguments(config); |
| 615 } | 614 } |
| 616 return result.isEmpty ? null : result; | 615 return result.isEmpty ? null : result; |
| 617 } | 616 } |
| 618 | 617 |
| 619 // For printing out reproducing command lines, we don't want to add these | 618 // For printing out reproducing command lines, we don't want to add these |
| 620 // options. | 619 // options. |
| 621 Set<String> _blacklistedOptions = new Set<String>.from([ | 620 final _blacklistedOptions = [ |
| 622 'append_logs', | 621 'append_logs', |
| 623 'build_directory', | 622 'build_directory', |
| 624 'chrome', | 623 'chrome', |
| 625 'copy_coredumps', | 624 'copy_coredumps', |
| 626 'dart', | 625 'dart', |
| 627 'flutter', | 626 'flutter', |
| 628 'dartium', | 627 'dartium', |
| 629 'drt', | 628 'drt', |
| 630 'exclude_suite', | 629 'exclude_suite', |
| 631 'failure-summary', | 630 'failure-summary', |
| 632 'firefox', | 631 'firefox', |
| 633 'local_ip', | 632 'local_ip', |
| 634 'progress', | 633 'progress', |
| 635 'report', | 634 'report', |
| 636 'safari', | 635 'safari', |
| 637 'shard', | 636 'shard', |
| 638 'shards', | 637 'shards', |
| 639 'step_name', | 638 'step_name', |
| 640 'tasks', | 639 'tasks', |
| 641 'time', | 640 'time', |
| 642 'verbose', | 641 'verbose', |
| 643 'write_debug_log', | 642 'write_debug_log', |
| 644 'write_test_outcome_log', | 643 'write_test_outcome_log', |
| 645 ]); | 644 ].toSet(); |
| 646 | 645 |
| 647 List<String> _constructReproducingCommandArguments(Map config) { | 646 List<String> _constructReproducingCommandArguments(Map config) { |
| 648 var arguments = new List<String>(); | 647 var arguments = new List<String>(); |
| 649 for (var option in _options) { | 648 for (var option in _options) { |
| 650 var name = option.name; | 649 var name = option.name; |
| 651 if (!config.containsKey(name) || _blacklistedOptions.contains(name)) { | 650 if (!config.containsKey(name) || _blacklistedOptions.contains(name)) { |
| 652 continue; | 651 continue; |
| 653 } | 652 } |
| 654 var value = config[name]; | 653 var value = config[name]; |
| 655 if (config[name] == option.defaultValue || | 654 if (config[name] == option.defaultValue || |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 // regular expressions to be used on the full path of a test file | 805 // regular expressions to be used on the full path of a test file |
| 807 // in that test suite. If no selectors are explicitly given use | 806 // in that test suite. If no selectors are explicitly given use |
| 808 // the default suite patterns. | 807 // the default suite patterns. |
| 809 var selectors = configuration['selectors']; | 808 var selectors = configuration['selectors']; |
| 810 if (selectors is! Map) { | 809 if (selectors is! Map) { |
| 811 if (selectors == null) { | 810 if (selectors == null) { |
| 812 if (configuration['suite_dir'] != null) { | 811 if (configuration['suite_dir'] != null) { |
| 813 var suite_path = new Path(configuration['suite_dir']); | 812 var suite_path = new Path(configuration['suite_dir']); |
| 814 selectors = [suite_path.filename]; | 813 selectors = [suite_path.filename]; |
| 815 } else { | 814 } else { |
| 816 selectors = new List.from(defaultTestSelectors); | 815 selectors = defaultTestSelectors.toList(); |
| 817 } | 816 } |
| 818 | 817 |
| 819 var exclude_suites = configuration['exclude_suite'] != null | 818 var excludeSuites = configuration['exclude_suite'] != null |
| 820 ? configuration['exclude_suite'].split(',') | 819 ? configuration['exclude_suite'].split(',') |
| 821 : []; | 820 : []; |
| 822 for (var exclude in exclude_suites) { | 821 for (var exclude in excludeSuites) { |
| 823 if (selectors.contains(exclude)) { | 822 if (selectors.contains(exclude)) { |
| 824 selectors.remove(exclude); | 823 selectors.remove(exclude); |
| 825 } else { | 824 } else { |
| 826 print("Warning: default selectors does not contain $exclude"); | 825 print("Warning: default selectors does not contain $exclude"); |
| 827 } | 826 } |
| 828 } | 827 } |
| 829 } | 828 } |
| 830 Map<String, RegExp> selectorMap = new Map<String, RegExp>(); | 829 var selectorMap = <String, RegExp>{}; |
| 831 for (var i = 0; i < selectors.length; i++) { | 830 for (var i = 0; i < selectors.length; i++) { |
| 832 var pattern = selectors[i]; | 831 var pattern = selectors[i]; |
| 833 var suite = pattern; | 832 var suite = pattern; |
| 834 var slashLocation = pattern.indexOf('/'); | 833 var slashLocation = pattern.indexOf('/'); |
| 835 if (slashLocation != -1) { | 834 if (slashLocation != -1) { |
| 836 suite = pattern.substring(0, slashLocation); | 835 suite = pattern.substring(0, slashLocation); |
| 837 pattern = pattern.substring(slashLocation + 1); | 836 pattern = pattern.substring(slashLocation + 1); |
| 838 pattern = pattern.replaceAll('*', '.*'); | 837 pattern = pattern.replaceAll('*', '.*'); |
| 839 } else { | 838 } else { |
| 840 pattern = ".?"; | 839 pattern = ".?"; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 return option; | 1003 return option; |
| 1005 } | 1004 } |
| 1006 } | 1005 } |
| 1007 print('Unknown test option $name'); | 1006 print('Unknown test option $name'); |
| 1008 exit(1); | 1007 exit(1); |
| 1009 return null; // Unreachable. | 1008 return null; // Unreachable. |
| 1010 } | 1009 } |
| 1011 | 1010 |
| 1012 List<_TestOptionSpecification> _options; | 1011 List<_TestOptionSpecification> _options; |
| 1013 } | 1012 } |
| OLD | NEW |