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

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

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

Powered by Google App Engine
This is Rietveld 408576698