OLD | NEW |
| (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 import 'dart:async'; | |
6 import 'dart:io'; | |
7 import 'memory_compiler.dart'; | |
8 import 'package:async_helper/async_helper.dart'; | |
9 import 'package:compiler/src/diagnostics/spannable.dart' show Spannable; | |
10 import 'package:compiler/src/elements/entities.dart' | |
11 show LibraryEntity, ClassEntity; | |
12 import 'package:compiler/src/kernel/world_builder.dart'; | |
13 import 'package:compiler/src/library_loader.dart' | |
14 show ScriptLoader, LibraryLoaderTask; | |
15 import 'package:compiler/src/script.dart' show Script; | |
16 import 'package:compiler/src/apiimpl.dart' show CompilerImpl; | |
17 import "package:expect/expect.dart"; | |
18 import 'package:path/path.dart' as path; | |
19 | |
20 /// Run the dartk.dart script, and return the binary encoded results. | |
21 List<int> runDartk(Uri filename) { | |
22 String basePath = path.fromUri(Uri.base); | |
23 String dartkPath = | |
24 path.normalize(path.join(basePath, 'tools/dartk_wrappers/dartk')); | |
25 | |
26 var args = [filename.path, '-fbin', '-ostdout']; | |
27 ProcessResult result = Process.runSync( | |
28 dartkPath, [filename.path, '-fbin', '-ostdout'], | |
29 stdoutEncoding: null); | |
30 Expect.equals(0, result.exitCode); | |
31 return result.stdout; | |
32 } | |
33 | |
34 class TestScriptLoader implements ScriptLoader { | |
35 CompilerImpl compiler; | |
36 TestScriptLoader(this.compiler); | |
37 | |
38 Future<Script> readScript(Uri uri, [Spannable spannable]) => | |
39 compiler.readScript(uri, spannable); | |
40 } | |
41 | |
42 /// Test that the compiler can successfully read in .dill kernel files rather | |
43 /// than just string source files. | |
44 main() { | |
45 asyncTest(() async { | |
46 Uri uri = Uri.base.resolve('tests/corelib/list_literal_test.dart'); | |
47 File entity = new File.fromUri(uri); | |
48 DiagnosticCollector diagnostics = new DiagnosticCollector(); | |
49 OutputCollector output = new OutputCollector(); | |
50 Uri entryPoint = Uri.parse('memory:main.dill'); | |
51 List<int> kernelBinary = runDartk(entity.uri); | |
52 | |
53 CompilerImpl compiler = compilerFor( | |
54 entryPoint: entryPoint, | |
55 memorySourceFiles: {'main.dill': kernelBinary}, | |
56 diagnosticHandler: diagnostics, | |
57 outputProvider: output, | |
58 options: ['--read-dill']); | |
59 await compiler.setupSdk(); | |
60 dynamic loader = new LibraryLoaderTask( | |
61 true, | |
62 compiler.resolvedUriTranslator, | |
63 new TestScriptLoader(compiler), | |
64 null, | |
65 null, | |
66 null, | |
67 null, | |
68 null, | |
69 compiler.reporter, | |
70 compiler.measurer); | |
71 | |
72 await loader.loadLibrary(entryPoint); | |
73 | |
74 Expect.equals(0, diagnostics.errors.length); | |
75 Expect.equals(0, diagnostics.warnings.length); | |
76 | |
77 KernelWorldBuilder worldBuilder = loader.worldBuilder; | |
78 LibraryEntity library = worldBuilder.lookupLibrary(uri); | |
79 Expect.isNotNull(library); | |
80 ClassEntity clss = worldBuilder.lookupClass(library, 'ListLiteralTest'); | |
81 Expect.isNotNull(clss); | |
82 var member = worldBuilder.lookupClassMember(clss, 'testMain'); | |
83 Expect.isNotNull(member); | |
84 }); | |
85 } | |
OLD | NEW |