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

Side by Side Diff: pkg/analyzer/test/src/command_line/arguments_test.dart

Issue 2441053003: Intial support for unifying command-line handling (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 analyzer.test.src.context.context_builder_test;
6
7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/command_line/arguments.dart';
9 import 'package:analyzer/src/context/builder.dart';
10 import 'package:analyzer/src/dart/sdk/sdk.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:args/args.dart';
14 import 'package:test/test.dart';
15 import 'package:test_reflective_loader/test_reflective_loader.dart';
16
17 main() {
18 defineReflectiveSuite(() {
19 defineReflectiveTests(ArgumentsTest);
20 });
21 }
22
23 @reflectiveTest
24 class ArgumentsTest {
25 void test_createContextBuilderOptions_all() {
26 String dartSdkSummaryPath = 'a';
27 String defaultAnalysisOptionsFilePath = 'b';
28 String defaultPackageFilePath = 'c';
29 String defaultPackagesDirectoryPath = 'd';
30 MemoryResourceProvider provider = new MemoryResourceProvider();
31 ArgParser parser = new ArgParser();
32 defineAnalysisArguments(parser);
33 List<String> args = [
34 '--dart-sdk-summary=$dartSdkSummaryPath',
35 '-Dfoo=1',
36 '-Dbar=2',
37 '--enable-strict-call-checks',
38 '--initializing-formal-access',
39 '--no-implicit-casts',
40 '--no-implicit-dynamic',
41 '--options=$defaultAnalysisOptionsFilePath',
42 '--packages=$defaultPackageFilePath',
43 '--package-root=$defaultPackagesDirectoryPath',
44 '--strong',
45 '--supermixin',
46 ];
47 ArgResults result = parse(provider, parser, args);
48 ContextBuilderOptions options = createContextBuilderOptions(result);
49 expect(options, isNotNull);
50 expect(options.dartSdkSummaryPath, dartSdkSummaryPath);
51 Map<String, String> declaredVariables = options.declaredVariables;
52 expect(declaredVariables, hasLength(2));
53 expect(declaredVariables['foo'], '1');
54 expect(declaredVariables['bar'], '2');
55 expect(
56 options.defaultAnalysisOptionsFilePath, defaultAnalysisOptionsFilePath);
57 expect(options.defaultPackageFilePath, defaultPackageFilePath);
58 expect(options.defaultPackagesDirectoryPath, defaultPackagesDirectoryPath);
59 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
60 expect(defaultOptions, isNotNull);
61 expect(defaultOptions.enableInitializingFormalAccess, true);
62 expect(defaultOptions.enableStrictCallChecks, true);
63 expect(defaultOptions.strongMode, true);
64 expect(defaultOptions.implicitCasts, false);
65 expect(defaultOptions.implicitDynamic, false);
66 expect(options.pubSummaryManager, isNull);
67 }
68
69 void test_createContextBuilderOptions_none() {
70 MemoryResourceProvider provider = new MemoryResourceProvider();
71 ArgParser parser = new ArgParser();
72 defineAnalysisArguments(parser);
73 List<String> args = [];
74 ArgResults result = parse(provider, parser, args);
75 ContextBuilderOptions options = createContextBuilderOptions(result);
76 expect(options, isNotNull);
77 expect(options.dartSdkSummaryPath, isNull);
78 expect(options.declaredVariables, isEmpty);
79 expect(options.defaultAnalysisOptionsFilePath, isNull);
80 expect(options.defaultPackageFilePath, isNull);
81 expect(options.defaultPackagesDirectoryPath, isNull);
82 AnalysisOptionsImpl defaultOptions = options.defaultOptions;
83 expect(defaultOptions, isNotNull);
84 expect(defaultOptions.enableInitializingFormalAccess, false);
85 expect(defaultOptions.enableStrictCallChecks, false);
86 expect(defaultOptions.strongMode, false);
87 expect(defaultOptions.implicitCasts, true);
88 expect(defaultOptions.implicitDynamic, true);
89 expect(options.pubSummaryManager, isNull);
90 }
91
92 void test_createDartSdkManager_noPath_noSummaries() {
93 MemoryResourceProvider provider = new MemoryResourceProvider();
94 ArgParser parser = new ArgParser();
95 defineAnalysisArguments(parser);
96 List<String> args = [];
97 ArgResults result = parse(provider, parser, args);
98 DartSdkManager manager = createDartSdkManager(provider, false, result);
99 expect(manager, isNotNull);
100 expect(manager.defaultSdkDirectory,
101 FolderBasedDartSdk.defaultSdkDirectory(provider));
102 expect(manager.canUseSummaries, false);
103 }
104
105 void test_createDartSdkManager_noPath_summaries() {
106 MemoryResourceProvider provider = new MemoryResourceProvider();
107 ArgParser parser = new ArgParser();
108 defineAnalysisArguments(parser);
109 List<String> args = [];
110 ArgResults result = parse(provider, parser, args);
111 DartSdkManager manager = createDartSdkManager(provider, true, result);
112 expect(manager, isNotNull);
113 expect(manager.defaultSdkDirectory,
114 FolderBasedDartSdk.defaultSdkDirectory(provider));
115 expect(manager.canUseSummaries, true);
116 }
117
118 void test_createDartSdkManager_path_noSummaries() {
119 MemoryResourceProvider provider = new MemoryResourceProvider();
120 ArgParser parser = new ArgParser();
121 defineAnalysisArguments(parser);
122 List<String> args = ['--dart-sdk=x'];
123 ArgResults result = parse(provider, parser, args);
124 DartSdkManager manager = createDartSdkManager(provider, false, result);
125 expect(manager, isNotNull);
126 expect(manager.defaultSdkDirectory, 'x');
127 expect(manager.canUseSummaries, false);
128 }
129
130 void test_createDartSdkManager_path_summaries() {
131 MemoryResourceProvider provider = new MemoryResourceProvider();
132 ArgParser parser = new ArgParser();
133 defineAnalysisArguments(parser);
134 List<String> args = ['--dart-sdk=y'];
135 ArgResults result = parse(provider, parser, args);
136 DartSdkManager manager = createDartSdkManager(provider, true, result);
137 expect(manager, isNotNull);
138 expect(manager.defaultSdkDirectory, 'y');
139 expect(manager.canUseSummaries, true);
140 }
141
142 void test_defineAnalysisArguments() {
143 ArgParser parser = new ArgParser();
144 defineAnalysisArguments(parser);
145 expect(parser.options, hasLength(12));
146 }
147
148 void test_filterUnknownArguments() {
149 List<String> args = ['--a', '--b', '--c', 'foo', 'bar'];
150 ArgParser parser = new ArgParser();
151 parser.addFlag('a');
152 parser.addFlag('c');
153 List<String> result = filterUnknownArguments(args, parser);
154 expect(result, orderedEquals(['--a', '--c', 'foo', 'bar']));
155 }
156
157 void test_parse_noReplacement_noIgnored() {
158 MemoryResourceProvider provider = new MemoryResourceProvider();
159 ArgParser parser = new ArgParser();
160 parser.addFlag('xx');
161 parser.addOption('yy');
162 List<String> args = ['--xx', '--yy=abc', 'foo', 'bar'];
163 ArgResults result = parse(provider, parser, args);
164 expect(result, isNotNull);
165 expect(result['xx'], true);
166 expect(result['yy'], 'abc');
167 expect(result.rest, orderedEquals(['foo', 'bar']));
168 }
169
170 void test_preprocessArgs_noReplacement() {
171 MemoryResourceProvider provider = new MemoryResourceProvider();
172 List<String> result = preprocessArgs(provider, ['--xx' '--yy' 'baz']);
173 expect(result, orderedEquals(['--xx' '--yy' 'baz']));
174 }
175
176 void test_preprocessArgs_replacement_exists() {
177 MemoryResourceProvider provider = new MemoryResourceProvider();
178 String filePath = provider.convertPath('/args.txt');
179 provider.newFile(
180 filePath,
181 '''
182 -a
183 --xx
184
185 foo
186 bar
187 ''');
188 List<String> result =
189 preprocessArgs(provider, ['--preserved', '@$filePath']);
190 expect(result, orderedEquals(['--preserved', '-a', '--xx', 'foo', 'bar']));
191 }
192
193 void test_preprocessArgs_replacement_nonexistent() {
194 MemoryResourceProvider provider = new MemoryResourceProvider();
195 String filePath = provider.convertPath('/args.txt');
196 List<String> args = ['ignored', '@$filePath'];
197 List<String> result = preprocessArgs(provider, args);
198 expect(result, orderedEquals(args));
199 }
200
201 void test_preprocessArgs_replacement_notLast() {
202 MemoryResourceProvider provider = new MemoryResourceProvider();
203 String filePath = provider.convertPath('/args.txt');
204 List<String> args = ['a', '@$filePath', 'b'];
205 List<String> result = preprocessArgs(provider, args);
206 expect(result, orderedEquals(args));
207 }
208 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/command_line/arguments.dart ('k') | pkg/analyzer/test/src/command_line/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698