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