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'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:analyzer_cli/src/driver.dart'; | 9 import 'package:analyzer_cli/src/driver.dart'; |
10 import 'package:analyzer_cli/src/options.dart'; | 10 import 'package:analyzer_cli/src/options.dart'; |
11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 import 'package:usage/usage.dart'; |
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
13 | 14 |
14 main() { | 15 main() { |
15 group('CommandLineOptions', () { | 16 group('CommandLineOptions', () { |
16 group('parse', () { | 17 group('parse', () { |
| 18 int lastExitHandlerCode; |
| 19 StringBuffer outStringBuffer = new StringBuffer(); |
| 20 StringBuffer errorStringBuffer = new StringBuffer(); |
| 21 |
| 22 StringSink savedOutSink, savedErrorSink; |
| 23 int savedExitCode; |
| 24 ExitHandler savedExitHandler; |
| 25 |
| 26 setUp(() { |
| 27 savedOutSink = outSink; |
| 28 savedErrorSink = errorSink; |
| 29 savedExitHandler = exitHandler; |
| 30 savedExitCode = exitCode; |
| 31 exitHandler = (int code) { |
| 32 lastExitHandlerCode = code; |
| 33 }; |
| 34 outSink = outStringBuffer; |
| 35 errorSink = errorStringBuffer; |
| 36 }); |
| 37 |
| 38 tearDown(() { |
| 39 outSink = savedOutSink; |
| 40 errorSink = savedErrorSink; |
| 41 exitCode = savedExitCode; |
| 42 exitHandler = savedExitHandler; |
| 43 }); |
| 44 |
17 test('defaults', () { | 45 test('defaults', () { |
18 CommandLineOptions options = | 46 CommandLineOptions options = |
19 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); | 47 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); |
20 expect(options, isNotNull); | 48 expect(options, isNotNull); |
21 expect(options.buildMode, isFalse); | 49 expect(options.buildMode, isFalse); |
22 expect(options.buildAnalysisOutput, isNull); | 50 expect(options.buildAnalysisOutput, isNull); |
23 expect(options.buildSummaryInputs, isEmpty); | 51 expect(options.buildSummaryInputs, isEmpty); |
24 expect(options.buildSummaryOnly, isFalse); | 52 expect(options.buildSummaryOnly, isFalse); |
25 expect(options.buildSummaryOnlyDiet, isFalse); | 53 expect(options.buildSummaryOnlyDiet, isFalse); |
26 expect(options.buildSummaryOnlyUnlinked, isFalse); | 54 expect(options.buildSummaryOnlyUnlinked, isFalse); |
27 expect(options.buildSummaryOutput, isNull); | 55 expect(options.buildSummaryOutput, isNull); |
28 expect(options.buildSummaryOutputSemantic, isNull); | 56 expect(options.buildSummaryOutputSemantic, isNull); |
29 expect(options.buildSuppressExitCode, isFalse); | 57 expect(options.buildSuppressExitCode, isFalse); |
30 expect(options.dartSdkPath, isNotNull); | 58 expect(options.dartSdkPath, isNotNull); |
31 expect(options.disableCacheFlushing, isFalse); | 59 expect(options.disableCacheFlushing, isFalse); |
32 expect(options.disableHints, isFalse); | 60 expect(options.disableHints, isFalse); |
33 expect(options.lints, isFalse); | 61 expect(options.lints, isFalse); |
34 expect(options.displayVersion, isFalse); | 62 expect(options.displayVersion, isFalse); |
35 expect(options.enableStrictCallChecks, isFalse); | 63 expect(options.enableStrictCallChecks, isFalse); |
36 expect(options.enableSuperMixins, isFalse); | 64 expect(options.enableSuperMixins, isFalse); |
37 expect(options.enableTypeChecks, isFalse); | 65 expect(options.enableTypeChecks, isFalse); |
38 expect(options.enableAssertInitializer, isNull); | 66 expect(options.enableAssertInitializer, isNull); |
39 expect(options.infosAreFatal, isFalse); | 67 expect(options.infosAreFatal, isFalse); |
40 expect(options.ignoreUnrecognizedFlags, isFalse); | 68 expect(options.ignoreUnrecognizedFlags, isFalse); |
41 expect(options.log, isFalse); | 69 expect(options.log, isFalse); |
42 expect(options.machineFormat, isFalse); | 70 expect(options.machineFormat, isFalse); |
43 expect(options.packageRootPath, isNull); | 71 expect(options.packageRootPath, isNull); |
44 expect(options.shouldBatch, isFalse); | 72 expect(options.batchMode, isFalse); |
45 expect(options.showPackageWarnings, isFalse); | 73 expect(options.showPackageWarnings, isFalse); |
46 expect(options.showSdkWarnings, isFalse); | 74 expect(options.showSdkWarnings, isFalse); |
47 expect(options.sourceFiles, equals(['foo.dart'])); | 75 expect(options.sourceFiles, equals(['foo.dart'])); |
48 expect(options.warningsAreFatal, isFalse); | 76 expect(options.warningsAreFatal, isFalse); |
49 expect(options.strongMode, isFalse); | 77 expect(options.strongMode, isFalse); |
50 expect(options.lintsAreFatal, isFalse); | 78 expect(options.lintsAreFatal, isFalse); |
51 }); | 79 }); |
52 | 80 |
53 test('batch', () { | 81 test('batch', () { |
54 CommandLineOptions options = | 82 CommandLineOptions options = |
55 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); | 83 CommandLineOptions.parse(['--dart-sdk', '.', '--batch']); |
56 expect(options.shouldBatch, isTrue); | 84 expect(options.batchMode, isTrue); |
57 }); | 85 }); |
58 | 86 |
59 test('defined variables', () { | 87 test('defined variables', () { |
60 CommandLineOptions options = CommandLineOptions | 88 CommandLineOptions options = CommandLineOptions |
61 .parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart']); | 89 .parse(['--dart-sdk', '.', '-Dfoo=bar', 'foo.dart']); |
62 expect(options.definedVariables['foo'], equals('bar')); | 90 expect(options.definedVariables['foo'], equals('bar')); |
63 expect(options.definedVariables['bar'], isNull); | 91 expect(options.definedVariables['bar'], isNull); |
64 }); | 92 }); |
65 | 93 |
66 test('disable cache flushing', () { | 94 test('disable cache flushing', () { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 test('hintsAreFatal', () { | 216 test('hintsAreFatal', () { |
189 CommandLineOptions options = CommandLineOptions | 217 CommandLineOptions options = CommandLineOptions |
190 .parse(['--dart-sdk', '.', '--fatal-lints', 'foo.dart']); | 218 .parse(['--dart-sdk', '.', '--fatal-lints', 'foo.dart']); |
191 expect(options.lintsAreFatal, isTrue); | 219 expect(options.lintsAreFatal, isTrue); |
192 }); | 220 }); |
193 | 221 |
194 test("can't specify package and package-root", () { | 222 test("can't specify package and package-root", () { |
195 var failureMessage; | 223 var failureMessage; |
196 CommandLineOptions.parse( | 224 CommandLineOptions.parse( |
197 ['--package-root', '.', '--packages', '.', 'foo.dart'], | 225 ['--package-root', '.', '--packages', '.', 'foo.dart'], |
198 (msg) => failureMessage = msg); | 226 printAndFail: (msg) => failureMessage = msg); |
199 expect(failureMessage, | 227 expect(failureMessage, |
200 equals("Cannot specify both '--package-root' and '--packages.")); | 228 equals("Cannot specify both '--package-root' and '--packages.")); |
201 }); | 229 }); |
202 | 230 |
203 test("bad SDK dir", () { | 231 test("bad SDK dir", () { |
204 var failureMessage; | 232 var failureMessage; |
205 CommandLineOptions.parse( | 233 CommandLineOptions.parse(['--dart-sdk', '&&&&&', 'foo.dart'], |
206 ['--dart-sdk', '&&&&&', 'foo.dart'], (msg) => failureMessage = msg); | 234 printAndFail: (msg) => failureMessage = msg); |
207 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); | 235 expect(failureMessage, equals('Invalid Dart SDK path: &&&&&')); |
208 }); | 236 }); |
| 237 |
| 238 test('--analytics', () { |
| 239 AnalyticsMock mock = new AnalyticsMock()..enabled = false; |
| 240 setAnalytics(mock); |
| 241 CommandLineOptions.parse(['--analytics']); |
| 242 expect(mock.enabled, true); |
| 243 expect(lastExitHandlerCode, 0); |
| 244 expect(outStringBuffer.toString(), contains('Analytics are currently')); |
| 245 }); |
| 246 |
| 247 test('--no-analytics', () { |
| 248 AnalyticsMock mock = new AnalyticsMock()..enabled = false; |
| 249 setAnalytics(mock); |
| 250 CommandLineOptions.parse(['--no-analytics']); |
| 251 expect(mock.enabled, false); |
| 252 expect(lastExitHandlerCode, 0); |
| 253 expect(outStringBuffer.toString(), contains('Analytics are currently')); |
| 254 }); |
209 }); | 255 }); |
210 }); | 256 }); |
211 defineReflectiveTests(CommandLineOptionsTest); | 257 defineReflectiveTests(CommandLineOptionsTest); |
212 } | 258 } |
213 | 259 |
214 @reflectiveTest | 260 @reflectiveTest |
215 class AbstractStatusTest { | 261 class AbstractStatusTest { |
216 int lastExitHandlerCode; | 262 int lastExitHandlerCode; |
217 StringBuffer outStringBuffer = new StringBuffer(); | 263 StringBuffer outStringBuffer = new StringBuffer(); |
218 StringBuffer errorStringBuffer = new StringBuffer(); | 264 StringBuffer errorStringBuffer = new StringBuffer(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 'package:p/foo.dart|/path/to/p/lib/foo.dart' | 420 'package:p/foo.dart|/path/to/p/lib/foo.dart' |
375 ]); | 421 ]); |
376 expect(options.buildMode, isTrue); | 422 expect(options.buildMode, isTrue); |
377 expect(options.buildSuppressExitCode, isTrue); | 423 expect(options.buildSuppressExitCode, isTrue); |
378 } | 424 } |
379 | 425 |
380 void _parse(List<String> args) { | 426 void _parse(List<String> args) { |
381 options = CommandLineOptions.parse(args); | 427 options = CommandLineOptions.parse(args); |
382 } | 428 } |
383 } | 429 } |
OLD | NEW |