OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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:analyzer/src/summary/format.dart'; |
7 import 'package:front_end/compiler_options.dart'; | 8 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
9 import 'package:front_end/src/base/processed_options.dart'; | 10 import 'package:front_end/src/base/processed_options.dart'; |
10 import 'package:front_end/src/fasta/fasta.dart' show ByteSink; | |
11 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; | |
12 import 'package:kernel/kernel.dart' show Program, Library; | |
13 | |
14 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
16 | 13 |
17 main() { | 14 main() { |
18 defineReflectiveSuite(() { | 15 defineReflectiveSuite(() { |
19 defineReflectiveTests(ProcessedOptionsTest); | 16 defineReflectiveTests(ProcessedOptionsTest); |
20 }); | 17 }); |
21 } | 18 } |
22 | 19 |
23 @reflectiveTest | 20 @reflectiveTest |
24 class ProcessedOptionsTest { | 21 class ProcessedOptionsTest { |
25 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); | 22 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
26 | 23 |
27 Program _mockOutline; | 24 PackageBundleBuilder _mockSdkSummary; |
28 | 25 |
29 Program get mockSummary => _mockOutline ??= | 26 PackageBundleBuilder get mockSdkSummary => _mockSdkSummary ??= |
30 new Program(libraries: [new Library(Uri.parse('file:///a/b.dart'))]); | 27 new PackageBundleBuilder(apiSignature: 'mock summary signature'); |
| 28 |
| 29 Future<Null> checkMockSummary(CompilerOptions raw) async { |
| 30 var processed = new ProcessedOptions(raw); |
| 31 var sdkSummary = await processed.getSdkSummary(); |
| 32 expect(sdkSummary.apiSignature, mockSdkSummary.apiSignature); |
| 33 } |
31 | 34 |
32 test_compileSdk_false() { | 35 test_compileSdk_false() { |
33 for (var value in [false, true]) { | 36 for (var value in [false, true]) { |
34 var raw = new CompilerOptions()..compileSdk = value; | 37 var raw = new CompilerOptions()..compileSdk = value; |
35 var processed = new ProcessedOptions(raw); | 38 var processed = new ProcessedOptions(raw); |
36 expect(processed.compileSdk, value); | 39 expect(processed.compileSdk, value); |
37 } | 40 } |
38 } | 41 } |
39 | 42 |
40 test_fileSystem_noBazelRoots() { | 43 test_fileSystem_noBazelRoots() { |
41 // When no bazel roots are specified, the filesystem should be passed | 44 // When no bazel roots are specified, the filesystem should be passed |
42 // through unmodified. | 45 // through unmodified. |
43 var raw = new CompilerOptions()..fileSystem = fileSystem; | 46 var raw = new CompilerOptions()..fileSystem = fileSystem; |
44 var processed = new ProcessedOptions(raw); | 47 var processed = new ProcessedOptions(raw); |
45 expect(processed.fileSystem, same(fileSystem)); | 48 expect(processed.fileSystem, same(fileSystem)); |
46 } | 49 } |
47 | 50 |
| 51 test_getSdkSummary_sdkLocationProvided_noTrailingSlash() async { |
| 52 var uri = Uri.parse('file:///sdk'); |
| 53 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum')); |
| 54 checkMockSummary(new CompilerOptions() |
| 55 ..fileSystem = fileSystem |
| 56 ..sdkRoot = uri); |
| 57 } |
| 58 |
| 59 test_getSdkSummary_sdkLocationProvided_spec() async { |
| 60 var uri = Uri.parse('file:///sdk'); |
| 61 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/spec.sum')); |
| 62 checkMockSummary(new CompilerOptions() |
| 63 ..fileSystem = fileSystem |
| 64 ..strongMode = false |
| 65 ..sdkRoot = uri); |
| 66 } |
| 67 |
| 68 test_getSdkSummary_sdkLocationProvided_trailingSlash() async { |
| 69 var uri = Uri.parse('file:///sdk'); |
| 70 writeMockSummaryTo(Uri.parse('$uri/lib/_internal/strong.sum')); |
| 71 checkMockSummary(new CompilerOptions() |
| 72 ..fileSystem = fileSystem |
| 73 ..sdkRoot = Uri.parse('$uri/')); |
| 74 } |
| 75 |
48 test_getSdkSummary_summaryLocationProvided() async { | 76 test_getSdkSummary_summaryLocationProvided() async { |
49 var uri = Uri.parse('file:///sdkSummary'); | 77 var uri = Uri.parse('file:///sdkSummary'); |
50 writeMockSummaryTo(uri); | 78 writeMockSummaryTo(uri); |
51 checkMockSummary(new CompilerOptions() | 79 checkMockSummary(new CompilerOptions() |
52 ..fileSystem = fileSystem | 80 ..fileSystem = fileSystem |
53 ..sdkSummary = uri); | 81 ..sdkSummary = uri); |
54 } | 82 } |
55 | 83 |
56 void writeMockSummaryTo(Uri uri) { | |
57 var sink = new ByteSink(); | |
58 new BinaryPrinter(sink).writeProgramFile(mockSummary); | |
59 fileSystem.entityForUri(uri).writeAsBytesSync(sink.builder.takeBytes()); | |
60 } | |
61 | |
62 Future<Null> checkMockSummary(CompilerOptions raw) async { | |
63 var processed = new ProcessedOptions(raw); | |
64 var sdkSummary = await processed.sdkSummaryProgram; | |
65 expect(sdkSummary.libraries.single.importUri, | |
66 mockSummary.libraries.single.importUri); | |
67 } | |
68 | |
69 test_getUriTranslator_explicitPackagesFile() async { | 84 test_getUriTranslator_explicitPackagesFile() async { |
70 // This .packages file should be ignored. | 85 // This .packages file should be ignored. |
71 fileSystem | 86 fileSystem |
72 .entityForUri(Uri.parse('file:///.packages')) | 87 .entityForUri(Uri.parse('file:///.packages')) |
73 .writeAsStringSync('foo:bar\n'); | 88 .writeAsStringSync('foo:bar\n'); |
74 // This one should be used. | 89 // This one should be used. |
75 fileSystem | 90 fileSystem |
76 .entityForUri(Uri.parse('file:///explicit.packages')) | 91 .entityForUri(Uri.parse('file:///explicit.packages')) |
77 .writeAsStringSync('foo:baz\n'); | 92 .writeAsStringSync('foo:baz\n'); |
78 var raw = new CompilerOptions() | 93 var raw = new CompilerOptions() |
(...skipping 27 matching lines...) Expand all Loading... |
106 fileSystem | 121 fileSystem |
107 .entityForUri(Uri.parse('file:///.packages')) | 122 .entityForUri(Uri.parse('file:///.packages')) |
108 .writeAsStringSync('foo:bar\n'); | 123 .writeAsStringSync('foo:bar\n'); |
109 var raw = new CompilerOptions() | 124 var raw = new CompilerOptions() |
110 ..fileSystem = fileSystem | 125 ..fileSystem = fileSystem |
111 ..packagesFileUri = new Uri(); | 126 ..packagesFileUri = new Uri(); |
112 var processed = new ProcessedOptions(raw); | 127 var processed = new ProcessedOptions(raw); |
113 var uriTranslator = await processed.getUriTranslator(); | 128 var uriTranslator = await processed.getUriTranslator(); |
114 expect(uriTranslator.packages, isEmpty); | 129 expect(uriTranslator.packages, isEmpty); |
115 } | 130 } |
| 131 |
| 132 void writeMockSummaryTo(Uri uri) { |
| 133 fileSystem.entityForUri(uri).writeAsBytesSync(mockSdkSummary.toBuffer()); |
| 134 } |
116 } | 135 } |
OLD | NEW |