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

Side by Side Diff: pkg/analyzer/test/generated/bazel_test.dart

Issue 2393963004: Add BazelPackageUriResolver with resolveAbsolute(). (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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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.test.generated.bazel_test; 5 library analyzer.test.generated.bazel_test;
6 6
7 import 'package:analyzer/file_system/memory_file_system.dart'; 7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/generated/bazel.dart'; 8 import 'package:analyzer/src/generated/bazel.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; 11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 12
13 main() { 13 main() {
14 defineReflectiveSuite(() { 14 defineReflectiveSuite(() {
15 defineReflectiveTests(BazelFileUriResolverTest);
16 defineReflectiveTests(BazelPackageUriResolverTest);
15 defineReflectiveTests(BazelWorkspaceTest); 17 defineReflectiveTests(BazelWorkspaceTest);
16 defineReflectiveTests(BazelFileUriResolverTest);
17 }); 18 });
18 } 19 }
19 20
20 @reflectiveTest 21 @reflectiveTest
21 class BazelFileUriResolverTest extends _BaseTest { 22 class BazelFileUriResolverTest extends _BaseTest {
22 BazelWorkspace workspace; 23 BazelWorkspace workspace;
23 BazelFileUriResolver resolver; 24 BazelFileUriResolver resolver;
24 25
25 void setUp() { 26 void setUp() {
26 provider.newFile(_p('/workspace/WORKSPACE'), ''); 27 provider.newFile(_p('/workspace/WORKSPACE'), '');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 92
92 Source _resolvePath(String absolutePosixPath) { 93 Source _resolvePath(String absolutePosixPath) {
93 String absolutePath = provider.convertPath(absolutePosixPath); 94 String absolutePath = provider.convertPath(absolutePosixPath);
94 Uri uri = provider.pathContext.toUri(absolutePath); 95 Uri uri = provider.pathContext.toUri(absolutePath);
95 return resolver.resolveAbsolute(uri); 96 return resolver.resolveAbsolute(uri);
96 } 97 }
97 } 98 }
98 99
99 @reflectiveTest 100 @reflectiveTest
101 class BazelPackageUriResolverTest extends _BaseTest {
102 BazelWorkspace workspace;
103 BazelPackageUriResolver resolver;
104
105 void setUp() {
106 provider.newFile(_p('/workspace/WORKSPACE'), '');
107 workspace = new BazelWorkspace(provider, _p('/workspace'));
108 resolver = new BazelPackageUriResolver(workspace);
109 provider.newFile(_p('/workspace/my/foo/lib/foo1.dart'), '');
110 provider.newFile(_p('/workspace/my/foo/lib/gen1.dart'), '');
111 provider.newFile(_p('/workspace/my/foo/lib/gen2.dart'), '');
112 provider.newFile(_p('/workspace/my/foo/lib/src/foo4.dart'), '');
113 provider.newFile(_p('/workspace/third_party/dart/bar/lib/bar1.dart'), '');
114 provider.newFile(
115 _p('/workspace/third_party/dart/bar/lib/src/bar2.dart'), '');
116 provider.newFile(_p('/workspace/bazel-bin/my/foo/lib/gen1.dart'), '');
117 provider.newFile(_p('/workspace/bazel-genfiles/my/foo/lib/gen2.dart'), '');
118 provider.newFile(_p('/workspace/bazel-genfiles/my/foo/lib/gen3.dart'), '');
119 }
120
121 void test_resolveAbsolute_inBazelBin() {
122 _assertResolve(
123 'package:my.foo/gen1.dart', '/workspace/bazel-bin/my/foo/lib/gen1.dart',
124 exists: true);
125 }
126
127 void test_resolveAbsolute_inBazelGenfiles() {
128 _assertResolve('package:my.foo/gen2.dart',
129 '/workspace/bazel-genfiles/my/foo/lib/gen2.dart',
130 exists: true);
131 }
132
133 void test_resolveAbsolute_inBazelGenfiles_notInWorkspace() {
134 _assertResolve('package:my.foo/gen3.dart',
135 '/workspace/bazel-genfiles/my/foo/lib/gen3.dart',
136 exists: true);
137 }
138
139 void test_resolveAbsolute_inWorkspace_doesNotExist() {
140 _assertResolve('package:my.foo/doesNotExist.dart',
141 '/workspace/my/foo/lib/doesNotExist.dart',
142 exists: false);
143 }
144
145 void test_resolveAbsolute_inWorkspace_exists() {
146 _assertResolve(
147 'package:my.foo/foo1.dart', '/workspace/my/foo/lib/foo1.dart',
148 exists: true);
149 }
150
151 void test_resolveAbsolute_null_notPackage() {
152 Source source = resolver.resolveAbsolute(Uri.parse('dart:async'));
153 expect(source, isNull);
154 }
155
156 void test_resolveAbsolute_thirdParty() {
157 _assertResolve('package:bar/bar1.dart',
158 '/workspace/third_party/dart/bar/lib/bar1.dart',
159 exists: true);
160 _assertResolve('package:bar/src/bar2.dart',
161 '/workspace/third_party/dart/bar/lib/src/bar2.dart',
162 exists: true);
163 }
164
165 void _assertResolve(String uriStr, String posixPath, {bool exists: true}) {
166 Uri uri = Uri.parse(uriStr);
167 Source source = resolver.resolveAbsolute(uri);
168 expect(source, isNotNull);
169 expect(source.fullName, _p(posixPath));
170 expect(source.uri, uri);
171 expect(source.exists(), exists);
172 }
173 }
174
175 @reflectiveTest
100 class BazelWorkspaceTest extends _BaseTest { 176 class BazelWorkspaceTest extends _BaseTest {
101 void test_factory_fail_notAbsolute() { 177 void test_factory_fail_notAbsolute() {
102 expect(() => new BazelWorkspace(provider, _p('not_absolute')), 178 expect(() => new BazelWorkspace(provider, _p('not_absolute')),
103 throwsArgumentError); 179 throwsArgumentError);
104 } 180 }
105 181
106 void test_factory_hasReadonlyFolder() { 182 void test_factory_hasReadonlyFolder() {
107 provider.newFolder(_p('/Users/user/test/READONLY/prime')); 183 provider.newFolder(_p('/Users/user/test/READONLY/prime'));
108 provider.newFolder(_p('/Users/user/test/prime')); 184 provider.newFolder(_p('/Users/user/test/prime'));
109 BazelWorkspace workspace = new BazelWorkspace( 185 BazelWorkspace workspace = new BazelWorkspace(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 _p('/workspace/bazel-genfiles/my/module/test3.dart')); 294 _p('/workspace/bazel-genfiles/my/module/test3.dart'));
219 } 295 }
220 } 296 }
221 297
222 class _BaseTest { 298 class _BaseTest {
223 final MemoryResourceProvider provider = new MemoryResourceProvider(); 299 final MemoryResourceProvider provider = new MemoryResourceProvider();
224 300
225 /** 301 /**
226 * Return the [provider] specific path for the given Posix [path]. 302 * Return the [provider] specific path for the given Posix [path].
227 */ 303 */
228 String _p(String path) => provider.convertPath(path); 304 String _p(String path) => provider.convertPath(path);
Brian Wilkerson 2016/10/06 21:55:52 Hah! I missed that before. Much better than 'ppp'
229 } 305 }
OLDNEW
« pkg/analyzer/lib/src/generated/bazel.dart ('K') | « pkg/analyzer/lib/src/generated/bazel.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698