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

Side by Side Diff: pkg/kernel/test/closures/suite.dart

Issue 2561723003: Merge kernel closure conversion into the Dart SDK (Closed)
Patch Set: Remove path constraint Created 4 years 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 | « pkg/kernel/test/closures/kernel_chain.dart ('k') | pkg/kernel/test/closures/testing.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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.md file.
4
5 library test.kernel.closures.suite;
6
7 import 'dart:async' show Future;
8
9 import 'dart:io' show Directory, File, Platform;
10
11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
12
13 import 'package:kernel/analyzer/loader.dart'
14 show DartLoader, DartOptions, createDartSdk;
15
16 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
17
18 import 'package:kernel/repository.dart' show Repository;
19
20 import 'kernel_chain.dart'
21 show MatchExpectation, Print, ReadDill, SanityCheck, WriteDill;
22
23 import 'package:testing/testing.dart'
24 show
25 Chain,
26 ChainContext,
27 Result,
28 StdioProcess,
29 Step,
30 TestDescription,
31 runMe;
32
33 import 'package:kernel/ast.dart' show Program;
34
35 import 'package:kernel/transformations/closure_conversion.dart'
36 as closure_conversion;
37
38 import 'package:package_config/discovery.dart' show loadPackagesFile;
39
40 class TestContext extends ChainContext {
41 final Uri vm;
42
43 final Uri packages;
44
45 final DartOptions options;
46
47 final DartSdk dartSdk;
48
49 final List<Step> steps;
50
51 TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk,
52 bool updateExpectations)
53 : packages = packages,
54 options = new DartOptions(
55 strongMode: strongMode,
56 sdk: sdk,
57 packagePath: packages.toFilePath()),
58 steps = <Step>[
59 const Kernel(),
60 const Print(),
61 const SanityCheck(),
62 const ClosureConversion(),
63 const Print(),
64 const SanityCheck(),
65 new MatchExpectation(".expect",
66 updateExpectations: updateExpectations),
67 const WriteDill(),
68 const ReadDill(),
69 const Run(),
70 ];
71
72 Future<DartLoader> createLoader() async {
73 Repository repository = new Repository();
74 return new DartLoader(repository, options, await loadPackagesFile(packages),
75 dartSdk: dartSdk);
76 }
77 }
78
79 enum Environment {
80 directory,
81 file,
82 }
83
84 Future<String> getEnvironmentVariable(
85 String name, Environment kind, String undefined, notFound(String n)) async {
86 String result = Platform.environment[name];
87 if (result == null) {
88 throw undefined;
89 }
90 switch (kind) {
91 case Environment.directory:
92 if (!await new Directory(result).exists()) throw notFound(result);
93 break;
94
95 case Environment.file:
96 if (!await new File(result).exists()) throw notFound(result);
97 break;
98 }
99 return result;
100 }
101
102 Future<bool> fileExists(Uri base, String path) async {
103 return await new File.fromUri(base.resolve(path)).exists();
104 }
105
106 Future<TestContext> createContext(
107 Chain suite, Map<String, String> environment) async {
108 const String suggestion = """Try building the patched SDK by running
109 'tools/build.py patched_sdk'""";
110
111 // TODO(karlklose): The path is different on MacOS.
112 String sdk = "out/DebugX64/patched_sdk/";
113 Uri sdkUri = Uri.base.resolve(sdk);
114 const String asyncDart = "lib/async/async.dart";
115 if (!await fileExists(sdkUri, asyncDart)) {
116 throw "Couldn't find the patched SDK. $suggestion";
117 }
118 const String asyncSources = "lib/async/async_sources.gypi";
119 if (await fileExists(sdkUri, asyncSources)) {
120 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. "
121 "$suggestion";
122 }
123
124 // TODO(karlklose): select the VM based on the mode.
125 Uri vm = Uri.base.resolve("out/ReleaseX64/dart");
126
127 Uri packages = Uri.base.resolve(".packages");
128 bool strongMode = false;
129 bool updateExpectations = environment["updateExpectations"] != "false";
130 return new TestContext(sdk, vm, packages, strongMode,
131 createDartSdk(sdk, strongMode: strongMode), updateExpectations);
132 }
133
134 class Kernel extends Step<TestDescription, Program, TestContext> {
135 const Kernel();
136
137 String get name => "kernel";
138
139 Future<Result<Program>> run(
140 TestDescription description, TestContext testContext) async {
141 try {
142 DartLoader loader = await testContext.createLoader();
143 Target target = getTarget(
144 "vm", new TargetFlags(strongMode: testContext.options.strongMode));
145 String path = description.file.path;
146 Uri uri = Uri.base.resolve(path);
147 Program program = loader.loadProgram(uri, target: target);
148 for (var error in loader.errors) {
149 return fail(program, "$error");
150 }
151 target.transformProgram(program);
152 return pass(program);
153 } catch (e, s) {
154 return crash(e, s);
155 }
156 }
157 }
158
159 class ClosureConversion extends Step<Program, Program, TestContext> {
160 const ClosureConversion();
161
162 String get name => "closure conversion";
163
164 Future<Result<Program>> run(Program program, TestContext testContext) async {
165 try {
166 program = closure_conversion.transformProgram(program);
167 return pass(program);
168 } catch (e, s) {
169 return crash(e, s);
170 }
171 }
172 }
173
174 class Run extends Step<Uri, int, TestContext> {
175 const Run();
176
177 String get name => "run";
178
179 Future<Result<int>> run(Uri uri, TestContext context) async {
180 File generated = new File.fromUri(uri);
181 StdioProcess process;
182 try {
183 process = await StdioProcess
184 .run(context.vm.toFilePath(), [generated.path, "Hello, World!"]);
185 print(process.output);
186 } finally {
187 generated.parent.delete(recursive: true);
188 }
189 return process.toResult();
190 }
191 }
192
193 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
OLDNEW
« no previous file with comments | « pkg/kernel/test/closures/kernel_chain.dart ('k') | pkg/kernel/test/closures/testing.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698