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:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
10 import 'package:front_end/src/incremental/byte_store.dart'; | 10 import 'package:front_end/src/incremental/byte_store.dart'; |
(...skipping 16 matching lines...) Expand all Loading... | |
27 /// Virtual filesystem for testing. | 27 /// Virtual filesystem for testing. |
28 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); | 28 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
29 | 29 |
30 /// The used file watcher. | 30 /// The used file watcher. |
31 WatchUsedFilesFn watchFn = (uri, used) {}; | 31 WatchUsedFilesFn watchFn = (uri, used) {}; |
32 | 32 |
33 /// The object under test. | 33 /// The object under test. |
34 IncrementalKernelGeneratorImpl incrementalKernelGenerator; | 34 IncrementalKernelGeneratorImpl incrementalKernelGenerator; |
35 | 35 |
36 /// Compute the initial [Program] for the given [entryPoint]. | 36 /// Compute the initial [Program] for the given [entryPoint]. |
37 Future<Program> getInitialState(Uri entryPoint) async { | 37 Future<Program> getInitialState(Uri entryPoint, |
38 {bool setPackages: true}) async { | |
38 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); | 39 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); |
39 // TODO(scheglov) Builder the SDK kernel and set it into the options. | 40 // TODO(scheglov) Builder the SDK kernel and set it into the options. |
40 | 41 |
41 // TODO(scheglov) Make `.packages` file optional. | 42 // TODO(scheglov) Make `.packages` file optional. |
42 | 43 |
43 var compilerOptions = new CompilerOptions() | 44 var compilerOptions = new CompilerOptions() |
44 ..fileSystem = fileSystem | 45 ..fileSystem = fileSystem |
45 ..byteStore = new MemoryByteStore() | 46 ..byteStore = new MemoryByteStore() |
46 // ..logger = new PerformanceLog(stdout) | 47 // ..logger = new PerformanceLog(stdout) |
47 ..strongMode = true | 48 ..strongMode = true |
48 ..chaseDependencies = true | 49 ..chaseDependencies = true |
49 ..dartLibraries = dartLibraries | 50 ..dartLibraries = dartLibraries; |
50 ..packagesFileUri = Uri.parse('file:///test/.packages'); | 51 |
52 if (setPackages) { | |
53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); | |
54 } | |
51 incrementalKernelGenerator = await IncrementalKernelGenerator | 55 incrementalKernelGenerator = await IncrementalKernelGenerator |
52 .newInstance(compilerOptions, entryPoint, watch: watchFn); | 56 .newInstance(compilerOptions, entryPoint, watch: watchFn); |
53 return (await incrementalKernelGenerator.computeDelta()).newProgram; | 57 return (await incrementalKernelGenerator.computeDelta()).newProgram; |
54 } | 58 } |
55 | 59 |
56 test_compile_chain() async { | 60 test_compile_chain() async { |
57 writeFile('/test/.packages', 'test:lib/'); | 61 writeFile('/test/.packages', 'test:lib/'); |
58 String aPath = '/test/lib/a.dart'; | 62 String aPath = '/test/lib/a.dart'; |
59 String bPath = '/test/lib/b.dart'; | 63 String bPath = '/test/lib/b.dart'; |
60 String cPath = '/test/lib/c.dart'; | 64 String cPath = '/test/lib/c.dart'; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 import self as self; | 227 import self as self; |
224 import "dart:core" as core; | 228 import "dart:core" as core; |
225 | 229 |
226 static method main() → dynamic { | 230 static method main() → dynamic { |
227 core::double v = 2.3; | 231 core::double v = 2.3; |
228 } | 232 } |
229 '''); | 233 '''); |
230 } | 234 } |
231 } | 235 } |
232 | 236 |
237 // Ensures that the `.packages` file can be discovered automatically | |
238 // from the entry point file. | |
scheglov
2017/08/01 21:23:52
Please don't put non-documentation comments outsid
Siggi Cherem (dart-lang)
2017/08/01 21:37:34
Done. (though, that sounds like a bug for the edit
| |
239 test_inferPackagesFile() async { | |
240 writeFile('/test/.packages', 'test:lib/'); | |
241 String path = '/test/lib/test.dart'; | |
242 Uri uri = writeFile(path, r''' | |
243 main() { | |
scheglov
2017/08/01 21:23:52
This is not quite representative test.
I think it
Siggi Cherem (dart-lang)
2017/08/01 21:37:34
Done. Good point. It was before failing as early a
| |
244 var v = 1; | |
245 } | |
246 '''); | |
247 | |
248 String initialText = r''' | |
249 library; | |
250 import self as self; | |
251 import "dart:core" as core; | |
252 | |
253 static method main() → dynamic { | |
254 core::int v = 1; | |
255 } | |
256 '''; | |
257 | |
258 Program program = await getInitialState(uri, setPackages: false); | |
259 Library library = _getLibrary(program, uri); | |
260 expect(_getLibraryText(library), initialText); | |
261 } | |
262 | |
233 test_watch() async { | 263 test_watch() async { |
234 writeFile('/test/.packages', 'test:lib/'); | 264 writeFile('/test/.packages', 'test:lib/'); |
235 String aPath = '/test/lib/a.dart'; | 265 String aPath = '/test/lib/a.dart'; |
236 String bPath = '/test/lib/b.dart'; | 266 String bPath = '/test/lib/b.dart'; |
237 String cPath = '/test/lib/c.dart'; | 267 String cPath = '/test/lib/c.dart'; |
238 Uri aUri = writeFile(aPath, ''); | 268 Uri aUri = writeFile(aPath, ''); |
239 Uri bUri = writeFile(bPath, ''); | 269 Uri bUri = writeFile(bPath, ''); |
240 Uri cUri = writeFile(cPath, r''' | 270 Uri cUri = writeFile(cPath, r''' |
241 import 'a.dart'; | 271 import 'a.dart'; |
242 '''); | 272 '''); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 throw fail('No library found with URI "$uri"'); | 382 throw fail('No library found with URI "$uri"'); |
353 } | 383 } |
354 | 384 |
355 String _getLibraryText(Library library) { | 385 String _getLibraryText(Library library) { |
356 StringBuffer buffer = new StringBuffer(); | 386 StringBuffer buffer = new StringBuffer(); |
357 new Printer(buffer, syntheticNames: new NameSystem()) | 387 new Printer(buffer, syntheticNames: new NameSystem()) |
358 .writeLibraryFile(library); | 388 .writeLibraryFile(library); |
359 return buffer.toString(); | 389 return buffer.toString(); |
360 } | 390 } |
361 } | 391 } |
OLD | NEW |