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

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

Issue 2979463002: Revert "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service." (Closed)
Patch Set: 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
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | tools/patch_sdk.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:front_end/front_end.dart'; 19 import 'package:path/path.dart' as path;
20 import 'package:front_end/src/fasta/kernel/utils.dart' show serializeProgram; 20
21 import 'package:compiler/src/kernel/dart2js_target.dart'; 21 final String dartkExecutable = Platform.isWindows
22 import 'package:kernel/target/targets.dart' show TargetFlags; 22 ? 'tools/dartk_wrappers/dartk.bat'
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 }
23 35
24 class TestScriptLoader implements ScriptLoader { 36 class TestScriptLoader implements ScriptLoader {
25 CompilerImpl compiler; 37 CompilerImpl compiler;
26 TestScriptLoader(this.compiler); 38 TestScriptLoader(this.compiler);
27 39
28 Future<Script> readScript(Uri uri, [Spannable spannable]) => 40 Future<Script> readScript(Uri uri, [Spannable spannable]) =>
29 compiler.readScript(uri, spannable); 41 compiler.readScript(uri, spannable);
30 42
31 Future<Binary> readBinary(Uri uri, [Spannable spannable]) => 43 Future<Binary> readBinary(Uri uri, [Spannable spannable]) =>
32 compiler.readBinary(uri, spannable); 44 compiler.readBinary(uri, spannable);
33 } 45 }
34 46
35 /// Test that the compiler can successfully read in .dill kernel files rather 47 /// Test that the compiler can successfully read in .dill kernel files rather
36 /// than just string source files. 48 /// than just string source files.
37 main() { 49 main() {
38 asyncTest(() async { 50 asyncTest(() async {
39 String filename = 'tests/corelib/list_literal_test.dart'; 51 String filename = 'tests/corelib/list_literal_test.dart';
40 Uri uri = Uri.base.resolve(filename); 52 Uri uri = Uri.base.resolve(filename);
41 DiagnosticCollector diagnostics = new DiagnosticCollector(); 53 DiagnosticCollector diagnostics = new DiagnosticCollector();
42 OutputCollector output = new OutputCollector(); 54 OutputCollector output = new OutputCollector();
43 Uri entryPoint = Uri.parse('memory:main.dill'); 55 Uri entryPoint = Uri.parse('memory:main.dill');
56 List<int> kernelBinary = runDartk(filename);
44 57
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));
57 CompilerImpl compiler = compilerFor( 58 CompilerImpl compiler = compilerFor(
58 entryPoint: entryPoint, 59 entryPoint: entryPoint,
59 memorySourceFiles: {'main.dill': kernelBinary}, 60 memorySourceFiles: {'main.dill': kernelBinary},
60 diagnosticHandler: diagnostics, 61 diagnosticHandler: diagnostics,
61 outputProvider: output, 62 outputProvider: output,
62 options: [Flags.loadFromDill]); 63 options: [Flags.loadFromDill]);
63 await compiler.setupSdk(); 64 await compiler.setupSdk();
64 await compiler.libraryLoader.loadLibrary(entryPoint); 65 await compiler.libraryLoader.loadLibrary(entryPoint);
65 66
66 Expect.equals(0, diagnostics.errors.length); 67 Expect.equals(0, diagnostics.errors.length);
67 Expect.equals(0, diagnostics.warnings.length); 68 Expect.equals(0, diagnostics.warnings.length);
68 69
69 ElementEnvironment environment = 70 ElementEnvironment environment =
70 compiler.frontendStrategy.elementEnvironment; 71 compiler.frontendStrategy.elementEnvironment;
71 LibraryEntity library = environment.lookupLibrary(uri); 72 LibraryEntity library = environment.lookupLibrary(uri);
72 Expect.isNotNull(library); 73 Expect.isNotNull(library);
73 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest'); 74 ClassEntity clss = environment.lookupClass(library, 'ListLiteralTest');
74 Expect.isNotNull(clss); 75 Expect.isNotNull(clss);
75 var member = environment.lookupClassMember(clss, 'testMain'); 76 var member = environment.lookupClassMember(clss, 'testMain');
76 Expect.isNotNull(member); 77 Expect.isNotNull(member);
77 }); 78 });
78 } 79 }
79
80 void errorHandler(CompilationError e) {
81 exitCode = 1;
82 print(e.message);
83 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | tools/patch_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698