Chromium Code Reviews| Index: tests/compiler/dart2js/dill_loader_test.dart |
| diff --git a/tests/compiler/dart2js/dill_loader_test.dart b/tests/compiler/dart2js/dill_loader_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8857bafeeb0745752ccf15725240c309b80b4481 |
| --- /dev/null |
| +++ b/tests/compiler/dart2js/dill_loader_test.dart |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:async'; |
| +import 'dart:io'; |
| +import 'memory_compiler.dart'; |
| +import 'package:async_helper/async_helper.dart'; |
| +import 'package:compiler/src/diagnostics/spannable.dart' show Spannable; |
| +import 'package:compiler/src/elements/entities.dart' |
| + show LibraryEntity, ClassEntity; |
| +import 'package:compiler/src/kernel/world_builder.dart'; |
| +import 'package:compiler/src/library_loader.dart' |
| + show ScriptLoader, LibraryLoaderTask; |
| +import 'package:compiler/src/script.dart' show Script; |
| +import 'package:compiler/src/apiimpl.dart' show CompilerImpl; |
| +import "package:expect/expect.dart"; |
| +import 'package:path/path.dart' as path; |
| + |
| +/// Run the dartk.dart script, and return the binary encoded results. |
| +List<int> runDartk(Uri filename) { |
| + 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.
|
| + while (path.basename(basePath) != 'sdk') { |
| + basePath = path.dirname(basePath); |
| + } |
| + String dartkPath = |
| + 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.
|
| + |
| + var args = [filename.path, '-fbin', '-ostdout']; |
| + ProcessResult result = Process.runSync( |
| + dartkPath, [filename.path, '-fbin', '-ostdout'], |
| + stdoutEncoding: null); |
| + Expect.equals(0, result.exitCode); |
| + return result.stdout; |
| +} |
| + |
| +class TestScriptLoader implements ScriptLoader { |
| + CompilerImpl compiler; |
| + TestScriptLoader(this.compiler); |
| + |
| + Future<Script> readScript(Uri uri, [Spannable spannable]) => |
| + compiler.readScript(uri, spannable); |
| +} |
| + |
| +/// Test that the compiler can successfully read in .dill kernel files rather |
| +/// than just string source files. |
| +main() { |
| + asyncTest(() async { |
| + 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.
|
| + File entity = new File.fromUri(uri); |
| + DiagnosticCollector diagnostics = new DiagnosticCollector(); |
| + OutputCollector output = new OutputCollector(); |
| + Uri entryPoint = Uri.parse('memory:main.dill'); |
| + List<int> kernelBinary = runDartk(entity.uri); |
| + |
| + CompilerImpl compiler = compilerFor( |
| + entryPoint: entryPoint, |
| + memorySourceFiles: {'main.dill': kernelBinary}, |
| + diagnosticHandler: diagnostics, |
| + outputProvider: output, |
| + options: ['--read-dill']); |
| + await compiler.setupSdk(); |
| + 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
|
| + true, |
| + compiler.resolvedUriTranslator, |
| + new TestScriptLoader(compiler), |
| + null, |
| + null, |
| + null, |
| + null, |
| + null, |
| + compiler.reporter, |
| + compiler.measurer); |
| + |
| + await loader.loadLibrary(entryPoint); |
| + |
| + Expect.equals(0, diagnostics.errors.length); |
| + Expect.equals(0, diagnostics.warnings.length); |
| + |
| + KernelWorldBuilder worldBuilder = loader.worldBuilder; |
| + LibraryEntity library = worldBuilder.lookupLibrary(uri); |
| + Expect.isNotNull(library); |
| + ClassEntity clss = worldBuilder.lookupClass(library, 'ListLiteralTest'); |
| + Expect.isNotNull(clss); |
| + var member = worldBuilder.lookupClassMember(clss, 'testMain'); |
| + Expect.isNotNull(member); |
| + }); |
| +} |