Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: tests/compiler/dart2js/dill_loader_test.dart

Issue 2976543002: Reapply "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service."" (Closed)
Patch Set: fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/commandline_options.dart'; 9 import 'package:compiler/src/commandline_options.dart';
10 import 'package:compiler/src/common_elements.dart'; 10 import 'package:compiler/src/common_elements.dart';
11 import 'package:compiler/src/diagnostics/spannable.dart' show Spannable; 11 import 'package:compiler/src/diagnostics/spannable.dart' show Spannable;
12 import 'package:compiler/src/elements/entities.dart' 12 import 'package:compiler/src/elements/entities.dart'
13 show LibraryEntity, ClassEntity; 13 show LibraryEntity, ClassEntity;
14 import 'package:compiler/src/io/source_file.dart' show Binary; 14 import 'package:compiler/src/io/source_file.dart' show Binary;
15 import 'package:compiler/src/library_loader.dart' show ScriptLoader; 15 import 'package:compiler/src/library_loader.dart' show ScriptLoader;
16 import 'package:compiler/src/script.dart' show Script; 16 import 'package:compiler/src/script.dart' show Script;
17 import 'package:compiler/src/apiimpl.dart' show CompilerImpl; 17 import 'package:compiler/src/apiimpl.dart' show CompilerImpl;
18 import "package:expect/expect.dart"; 18 import "package:expect/expect.dart";
19 import 'package:path/path.dart' as path; 19 import 'package:front_end/front_end.dart';
20 20 import 'package:front_end/src/fasta/kernel/utils.dart' show serializeProgram;
21 final String dartkExecutable = Platform.isWindows 21 import 'package:compiler/src/kernel/dart2js_target.dart';
22 ? 'tools/dartk_wrappers/dartk.bat' 22 import 'package:kernel/target/targets.dart' show TargetFlags;
23 : 'tools/dartk_wrappers/dartk';
24
25 /// Run the dartk.dart script, and return the binary encoded results.
26 List<int> runDartk(String filename) {
27 String basePath = path.fromUri(Uri.base);
28 String dartkPath = path.normalize(path.join(basePath, dartkExecutable));
29
30 var args = [filename, '-fbin', '-ostdout'];
31 ProcessResult result = Process.runSync(dartkPath, args, stdoutEncoding: null);
32 Expect.equals(0, result.exitCode, result.stderr);
33 return result.stdout;
34 }
35 23
36 class TestScriptLoader implements ScriptLoader { 24 class TestScriptLoader implements ScriptLoader {
37 CompilerImpl compiler; 25 CompilerImpl compiler;
38 TestScriptLoader(this.compiler); 26 TestScriptLoader(this.compiler);
39 27
40 Future<Script> readScript(Uri uri, [Spannable spannable]) => 28 Future<Script> readScript(Uri uri, [Spannable spannable]) =>
41 compiler.readScript(uri, spannable); 29 compiler.readScript(uri, spannable);
42 30
43 Future<Binary> readBinary(Uri uri, [Spannable spannable]) => 31 Future<Binary> readBinary(Uri uri, [Spannable spannable]) =>
44 compiler.readBinary(uri, spannable); 32 compiler.readBinary(uri, spannable);
45 } 33 }
46 34
47 /// Test that the compiler can successfully read in .dill kernel files rather 35 /// Test that the compiler can successfully read in .dill kernel files rather
48 /// than just string source files. 36 /// than just string source files.
49 main() { 37 main() {
50 asyncTest(() async { 38 asyncTest(() async {
51 String filename = 'tests/corelib/list_literal_test.dart'; 39 String filename = 'tests/corelib/list_literal_test.dart';
52 Uri uri = Uri.base.resolve(filename); 40 Uri uri = Uri.base.resolve(filename);
53 DiagnosticCollector diagnostics = new DiagnosticCollector(); 41 DiagnosticCollector diagnostics = new DiagnosticCollector();
54 OutputCollector output = new OutputCollector(); 42 OutputCollector output = new OutputCollector();
55 Uri entryPoint = Uri.parse('memory:main.dill'); 43 Uri entryPoint = Uri.parse('memory:main.dill');
56 List<int> kernelBinary = runDartk(filename);
57 44
45 var platform = Uri
46 .parse(Platform.resolvedExecutable)
47 .resolve('patched_dart2js_sdk/platform.dill');
48 var options = new CompilerOptions()
49 ..target = new Dart2jsTarget(new TargetFlags())
50 ..packagesFileUri = Platform.script.resolve('../../../.packages')
51 ..linkedDependencies = [platform]
52 ..verify = true
53 ..onError = errorHandler;
54
55 List<int> kernelBinary =
56 serializeProgram(await kernelForProgram(uri, options));
58 CompilerImpl compiler = compilerFor( 57 CompilerImpl compiler = compilerFor(
59 entryPoint: entryPoint, 58 entryPoint: entryPoint,
60 memorySourceFiles: {'main.dill': kernelBinary}, 59 memorySourceFiles: {'main.dill': kernelBinary},
61 diagnosticHandler: diagnostics, 60 diagnosticHandler: diagnostics,
62 outputProvider: output, 61 outputProvider: output,
63 options: [Flags.loadFromDill]); 62 options: [Flags.loadFromDill]);
64 await compiler.setupSdk(); 63 await compiler.setupSdk();
65 await compiler.libraryLoader.loadLibrary(entryPoint); 64 await compiler.libraryLoader.loadLibrary(entryPoint);
66 65
67 Expect.equals(0, diagnostics.errors.length); 66 Expect.equals(0, diagnostics.errors.length);
68 Expect.equals(0, diagnostics.warnings.length); 67 Expect.equals(0, diagnostics.warnings.length);
69 68
70 ElementEnvironment environment = 69 ElementEnvironment environment =
71 compiler.frontendStrategy.elementEnvironment; 70 compiler.frontendStrategy.elementEnvironment;
72 LibraryEntity library = environment.lookupLibrary(uri); 71 LibraryEntity library = environment.lookupLibrary(uri);
73 Expect.isNotNull(library); 72 Expect.isNotNull(library);
74 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest'); 73 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest');
75 Expect.isNotNull(clss); 74 Expect.isNotNull(clss);
76 var member = environment.lookupClassMember(clss, 'testMain'); 75 var member = environment.lookupClassMember(clss, 'testMain');
77 Expect.isNotNull(member); 76 Expect.isNotNull(member);
78 }); 77 });
79 } 78 }
79
80 void errorHandler(CompilationError e) {
81 exitCode = 1;
82 print(e.message);
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698