| 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 options_test; | 5 library options_test; |
| 6 | 6 |
| 7 import 'package:analyzer/options.dart'; | 7 import 'package:analyzer/options.dart'; |
| 8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import 'reflective_tests.dart'; | 11 import 'reflective_tests.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 | |
| 15 group('AnalyzerOptions.parse()', () { | 14 group('AnalyzerOptions.parse()', () { |
| 16 | |
| 17 test('defaults', () { | 15 test('defaults', () { |
| 18 CommandLineOptions options = | 16 CommandLineOptions options = |
| 19 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); | 17 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); |
| 20 expect(options, isNotNull); | 18 expect(options, isNotNull); |
| 21 expect(options.dartSdkPath, isNotNull); | 19 expect(options.dartSdkPath, isNotNull); |
| 22 expect(options.disableHints, isFalse); | 20 expect(options.disableHints, isFalse); |
| 23 expect(options.displayVersion, isFalse); | 21 expect(options.displayVersion, isFalse); |
| 24 expect(options.enableTypeChecks, isFalse); | 22 expect(options.enableTypeChecks, isFalse); |
| 25 expect(options.ignoreUnrecognizedFlags, isFalse); | 23 expect(options.ignoreUnrecognizedFlags, isFalse); |
| 26 expect(options.log, isFalse); | 24 expect(options.log, isFalse); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 expect(options.customUrlMappings.isEmpty, isTrue); | 35 expect(options.customUrlMappings.isEmpty, isTrue); |
| 38 }); | 36 }); |
| 39 | 37 |
| 40 test('batch', () { | 38 test('batch', () { |
| 41 CommandLineOptions options = | 39 CommandLineOptions options = |
| 42 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); | 40 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); |
| 43 expect(options.shouldBatch, isTrue); | 41 expect(options.shouldBatch, isTrue); |
| 44 }); | 42 }); |
| 45 | 43 |
| 46 test('defined variables', () { | 44 test('defined variables', () { |
| 47 CommandLineOptions options = | 45 CommandLineOptions options = CommandLineOptions |
| 48 CommandLineOptions.parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart'])
; | 46 .parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart']); |
| 49 expect(options.definedVariables['foo'], equals('bar')); | 47 expect(options.definedVariables['foo'], equals('bar')); |
| 50 expect(options.definedVariables['bar'], isNull); | 48 expect(options.definedVariables['bar'], isNull); |
| 51 }); | 49 }); |
| 52 | 50 |
| 53 test('enable type checks', () { | 51 test('enable type checks', () { |
| 54 CommandLineOptions options = CommandLineOptions.parse( | 52 CommandLineOptions options = CommandLineOptions |
| 55 ['--dart-sdk', '.', '--enable_type_checks', 'foo.dart']); | 53 .parse(['--dart-sdk', '.', '--enable_type_checks', 'foo.dart']); |
| 56 expect(options.enableTypeChecks, isTrue); | 54 expect(options.enableTypeChecks, isTrue); |
| 57 }); | 55 }); |
| 58 | 56 |
| 59 test('log', () { | 57 test('log', () { |
| 60 CommandLineOptions options = | 58 CommandLineOptions options = |
| 61 CommandLineOptions.parse(['--dart-sdk', '.', '--log', 'foo.dart']); | 59 CommandLineOptions.parse(['--dart-sdk', '.', '--log', 'foo.dart']); |
| 62 expect(options.log, isTrue); | 60 expect(options.log, isTrue); |
| 63 }); | 61 }); |
| 64 | 62 |
| 65 test('machine format', () { | 63 test('machine format', () { |
| 66 CommandLineOptions options = | 64 CommandLineOptions options = CommandLineOptions |
| 67 CommandLineOptions.parse(['--dart-sdk', '.', '--format=machine', 'foo.
dart']); | 65 .parse(['--dart-sdk', '.', '--format=machine', 'foo.dart']); |
| 68 expect(options.machineFormat, isTrue); | 66 expect(options.machineFormat, isTrue); |
| 69 }); | 67 }); |
| 70 | 68 |
| 71 test('no-hints', () { | 69 test('no-hints', () { |
| 72 CommandLineOptions options = | 70 CommandLineOptions options = CommandLineOptions |
| 73 CommandLineOptions.parse(['--dart-sdk', '.', '--no-hints', 'foo.dart']
); | 71 .parse(['--dart-sdk', '.', '--no-hints', 'foo.dart']); |
| 74 expect(options.disableHints, isTrue); | 72 expect(options.disableHints, isTrue); |
| 75 }); | 73 }); |
| 76 | 74 |
| 77 test('package root', () { | 75 test('package root', () { |
| 78 CommandLineOptions options = | 76 CommandLineOptions options = CommandLineOptions |
| 79 CommandLineOptions.parse(['--dart-sdk', '.', '-p', 'bar', 'foo.dart'])
; | 77 .parse(['--dart-sdk', '.', '-p', 'bar', 'foo.dart']); |
| 80 expect(options.packageRootPath, equals('bar')); | 78 expect(options.packageRootPath, equals('bar')); |
| 81 }); | 79 }); |
| 82 | 80 |
| 83 test('package warnings', () { | 81 test('package warnings', () { |
| 84 CommandLineOptions options = CommandLineOptions.parse( | 82 CommandLineOptions options = CommandLineOptions |
| 85 ['--dart-sdk', '.', '--package-warnings', 'foo.dart']); | 83 .parse(['--dart-sdk', '.', '--package-warnings', 'foo.dart']); |
| 86 expect(options.showPackageWarnings, isTrue); | 84 expect(options.showPackageWarnings, isTrue); |
| 87 }); | 85 }); |
| 88 | 86 |
| 89 test('perf', () { | 87 test('perf', () { |
| 90 CommandLineOptions options = | 88 CommandLineOptions options = |
| 91 CommandLineOptions.parse(['--dart-sdk', '.', '--perf', 'foo.dart']); | 89 CommandLineOptions.parse(['--dart-sdk', '.', '--perf', 'foo.dart']); |
| 92 expect(options.perf, isTrue); | 90 expect(options.perf, isTrue); |
| 93 }); | 91 }); |
| 94 | 92 |
| 95 test('sdk warnings', () { | 93 test('sdk warnings', () { |
| 96 CommandLineOptions options = | 94 CommandLineOptions options = CommandLineOptions |
| 97 CommandLineOptions.parse(['--dart-sdk', '.', '--warnings', 'foo.dart']
); | 95 .parse(['--dart-sdk', '.', '--warnings', 'foo.dart']); |
| 98 expect(options.showSdkWarnings, isTrue); | 96 expect(options.showSdkWarnings, isTrue); |
| 99 }); | 97 }); |
| 100 | 98 |
| 101 test('sourceFiles', () { | 99 test('sourceFiles', () { |
| 102 CommandLineOptions options = CommandLineOptions.parse( | 100 CommandLineOptions options = CommandLineOptions.parse( |
| 103 ['--dart-sdk', '.', '--log', 'foo.dart', 'foo2.dart', 'foo3.dart']); | 101 ['--dart-sdk', '.', '--log', 'foo.dart', 'foo2.dart', 'foo3.dart']); |
| 104 expect( | 102 expect( |
| 105 options.sourceFiles, | 103 options.sourceFiles, equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); |
| 106 equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); | |
| 107 }); | 104 }); |
| 108 | 105 |
| 109 test('warningsAreFatal', () { | 106 test('warningsAreFatal', () { |
| 110 CommandLineOptions options = | 107 CommandLineOptions options = CommandLineOptions |
| 111 CommandLineOptions.parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.
dart']); | 108 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']); |
| 112 expect(options.warningsAreFatal, isTrue); | 109 expect(options.warningsAreFatal, isTrue); |
| 113 }); | 110 }); |
| 114 | 111 |
| 115 test('customUrlMappings', () { | 112 test('customUrlMappings', () { |
| 116 CommandLineOptions options = CommandLineOptions.parse( | 113 CommandLineOptions options = CommandLineOptions.parse([ |
| 117 [ | 114 '--dart-sdk', |
| 118 '--dart-sdk', | 115 '.', |
| 119 '.', | 116 '--url-mapping', |
| 120 '--url-mapping', | 117 'dart:dummy,/path/to/dummy.dart', |
| 121 'dart:dummy,/path/to/dummy.dart', | 118 'foo.dart' |
| 122 'foo.dart']); | 119 ]); |
| 123 expect(options.customUrlMappings, isNotNull); | 120 expect(options.customUrlMappings, isNotNull); |
| 124 expect(options.customUrlMappings.isEmpty, isFalse); | 121 expect(options.customUrlMappings.isEmpty, isFalse); |
| 125 expect( | 122 expect(options.customUrlMappings['dart:dummy'], |
| 126 options.customUrlMappings['dart:dummy'], | |
| 127 equals('/path/to/dummy.dart')); | 123 equals('/path/to/dummy.dart')); |
| 128 }); | 124 }); |
| 129 | 125 |
| 130 // test('notice unrecognized flags', () { | 126 // test('notice unrecognized flags', () { |
| 131 // CommandLineOptions options = CommandLineOptions.parse(['--bar', '--baz', | 127 // CommandLineOptions options = CommandLineOptions.parse(['--bar', '--baz', |
| 132 // 'foo.dart']); | 128 // 'foo.dart']); |
| 133 // expect(options, isNull); | 129 // expect(options, isNull); |
| 134 // }); | 130 // }); |
| 135 | 131 |
| 136 test('ignore unrecognized flags', () { | 132 test('ignore unrecognized flags', () { |
| 137 CommandLineOptions options = CommandLineOptions.parse( | 133 CommandLineOptions options = CommandLineOptions.parse([ |
| 138 [ | 134 '--ignore-unrecognized-flags', |
| 139 '--ignore-unrecognized-flags', | 135 '--bar', |
| 140 '--bar', | 136 '--baz', |
| 141 '--baz', | 137 '--dart-sdk', |
| 142 '--dart-sdk', | 138 '.', |
| 143 '.', | 139 'foo.dart' |
| 144 'foo.dart']); | 140 ]); |
| 145 expect(options, isNotNull); | 141 expect(options, isNotNull); |
| 146 expect(options.sourceFiles, equals(['foo.dart'])); | 142 expect(options.sourceFiles, equals(['foo.dart'])); |
| 147 }); | 143 }); |
| 148 | |
| 149 }); | 144 }); |
| 150 | 145 |
| 151 runReflectiveTests(CommandLineParserTest); | 146 runReflectiveTests(CommandLineParserTest); |
| 152 } | 147 } |
| 153 | 148 |
| 154 | |
| 155 @reflectiveTest | 149 @reflectiveTest |
| 156 class CommandLineParserTest { | 150 class CommandLineParserTest { |
| 157 test_ignoreUnrecognizedOptions() { | 151 test_ignoreUnrecognizedOptions() { |
| 158 CommandLineParser parser = | 152 CommandLineParser parser = |
| 159 new CommandLineParser(alwaysIgnoreUnrecognized: true); | 153 new CommandLineParser(alwaysIgnoreUnrecognized: true); |
| 160 parser.addOption('optionA'); | 154 parser.addOption('optionA'); |
| 161 parser.addFlag('flagA'); | 155 parser.addFlag('flagA'); |
| 162 ArgResults argResults = | 156 ArgResults argResults = |
| 163 parser.parse(['--optionA=1', '--optionB=2', '--flagA'], {}); | 157 parser.parse(['--optionA=1', '--optionB=2', '--flagA'], {}); |
| 164 expect(argResults['optionA'], '1'); | 158 expect(argResults['optionA'], '1'); |
| 165 expect(argResults['flagA'], isTrue); | 159 expect(argResults['flagA'], isTrue); |
| 166 } | 160 } |
| 167 } | 161 } |
| OLD | NEW |