| OLD | NEW |
| 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 analyzer_cli.test.options; | 5 library analyzer_cli.test.options; |
| 6 | 6 |
| 7 import 'dart:io'; |
| 8 |
| 9 import 'package:analyzer_cli/src/driver.dart'; |
| 7 import 'package:analyzer_cli/src/options.dart'; | 10 import 'package:analyzer_cli/src/options.dart'; |
| 8 import 'package:args/args.dart'; | 11 import 'package:args/args.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 10 | 14 |
| 11 main() { | 15 main() { |
| 12 group('CommandLineOptions', () { | 16 group('CommandLineOptions', () { |
| 13 group('parse', () { | 17 group('parse', () { |
| 14 test('defaults', () { | 18 test('defaults', () { |
| 15 CommandLineOptions options = | 19 CommandLineOptions options = |
| 16 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); | 20 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); |
| 17 expect(options, isNotNull); | 21 expect(options, isNotNull); |
| 18 expect(options.dartSdkPath, isNotNull); | 22 expect(options.dartSdkPath, isNotNull); |
| 19 expect(options.disableHints, isFalse); | 23 expect(options.disableHints, isFalse); |
| 20 expect(options.lints, isFalse); | 24 expect(options.lints, isFalse); |
| 21 expect(options.displayVersion, isFalse); | 25 expect(options.displayVersion, isFalse); |
| 22 expect(options.enableStrictCallChecks, isFalse); | 26 expect(options.enableStrictCallChecks, isFalse); |
| 23 expect(options.enableSuperMixins, isFalse); | 27 expect(options.enableSuperMixins, isFalse); |
| 24 expect(options.enableTypeChecks, isFalse); | 28 expect(options.enableTypeChecks, isFalse); |
| 25 expect(options.hintsAreFatal, isFalse); | 29 expect(options.hintsAreFatal, isFalse); |
| 26 expect(options.ignoreUnrecognizedFlags, isFalse); | 30 expect(options.ignoreUnrecognizedFlags, isFalse); |
| 27 expect(options.log, isFalse); | 31 expect(options.log, isFalse); |
| 28 expect(options.machineFormat, isFalse); | 32 expect(options.machineFormat, isFalse); |
| 33 expect(options.packageMode, isFalse); |
| 29 expect(options.packageRootPath, isNull); | 34 expect(options.packageRootPath, isNull); |
| 35 expect(options.packageSummaryInputs, isEmpty); |
| 30 expect(options.shouldBatch, isFalse); | 36 expect(options.shouldBatch, isFalse); |
| 31 expect(options.showPackageWarnings, isFalse); | 37 expect(options.showPackageWarnings, isFalse); |
| 32 expect(options.showSdkWarnings, isFalse); | 38 expect(options.showSdkWarnings, isFalse); |
| 33 expect(options.sourceFiles, equals(['foo.dart'])); | 39 expect(options.sourceFiles, equals(['foo.dart'])); |
| 34 expect(options.warningsAreFatal, isFalse); | 40 expect(options.warningsAreFatal, isFalse); |
| 35 expect(options.strongMode, isFalse); | 41 expect(options.strongMode, isFalse); |
| 36 }); | 42 }); |
| 37 | 43 |
| 38 test('batch', () { | 44 test('batch', () { |
| 39 CommandLineOptions options = | 45 CommandLineOptions options = |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 new CommandLineParser(alwaysIgnoreUnrecognized: true); | 164 new CommandLineParser(alwaysIgnoreUnrecognized: true); |
| 159 parser.addOption('optionA'); | 165 parser.addOption('optionA'); |
| 160 parser.addFlag('flagA'); | 166 parser.addFlag('flagA'); |
| 161 ArgResults argResults = | 167 ArgResults argResults = |
| 162 parser.parse(['--optionA=1', '--optionB=2', '--flagA'], {}); | 168 parser.parse(['--optionA=1', '--optionB=2', '--flagA'], {}); |
| 163 expect(argResults['optionA'], '1'); | 169 expect(argResults['optionA'], '1'); |
| 164 expect(argResults['flagA'], isTrue); | 170 expect(argResults['flagA'], isTrue); |
| 165 }); | 171 }); |
| 166 | 172 |
| 167 test('strong mode', () { | 173 test('strong mode', () { |
| 168 CommandLineOptions options = CommandLineOptions | 174 CommandLineOptions options = |
| 169 .parse(['--strong', 'foo.dart']); | 175 CommandLineOptions.parse(['--strong', 'foo.dart']); |
| 170 expect(options.strongMode, isTrue); | 176 expect(options.strongMode, isTrue); |
| 171 }); | 177 }); |
| 172 | 178 |
| 173 test("can't specify package and package-root", () { | 179 test("can't specify package and package-root", () { |
| 174 var failureMessage; | 180 var failureMessage; |
| 175 CommandLineOptions.parse( | 181 CommandLineOptions.parse( |
| 176 ['--package-root', '.', '--packages', '.', 'foo.dart'], | 182 ['--package-root', '.', '--packages', '.', 'foo.dart'], |
| 177 (msg) => failureMessage = msg); | 183 (msg) => failureMessage = msg); |
| 178 expect(failureMessage, | 184 expect(failureMessage, |
| 179 equals("Cannot specify both '--package-root' and '--packages.")); | 185 equals("Cannot specify both '--package-root' and '--packages.")); |
| 180 }); | 186 }); |
| 181 | 187 |
| 182 test("bad SDK dir", () { | 188 test("bad SDK dir", () { |
| 183 var failureMessage; | 189 var failureMessage; |
| 184 CommandLineOptions.parse( | 190 CommandLineOptions.parse( |
| 185 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); | 191 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); |
| 186 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); | 192 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); |
| 187 }); | 193 }); |
| 188 }); | 194 }); |
| 189 }); | 195 }); |
| 196 defineReflectiveTests(CommandLineOptionsTest); |
| 190 } | 197 } |
| 198 |
| 199 @reflectiveTest |
| 200 class AbstractStatusTest { |
| 201 int lastExitHandlerCode; |
| 202 StringBuffer outStringBuffer = new StringBuffer(); |
| 203 StringBuffer errorStringBuffer = new StringBuffer(); |
| 204 |
| 205 StringSink savedOutSink, savedErrorSink; |
| 206 int savedExitCode; |
| 207 ExitHandler savedExitHandler; |
| 208 |
| 209 setUp() { |
| 210 savedOutSink = outSink; |
| 211 savedErrorSink = errorSink; |
| 212 savedExitHandler = exitHandler; |
| 213 savedExitCode = exitCode; |
| 214 exitHandler = (int code) { |
| 215 lastExitHandlerCode = code; |
| 216 }; |
| 217 outSink = outStringBuffer; |
| 218 errorSink = errorStringBuffer; |
| 219 } |
| 220 |
| 221 tearDown() { |
| 222 outSink = savedOutSink; |
| 223 errorSink = savedErrorSink; |
| 224 exitCode = savedExitCode; |
| 225 exitHandler = savedExitHandler; |
| 226 } |
| 227 } |
| 228 |
| 229 @reflectiveTest |
| 230 class CommandLineOptionsTest extends AbstractStatusTest { |
| 231 CommandLineOptions options; |
| 232 |
| 233 test_packageMode() { |
| 234 _parse(['--package-mode', '/path/to/pkg']); |
| 235 expect(options.packageMode, isTrue); |
| 236 print(options.packageSummaryInputs); |
| 237 } |
| 238 |
| 239 test_packageSummaryInput() { |
| 240 _parse([ |
| 241 '--package-mode', |
| 242 '--package-summary-input=aaa,/path/to/aaa.sum', |
| 243 '--package-summary-input=long.package.bbb,/path/to/bbb.sum', |
| 244 '/path/to/pkg' |
| 245 ]); |
| 246 expect(options.packageMode, isTrue); |
| 247 Map<String, String> map = options.packageSummaryInputs; |
| 248 expect(map, hasLength(2)); |
| 249 expect(map, containsPair('aaa', '/path/to/aaa.sum')); |
| 250 expect(map, containsPair('long.package.bbb', '/path/to/bbb.sum')); |
| 251 } |
| 252 |
| 253 test_packageSummaryInput_noComma() { |
| 254 _parse([ |
| 255 '--package-mode', |
| 256 '--package-summary-input=noCommaInMapping', |
| 257 '/path/to/pkg' |
| 258 ]); |
| 259 expect(lastExitHandlerCode, 15); |
| 260 expect(errorStringBuffer.toString(), contains('--package-summary-input')); |
| 261 expect(errorStringBuffer.toString(), contains('noCommaInMapping')); |
| 262 } |
| 263 |
| 264 test_packageSummaryOutput() { |
| 265 _parse([ |
| 266 '--package-mode', |
| 267 '--package-summary-output=/path/to/output.sum', |
| 268 '/path/to/pkg' |
| 269 ]); |
| 270 expect(options.packageMode, isTrue); |
| 271 expect(options.packageSummaryOutput, '/path/to/output.sum'); |
| 272 } |
| 273 |
| 274 void _parse(List<String> args) { |
| 275 options = CommandLineOptions.parse(args); |
| 276 } |
| 277 } |
| OLD | NEW |