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

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

Issue 2651613003: Added support for GN workspaces. (Closed)
Patch Set: Tests Created 3 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/gn.dart ('k') | pkg/analyzer/test/generated/test_all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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.generated.gn_test;
6
7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/generated/gn.dart';
9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12
13 main() {
14 defineReflectiveSuite(() {
15 defineReflectiveTests(GnPackageUriResolverTest);
16 defineReflectiveTests(GnWorkspaceTest);
17 });
18 }
19
20 @reflectiveTest
21 class GnPackageUriResolverTest extends _BaseTest {
22 GnWorkspace workspace;
23 GnPackageUriResolver resolver;
24
25 void test_resolve() {
26 _addResources([
27 '/workspace/.jiri_root/',
28 '/workspace/out/debug-x87_128/gen/dart.sources/',
29 '/workspace/some/code/',
30 '/workspace/a/source/code.dart',
31 ]);
32 provider.newFile(
33 _p('/workspace/out/debug-x87_128/gen/dart.sources/flutter'),
34 '/workspace/a/source');
35 _setUp();
36 _assertResolve(
37 'package:flutter/code.dart', '/workspace/a/source/code.dart');
38 }
39
40 void test_resolveDoesNotExist() {
41 _addResources([
42 '/workspace/.jiri_root/',
43 '/workspace/out/debug-x87_128/gen/dart.sources/',
44 '/workspace/some/code/',
45 '/workspace/a/source/code.dart',
46 ]);
47 provider.newFile(
48 _p('/workspace/out/debug-x87_128/gen/dart.sources/flutter'),
49 '/workspace/a/source');
50 _setUp();
51 expect(
52 resolver.resolveAbsolute(Uri.parse('package:bogus/code.dart')), null);
53 }
54
55 void _addResources(List<String> paths) {
56 for (String path in paths) {
57 if (path.endsWith('/')) {
58 provider.newFolder(_p(path.substring(0, path.length - 1)));
59 } else {
60 provider.newFile(_p(path), '');
61 }
62 }
63 }
64
65 void _setUp() {
66 workspace = GnWorkspace.find(provider, _p('/workspace'));
67 resolver = new GnPackageUriResolver(workspace);
68 }
69
70 void _assertResolve(String uriStr, String posixPath,
71 {bool exists: true, bool restore: true}) {
72 Uri uri = Uri.parse(uriStr);
73 Source source = resolver.resolveAbsolute(uri);
74 expect(source, isNotNull);
75 expect(source.fullName, _p(posixPath));
76 expect(source.uri, uri);
77 expect(source.exists(), exists);
78 // If enabled, test also "restoreAbsolute".
79 if (restore) {
80 Uri uri = resolver.restoreAbsolute(source);
81 expect(uri.toString(), uriStr);
82 }
83 }
84 }
85
86 @reflectiveTest
87 class GnWorkspaceTest extends _BaseTest {
88 void test_find_notAbsolute() {
89 expect(() => GnWorkspace.find(provider, _p('not_absolute')),
90 throwsArgumentError);
91 }
92
93 void test_find_noJiriRoot() {
94 provider.newFolder(_p('/workspace'));
95 GnWorkspace workspace = GnWorkspace.find(provider, _p('/workspace'));
96 expect(workspace, isNull);
97 }
98
99 void test_find_withRoot() {
100 provider.newFolder(_p('/workspace/.jiri_root'));
101 provider.newFolder(_p('/workspace/out/debug-x87_128/gen/dart.sources'));
102 provider.newFolder(_p('/workspace/some/code'));
103 GnWorkspace workspace =
104 GnWorkspace.find(provider, _p('/workspace/some/code'));
105 expect(workspace, isNotNull);
106 expect(workspace.root, _p('/workspace'));
107 }
108
109 void test_packages() {
110 provider.newFolder(_p('/workspace/.jiri_root'));
111 provider.newFolder(_p('/workspace/out/debug-x87_128/gen/dart.sources'));
112 provider.newFile(
113 _p('/workspace/out/debug-x87_128/gen/dart.sources/flutter'),
114 '/path/to/source');
115 provider.newFolder(_p('/workspace/some/code'));
116 GnWorkspace workspace =
117 GnWorkspace.find(provider, _p('/workspace/some/code'));
118 expect(workspace, isNotNull);
119 expect(workspace.root, _p('/workspace'));
120 expect(workspace.packages.length, 1);
121 expect(workspace.packages['flutter'], '/path/to/source');
122 }
123 }
124
125 class _BaseTest {
126 final MemoryResourceProvider provider = new MemoryResourceProvider();
127
128 /**
129 * Return the [provider] specific path for the given Posix [path].
130 */
131 String _p(String path) => provider.convertPath(path);
132 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/gn.dart ('k') | pkg/analyzer/test/generated/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698