Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: pkg/analyzer_cli/test/options_test.dart

Issue 2578733002: move CommandLineParser into analyzer for reuse by DDC (Closed)
Patch Set: merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer_cli/lib/src/options.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:args/args.dart';
12 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; 12 import 'package:test_reflective_loader/test_reflective_loader.dart';
14 13
15 main() { 14 main() {
16 group('CommandLineOptions', () { 15 group('CommandLineOptions', () {
17 group('parse', () { 16 group('parse', () {
18 test('defaults', () { 17 test('defaults', () {
19 CommandLineOptions options = 18 CommandLineOptions options =
20 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']); 19 CommandLineOptions.parse(['--dart-sdk', '.', 'foo.dart']);
21 expect(options, isNotNull); 20 expect(options, isNotNull);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 expect(options.sourceFiles, 144 expect(options.sourceFiles,
146 equals(['foo.dart', 'foo2.dart', 'foo3.dart'])); 145 equals(['foo.dart', 'foo2.dart', 'foo3.dart']));
147 }); 146 });
148 147
149 test('warningsAreFatal', () { 148 test('warningsAreFatal', () {
150 CommandLineOptions options = CommandLineOptions 149 CommandLineOptions options = CommandLineOptions
151 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']); 150 .parse(['--dart-sdk', '.', '--fatal-warnings', 'foo.dart']);
152 expect(options.warningsAreFatal, isTrue); 151 expect(options.warningsAreFatal, isTrue);
153 }); 152 });
154 153
155 test('notice unrecognized flags', () {
156 expect(
157 () => new CommandLineParser().parse(['--bar', '--baz', 'foo.dart']),
158 throwsA(new isInstanceOf<FormatException>()));
159 });
160
161 test('ignore unrecognized flags', () { 154 test('ignore unrecognized flags', () {
162 CommandLineOptions options = CommandLineOptions.parse([ 155 CommandLineOptions options = CommandLineOptions.parse([
163 '--ignore-unrecognized-flags', 156 '--ignore-unrecognized-flags',
164 '--bar', 157 '--bar',
165 '--baz', 158 '--baz',
166 '--dart-sdk', 159 '--dart-sdk',
167 '.', 160 '.',
168 'foo.dart' 161 'foo.dart'
169 ]); 162 ]);
170 expect(options, isNotNull); 163 expect(options, isNotNull);
171 expect(options.sourceFiles, equals(['foo.dart'])); 164 expect(options.sourceFiles, equals(['foo.dart']));
172 }); 165 });
173 166
174 test('ignore unrecognized options', () {
175 CommandLineParser parser =
176 new CommandLineParser(alwaysIgnoreUnrecognized: true);
177 parser.addOption('optionA');
178 parser.addFlag('flagA');
179 ArgResults argResults =
180 parser.parse(['--optionA=1', '--optionB=2', '--flagA']);
181 expect(argResults['optionA'], '1');
182 expect(argResults['flagA'], isTrue);
183 });
184
185 test('strong mode', () { 167 test('strong mode', () {
186 CommandLineOptions options = 168 CommandLineOptions options =
187 CommandLineOptions.parse(['--strong', 'foo.dart']); 169 CommandLineOptions.parse(['--strong', 'foo.dart']);
188 expect(options.strongMode, isTrue); 170 expect(options.strongMode, isTrue);
189 }); 171 });
190 172
191 test('hintsAreFatal', () { 173 test('hintsAreFatal', () {
192 CommandLineOptions options = CommandLineOptions 174 CommandLineOptions options = CommandLineOptions
193 .parse(['--dart-sdk', '.', '--fatal-lints', 'foo.dart']); 175 .parse(['--dart-sdk', '.', '--fatal-lints', 'foo.dart']);
194 expect(options.lintsAreFatal, isTrue); 176 expect(options.lintsAreFatal, isTrue);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 'package:p/foo.dart|/path/to/p/lib/foo.dart' 333 'package:p/foo.dart|/path/to/p/lib/foo.dart'
352 ]); 334 ]);
353 expect(options.buildMode, isTrue); 335 expect(options.buildMode, isTrue);
354 expect(options.buildSuppressExitCode, isTrue); 336 expect(options.buildSuppressExitCode, isTrue);
355 } 337 }
356 338
357 void _parse(List<String> args) { 339 void _parse(List<String> args) {
358 options = CommandLineOptions.parse(args); 340 options = CommandLineOptions.parse(args);
359 } 341 }
360 } 342 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698