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

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

Issue 2614063007: Use URIs rather than paths in front end API. (Closed)
Patch Set: Minor fixes 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
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 17 matching lines...) Expand all
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(pathos.posix, '/'); 38 var fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///'));
39 contents.forEach((path, text) { 39 contents.forEach((path, text) {
40 fileSystem.entityForPath(path).writeAsStringSync(text); 40 fileSystem.entityForUri(pathos.posix.toUri(path)).writeAsStringSync(text);
41 }); 41 });
42 // TODO(paulberry): implement and test other option possibilities. 42 // TODO(paulberry): implement and test other option possibilities.
43 var options = new CompilerOptions() 43 var options = new CompilerOptions()
44 ..fileSystem = fileSystem 44 ..fileSystem = fileSystem
45 ..chaseDependencies = true 45 ..chaseDependencies = true
46 ..packagesFilePath = packagesFilePath; 46 ..packagesFilePath = packagesFilePath == ''
47 ? new Uri()
48 : pathos.posix.toUri(packagesFilePath);
47 var graph = await graphForProgram( 49 var graph = await graphForProgram(
48 startingPoints.map(pathos.posix.toUri).toList(), options); 50 startingPoints.map(pathos.posix.toUri).toList(), options);
49 return graph.topologicallySortedCycles; 51 return graph.topologicallySortedCycles;
50 } 52 }
51 53
52 /// Sort the given library cycles into a deterministic order based on their 54 /// Sort the given library cycles into a deterministic order based on their
53 /// URIs for easier unit testing. 55 /// URIs for easier unit testing.
54 List<LibraryCycleNode> sortCycles(Iterable<LibraryCycleNode> cycles) { 56 List<LibraryCycleNode> sortCycles(Iterable<LibraryCycleNode> cycles) {
55 var result = cycles.toList(); 57 var result = cycles.toList();
56 String sortKey(LibraryCycleNode node) => node.libraries.keys.join(','); 58 String sortKey(LibraryCycleNode node) => node.libraries.keys.join(',');
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 expect(bar.dependencies[0], same(foo)); 186 expect(bar.dependencies[0], same(foo));
185 } 187 }
186 188
187 test_singleFile() async { 189 test_singleFile() async {
188 var cycles = await getCycles({'/foo.dart': ''}); 190 var cycles = await getCycles({'/foo.dart': ''});
189 expect(cycles, hasLength(1)); 191 expect(cycles, hasLength(1));
190 expect(cycles[0].libraries, hasLength(1)); 192 expect(cycles[0].libraries, hasLength(1));
191 checkLibrary(cycles[0], 'file:///foo.dart'); 193 checkLibrary(cycles[0], 'file:///foo.dart');
192 } 194 }
193 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698