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

Side by Side Diff: pkg/front_end/test/fasta/testing/kernel_chain.dart

Issue 2828583003: remove dependencies to analyzer from lib/src/fasta (Closed)
Patch Set: add copyright Created 3 years, 8 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
(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.md file.
4
5 library front_end.test.fasta.testing.kernel_chain;
Siggi Cherem (dart-lang) 2017/04/19 20:46:18 this is the subset from lib/src/fasta/testing/kern
6
7 import 'dart:async' show Future;
8
9 import 'dart:io' show File;
10
11 import 'package:testing/testing.dart' show Result, StdioProcess, Step;
12
13 import 'package:kernel/ast.dart' show Program;
14
15 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
16
17 import 'package:analyzer/src/kernel/loader.dart'
18 show DartLoader, DartOptions, createDartSdk;
19
20 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
21
22 import 'package:testing/testing.dart'
23 show Chain, ChainContext, Result, StdioProcess, Step, TestDescription;
24
25 import 'package:package_config/discovery.dart' show loadPackagesFile;
26
27 import 'package:front_end/src/fasta/patched_sdk_location.dart';
28
29 const String STRONG_MODE = " strong mode ";
30
31 typedef Future<TestContext> TestContextConstructor(
32 Chain suite,
33 Map<String, String> environment,
34 Uri sdk,
35 Uri vm,
36 Uri packages,
37 bool strongMode,
38 DartSdk dartSdk,
39 bool updateExpectations);
40
41 abstract class TestContext extends ChainContext {
42 final Uri vm;
43
44 final Uri packages;
45
46 final DartOptions options;
47
48 final DartSdk dartSdk;
49
50 TestContext(Uri sdk, this.vm, Uri packages, bool strongMode, this.dartSdk)
51 : packages = packages,
52 options = new DartOptions(
53 strongMode: strongMode,
54 sdk: sdk.toFilePath(),
55 packagePath: packages.toFilePath());
56
57 Future<DartLoader> createLoader() async {
58 Program program = new Program();
59 return new DartLoader(program, options, await loadPackagesFile(packages),
60 ignoreRedirectingFactories: false, dartSdk: dartSdk);
61 }
62
63 static Future<TestContext> create(
64 Chain suite,
65 Map<String, String> environment,
66 TestContextConstructor constructor) async {
67 Uri sdk = await computePatchedSdk();
68 Uri vm = computeDartVm(sdk);
69 Uri packages = Uri.base.resolve(".packages");
70 bool strongMode = environment.containsKey(STRONG_MODE);
71 bool updateExpectations = environment["updateExpectations"] == "true";
72 return constructor(
73 suite,
74 environment,
75 sdk,
76 vm,
77 packages,
78 strongMode,
79 createDartSdk(sdk.toFilePath(), strongMode: strongMode),
80 updateExpectations);
81 }
82 }
83
84 class Kernel extends Step<TestDescription, Program, TestContext> {
85 const Kernel();
86
87 String get name => "kernel";
88
89 Future<Result<Program>> run(
90 TestDescription description, TestContext testContext) async {
91 try {
92 DartLoader loader = await testContext.createLoader();
93 Target target = getTarget(
94 "vm", new TargetFlags(strongMode: testContext.options.strongMode));
95 loader.loadProgram(description.uri, target: target);
96 Program program = loader.program;
97 for (var error in loader.errors) {
98 return fail(program, "$error");
99 }
100 target.performModularTransformations(program);
101 target.performGlobalTransformations(program);
102 return pass(program);
103 } catch (e, s) {
104 return crash(e, s);
105 }
106 }
107 }
108
109 class Run extends Step<Uri, int, TestContext> {
110 const Run();
111
112 String get name => "run";
113
114 bool get isAsync => true;
115
116 bool get isRuntime => true;
117
118 Future<Result<int>> run(Uri uri, TestContext context) async {
119 File generated = new File.fromUri(uri);
120 StdioProcess process;
121 try {
122 process = await StdioProcess
123 .run(context.vm.toFilePath(), [generated.path, "Hello, World!"]);
124 print(process.output);
125 } finally {
126 generated.parent.delete(recursive: true);
127 }
128 return process.toResult();
129 }
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698