Chromium Code Reviews| 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(Platform.script); | |
|
Johnni Winther
2017/04/04 07:25:20
Use `String basePath = path.fromUri(Uri.base);` an
Emily Fortuna
2017/04/04 20:03:52
Done.
| |
| 23 while (path.basename(basePath) != 'sdk') { | |
| 24 basePath = path.dirname(basePath); | |
| 25 } | |
| 26 String dartkPath = | |
| 27 path.normalize(path.join(basePath, 'tools/dartk_wrappers/dartk')); | |
|
Johnni Winther
2017/04/04 07:25:20
This won't work on Windows. I'll fix it when you l
Emily Fortuna
2017/04/04 20:03:53
I know, but I thought as per our discussion, that
Johnni Winther
2017/04/05 06:53:42
Yes. I'll fix it.
| |
| 28 | |
| 29 var args = [filename.path, '-fbin', '-ostdout']; | |
| 30 ProcessResult result = Process.runSync( | |
| 31 dartkPath, [filename.path, '-fbin', '-ostdout'], | |
| 32 stdoutEncoding: null); | |
| 33 Expect.equals(0, result.exitCode); | |
| 34 return result.stdout; | |
| 35 } | |
| 36 | |
| 37 class TestScriptLoader implements ScriptLoader { | |
| 38 CompilerImpl compiler; | |
| 39 TestScriptLoader(this.compiler); | |
| 40 | |
| 41 Future<Script> readScript(Uri uri, [Spannable spannable]) => | |
| 42 compiler.readScript(uri, spannable); | |
| 43 } | |
| 44 | |
| 45 /// Test that the compiler can successfully read in .dill kernel files rather | |
| 46 /// than just string source files. | |
| 47 main() { | |
| 48 asyncTest(() async { | |
| 49 Uri uri = Platform.script.resolve('../../corelib/list_literal_test.dart'); | |
|
Johnni Winther
2017/04/04 07:25:20
Use `Uri.base.resolve('tests/corelib/list_literal_
Emily Fortuna
2017/04/04 20:03:52
Done.
| |
| 50 File entity = new File.fromUri(uri); | |
| 51 DiagnosticCollector diagnostics = new DiagnosticCollector(); | |
| 52 OutputCollector output = new OutputCollector(); | |
| 53 Uri entryPoint = Uri.parse('memory:main.dill'); | |
| 54 List<int> kernelBinary = runDartk(entity.uri); | |
| 55 | |
| 56 CompilerImpl compiler = compilerFor( | |
| 57 entryPoint: entryPoint, | |
| 58 memorySourceFiles: {'main.dill': kernelBinary}, | |
| 59 diagnosticHandler: diagnostics, | |
| 60 outputProvider: output, | |
| 61 options: ['--read-dill']); | |
| 62 await compiler.setupSdk(); | |
| 63 LibraryLoaderTask loader = new LibraryLoaderTask( | |
|
Johnni Winther
2017/04/04 07:25:20
`LibraryLoaderTask loader` -> `dynamic loader`
Th
Emily Fortuna
2017/04/04 20:03:53
Is that really an improvement, that way we would n
Johnni Winther
2017/04/05 06:53:41
We are relying on implementation details (that the
| |
| 64 true, | |
| 65 compiler.resolvedUriTranslator, | |
| 66 new TestScriptLoader(compiler), | |
| 67 null, | |
| 68 null, | |
| 69 null, | |
| 70 null, | |
| 71 null, | |
| 72 compiler.reporter, | |
| 73 compiler.measurer); | |
| 74 | |
| 75 await loader.loadLibrary(entryPoint); | |
| 76 | |
| 77 Expect.equals(0, diagnostics.errors.length); | |
| 78 Expect.equals(0, diagnostics.warnings.length); | |
| 79 | |
| 80 KernelWorldBuilder worldBuilder = loader.worldBuilder; | |
| 81 LibraryEntity library = worldBuilder.lookupLibrary(uri); | |
| 82 Expect.isNotNull(library); | |
| 83 ClassEntity clss = worldBuilder.lookupClass(library, 'ListLiteralTest'); | |
| 84 Expect.isNotNull(clss); | |
| 85 var member = worldBuilder.lookupClassMember(clss, 'testMain'); | |
| 86 Expect.isNotNull(member); | |
| 87 }); | |
| 88 } | |
| OLD | NEW |