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

Side by Side Diff: pkg/front_end/test/dependency_grapher_test.dart

Issue 2979003002: support resolving .packages in FE (Closed)
Patch Set: cl comments Created 3 years, 5 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/front_end/messages.yaml ('k') | pkg/front_end/test/fasta/uri_translator_test.dart » ('j') | 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) 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:front_end/compiler_options.dart'; 7 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/dependency_grapher.dart'; 8 import 'package:front_end/dependency_grapher.dart';
9 import 'package:front_end/memory_file_system.dart'; 9 import 'package:front_end/memory_file_system.dart';
10 import 'package:path/path.dart' as pathos; 10 import 'package:path/path.dart' as pathos;
(...skipping 13 matching lines...) Expand all
24 List<String> parts: const []}) { 24 List<String> parts: const []}) {
25 var library = cycle.libraries[Uri.parse(uri)]; 25 var library = cycle.libraries[Uri.parse(uri)];
26 expect('${library.uri}', uri); 26 expect('${library.uri}', uri);
27 expect(library.dependencies.map((dep) => '${dep.uri}'), 27 expect(library.dependencies.map((dep) => '${dep.uri}'),
28 unorderedEquals(dependencies)); 28 unorderedEquals(dependencies));
29 expect(library.parts.map((part) => '$part'), unorderedEquals(parts)); 29 expect(library.parts.map((part) => '$part'), unorderedEquals(parts));
30 return library; 30 return library;
31 } 31 }
32 32
33 Future<List<LibraryCycleNode>> getCycles(Map<String, String> contents, 33 Future<List<LibraryCycleNode>> getCycles(Map<String, String> contents,
34 {List<String> startingPoints, String packagesFilePath = ''}) async { 34 {List<String> startingPoints, String packagesFilePath}) async {
35 // If no starting points given, assume the first entry in [contents] is the 35 // If no starting points given, assume the first entry in [contents] is the
36 // single starting point. 36 // single starting point.
37 startingPoints ??= [contents.keys.first]; 37 startingPoints ??= [contents.keys.first];
38 var fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 38 var fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
39 if (packagesFilePath == null) {
40 fileSystem.entityForUri(Uri.parse('.packages')).writeAsStringSync('');
41 }
39 contents.forEach((path, text) { 42 contents.forEach((path, text) {
40 fileSystem.entityForUri(pathos.posix.toUri(path)).writeAsStringSync(text); 43 fileSystem.entityForUri(pathos.posix.toUri(path)).writeAsStringSync(text);
41 }); 44 });
42 // TODO(paulberry): implement and test other option possibilities. 45 // TODO(paulberry): implement and test other option possibilities.
43 var options = new CompilerOptions() 46 var options = new CompilerOptions()
44 ..fileSystem = fileSystem 47 ..fileSystem = fileSystem
45 ..chaseDependencies = true 48 ..chaseDependencies = true
46 ..packagesFileUri = packagesFilePath == '' 49 ..packagesFileUri = packagesFilePath == null
47 ? new Uri() 50 ? Uri.parse('.packages')
48 : pathos.posix.toUri(packagesFilePath); 51 : pathos.posix.toUri(packagesFilePath);
49 var graph = await graphForProgram( 52 var graph = await graphForProgram(
50 startingPoints.map(pathos.posix.toUri).toList(), options); 53 startingPoints.map(pathos.posix.toUri).toList(), options);
51 return graph.topologicallySortedCycles; 54 return graph.topologicallySortedCycles;
52 } 55 }
53 56
54 /// Sort the given library cycles into a deterministic order based on their 57 /// Sort the given library cycles into a deterministic order based on their
55 /// URIs for easier unit testing. 58 /// URIs for easier unit testing.
56 List<LibraryCycleNode> sortCycles(Iterable<LibraryCycleNode> cycles) { 59 List<LibraryCycleNode> sortCycles(Iterable<LibraryCycleNode> cycles) {
57 var result = cycles.toList(); 60 var result = cycles.toList();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 expect(bar.dependencies[0], same(foo)); 189 expect(bar.dependencies[0], same(foo));
187 } 190 }
188 191
189 test_singleFile() async { 192 test_singleFile() async {
190 var cycles = await getCycles({'/foo.dart': ''}); 193 var cycles = await getCycles({'/foo.dart': ''});
191 expect(cycles, hasLength(1)); 194 expect(cycles, hasLength(1));
192 expect(cycles[0].libraries, hasLength(1)); 195 expect(cycles[0].libraries, hasLength(1));
193 checkLibrary(cycles[0], 'file:///foo.dart'); 196 checkLibrary(cycles[0], 'file:///foo.dart');
194 } 197 }
195 } 198 }
OLDNEW
« no previous file with comments | « pkg/front_end/messages.yaml ('k') | pkg/front_end/test/fasta/uri_translator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698