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

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

Issue 2850413002: Fix issues in interpreter tests (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library test.kernel.closures.suite; 5 library test.kernel.closures.suite;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show File; 9 import 'dart:io' show File;
10 10
11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
12
13 import 'package:analyzer/src/kernel/loader.dart' show DartLoader;
14
15 import 'package:testing/testing.dart' 11 import 'package:testing/testing.dart'
16 show Chain, Result, Step, TestDescription, runMe; 12 show Chain, ChainContext, Result, Step, TestDescription, runMe;
17 13
18 import 'package:kernel/ast.dart' show Program, Library; 14 import 'package:kernel/ast.dart' show Program, Library;
19 15
20 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; 16 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff;
21
22 import 'package:front_end/src/fasta/testing/kernel_chain.dart';
23 17
24 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 18 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
25 19
26 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 20 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
27 21
28 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 22 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
29 show KernelTarget; 23 show KernelTarget;
30 24
31 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 25 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
32 26
33 import 'package:front_end/src/fasta/errors.dart' show InputError; 27 import 'package:front_end/src/fasta/errors.dart' show InputError;
34 28
29 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
30
31 import 'package:kernel/kernel.dart' show loadProgramFromBinary;
32
35 import 'package:kernel/interpreter/interpreter.dart'; 33 import 'package:kernel/interpreter/interpreter.dart';
36 34
37 class InterpreterContext extends TestContext { 35 const String STRONG_MODE = " strong mode ";
36
37 class InterpreterContext extends ChainContext {
38 final bool strongMode;
39
38 final TranslateUri uriTranslator; 40 final TranslateUri uriTranslator;
39 41
40 final List<Step> steps; 42 final List<Step> steps;
41 43
42 Future<Program> platform; 44 Future<Program> platform;
43 45
44 InterpreterContext(Uri sdk, Uri vm, Uri packages, bool strongMode, 46 InterpreterContext(this.strongMode, this.uriTranslator)
45 DartSdk dartSdk, this.uriTranslator)
46 : steps = <Step>[ 47 : steps = <Step>[
47 const FastaCompile(), 48 const FastaCompile(),
48 const Interpret(), 49 const Interpret(),
49 const MatchLogExpectation(".expect"), 50 const MatchLogExpectation(".expect"),
50 ], 51 ];
51 super(sdk, vm, packages, strongMode, dartSdk);
52 52
53 Future<Program> createPlatform() { 53 Future<Program> loadPlatform() async {
54 return new Future<Program>(() async { 54 Uri sdk = await computePatchedSdk();
55 DartLoader loader = await createLoader(); 55 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath());
56 Target target =
57 getTarget("vm", new TargetFlags(strongMode: options.strongMode));
58 loader.loadProgram(Uri.base.resolve("pkg/fasta/test/platform.dart"),
59 target: target);
60 var program = loader.program;
61 if (loader.errors.isNotEmpty) {
62 throw loader.errors.join("\n");
63 }
64 Library mainLibrary = program.mainMethod.enclosingLibrary;
65 program.uriToSource.remove(mainLibrary.fileUri);
66 program = new Program(
67 program.libraries.where((Library l) => l != mainLibrary).toList(),
68 program.uriToSource);
69 target.performModularTransformations(program);
70 target.performGlobalTransformations(program);
71 return program;
72 });
73 } 56 }
74 57
75 static Future<InterpreterContext> create( 58 static Future<InterpreterContext> create(
76 Chain suite, Map<String, String> environment) async { 59 Chain suite, Map<String, String> environment) async {
77 return TestContext.create(suite, environment, (Chain suite, 60 Uri packages = Uri.base.resolve(".packages");
78 Map<String, String> environment, 61 bool strongMode = environment.containsKey(STRONG_MODE);
asgerf 2017/05/02 09:26:03 The string " strong mode ", with spaces, is a key
zhivkag 2017/05/02 09:39:53 I think so, initially I passed false for strong mo
79 Uri sdk, 62 TranslateUri uriTranslator = await TranslateUri.parse(packages);
80 Uri vm, 63 return new InterpreterContext(strongMode, uriTranslator);
81 Uri packages,
82 bool strongMode,
83 DartSdk dartSdk,
84 bool updateExpectations) async {
85 TranslateUri uriTranslator = await TranslateUri.parse(packages);
86 return new InterpreterContext(
87 sdk, vm, packages, strongMode, dartSdk, uriTranslator);
88 });
89 } 64 }
90 } 65 }
91 66
92 class FastaCompile extends Step<TestDescription, Program, InterpreterContext> { 67 class FastaCompile extends Step<TestDescription, Program, InterpreterContext> {
93 const FastaCompile(); 68 const FastaCompile();
94 69
95 String get name => "fasta compile"; 70 String get name => "fasta compile";
96 71
97 Future<Result<Program>> run( 72 Future<Result<Program>> run(
98 TestDescription description, InterpreterContext context) async { 73 TestDescription description, InterpreterContext context) async {
99 Program platform = await context.createPlatform(); 74 Program platform = await context.loadPlatform();
100 Ticker ticker = new Ticker(); 75 Ticker ticker = new Ticker();
101 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); 76 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator);
102 dillTarget.loader 77 dillTarget.loader
103 ..input = Uri.parse("org.dartlang:platform") 78 ..input = Uri.parse("org.dartlang:platform") // Make up a name.
104 ..setProgram(platform); 79 ..setProgram(platform);
105 KernelTarget sourceTarget = 80 KernelTarget sourceTarget =
106 new KernelTarget(dillTarget, context.uriTranslator, false); 81 new KernelTarget(dillTarget, context.uriTranslator, context.strongMode);
107 82
108 Program p; 83 Program p;
109 try { 84 try {
110 sourceTarget.read(description.uri); 85 sourceTarget.read(description.uri);
111 await dillTarget.writeOutline(null); 86 await dillTarget.writeOutline(null);
112 await sourceTarget.writeOutline(null); 87 await sourceTarget.writeOutline(null);
113 p = await sourceTarget.writeProgram(null); 88 p = await sourceTarget.writeProgram(null);
114 } on InputError catch (e, s) { 89 } on InputError catch (e, s) {
115 return fail(null, e.error, s); 90 return fail(null, e.error, s);
116 } 91 }
117
118 return pass(p); 92 return pass(p);
119 } 93 }
120 } 94 }
121 95
122 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> { 96 class Interpret extends Step<Program, EvaluationLog, InterpreterContext> {
123 const Interpret(); 97 const Interpret();
124 98
125 String get name => "interpret"; 99 String get name => "interpret";
126 100
127 Future<Result<EvaluationLog>> run(Program program, _) async { 101 Future<Result<EvaluationLog>> run(Program program, _) async {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 final Uri uri; 147 final Uri uri;
174 148
175 /// Evaluated program log. 149 /// Evaluated program log.
176 final String log; 150 final String log;
177 151
178 EvaluationLog(this.uri, this.log); 152 EvaluationLog(this.uri, this.log);
179 } 153 }
180 154
181 main(List<String> arguments) => 155 main(List<String> arguments) =>
182 runMe(arguments, InterpreterContext.create, "testing.json"); 156 runMe(arguments, InterpreterContext.create, "testing.json");
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698