OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 fasta.testing.suite; | 5 library fasta.testing.suite; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future; | 8 Future; |
9 | 9 |
10 import 'dart:convert' show | 10 import 'dart:convert' show |
11 JSON; | 11 JSON; |
12 | 12 |
| 13 import 'dart:typed_data' show |
| 14 Uint8List; |
| 15 |
13 import 'package:analyzer/src/generated/sdk.dart' show | 16 import 'package:analyzer/src/generated/sdk.dart' show |
14 DartSdk; | 17 DartSdk; |
15 | 18 |
16 import 'package:kernel/ast.dart' show | 19 import 'package:kernel/ast.dart' show |
17 Library, | 20 Library, |
18 Program; | 21 Program; |
19 | 22 |
| 23 import 'package:kernel/binary/ast_from_binary.dart' show |
| 24 BinaryBuilder; |
| 25 |
| 26 import 'package:kernel/binary/ast_to_binary.dart' show |
| 27 BinaryPrinter; |
| 28 |
| 29 import 'package:kernel/binary/loader.dart' show |
| 30 BinaryLoader; |
| 31 |
| 32 import 'package:kernel/kernel.dart' show |
| 33 Repository; |
| 34 |
20 import 'package:kernel/analyzer/loader.dart' show | 35 import 'package:kernel/analyzer/loader.dart' show |
21 DartLoader; | 36 DartLoader; |
22 | 37 |
23 import 'package:kernel/target/targets.dart' show | 38 import 'package:kernel/target/targets.dart' show |
24 Target, | 39 Target, |
25 TargetFlags, | 40 TargetFlags, |
26 getTarget; | 41 getTarget; |
27 | 42 |
28 import 'package:testing/testing.dart' show | 43 import 'package:testing/testing.dart' show |
29 Chain, | 44 Chain, |
30 ExpectationSet, | 45 ExpectationSet, |
31 Result, | 46 Result, |
32 Step, | 47 Step, |
33 TestDescription; | 48 TestDescription; |
34 | 49 |
35 import '../errors.dart' show | 50 import '../errors.dart' show |
36 InputError; | 51 InputError; |
37 | 52 |
38 import 'kernel_chain.dart' show | 53 import 'kernel_chain.dart' show |
| 54 BytesCollector, |
39 MatchExpectation, | 55 MatchExpectation, |
40 Print, | 56 Print, |
41 Run, | 57 Run, |
| 58 TestContext, |
42 Verify, | 59 Verify, |
43 TestContext, | |
44 WriteDill; | 60 WriteDill; |
45 | 61 |
46 import '../ticker.dart' show | 62 import '../ticker.dart' show |
47 Ticker; | 63 Ticker; |
48 | 64 |
49 import '../translate_uri.dart' show | 65 import '../translate_uri.dart' show |
50 TranslateUri; | 66 TranslateUri; |
51 | 67 |
52 import '../kernel/kernel_target.dart' show | 68 import '../kernel/kernel_target.dart' show |
53 KernelTarget; | 69 KernelTarget; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 106 } |
91 | 107 |
92 class FeContext extends TestContext { | 108 class FeContext extends TestContext { |
93 final TranslateUri uriTranslator; | 109 final TranslateUri uriTranslator; |
94 | 110 |
95 final List<Step> steps; | 111 final List<Step> steps; |
96 | 112 |
97 final ExpectationSet expectationSet = | 113 final ExpectationSet expectationSet = |
98 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); | 114 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); |
99 | 115 |
100 Future<Program> platform; | 116 Future<Uint8List> platform; |
101 | 117 |
102 FeContext(Uri sdk, Uri vm, Uri packages, bool strongMode, | 118 FeContext(Uri sdk, Uri vm, Uri packages, bool strongMode, |
103 DartSdk dartSdk, bool updateExpectations, this.uriTranslator, | 119 DartSdk dartSdk, bool updateExpectations, this.uriTranslator, |
104 bool fullCompile, AstKind astKind) | 120 bool fullCompile, AstKind astKind) |
105 : steps = <Step>[ | 121 : steps = <Step>[ |
106 new Outline(fullCompile, astKind), | 122 new Outline(fullCompile, astKind), |
107 const Print(), | 123 const Print(), |
108 new Verify(fullCompile), | 124 new Verify(fullCompile), |
109 new MatchExpectation( | 125 new MatchExpectation( |
110 fullCompile | 126 fullCompile |
111 ? ".${shortenAstKindName(astKind)}.expect" | 127 ? ".${shortenAstKindName(astKind)}.expect" |
112 : ".outline.expect", | 128 : ".outline.expect", |
113 updateExpectations: updateExpectations) | 129 updateExpectations: updateExpectations) |
114 ], | 130 ], |
115 super(sdk, vm, packages, strongMode, dartSdk) { | 131 super(sdk, vm, packages, strongMode, dartSdk) { |
116 if (fullCompile) { | 132 if (fullCompile) { |
117 steps.add(const WriteDill()); | 133 steps.add(const WriteDill()); |
118 steps.add(const Run()); | 134 steps.add(const Run()); |
119 } | 135 } |
120 } | 136 } |
121 | 137 |
122 Future<Program> createPlatform() { | 138 Future<Program> createPlatform() async { |
123 return platform ??= new Future<Program>(() async { | 139 platform ??= new Future<Uint8List>(() async { |
124 DartLoader loader = await createLoader(); | 140 DartLoader loader = await createLoader(); |
125 Target target = getTarget( | 141 Target target = getTarget( |
126 "vm", new TargetFlags(strongMode: options.strongMode)); | 142 "vm", new TargetFlags(strongMode: options.strongMode)); |
127 Program program = loader.loadProgram( | 143 Program program = loader.loadProgram( |
128 Uri.base.resolve("pkg/fasta/test/platform.dart"), target: target); | 144 Uri.base.resolve("pkg/fasta/test/platform.dart"), target: target); |
129 target.performModularTransformations(program); | |
130 target.performGlobalTransformations(program); | |
131 if (loader.errors.isNotEmpty) { | 145 if (loader.errors.isNotEmpty) { |
132 throw loader.errors.join("\n"); | 146 throw loader.errors.join("\n"); |
133 } | 147 } |
134 Library mainLibrary = program.mainMethod.enclosingLibrary; | 148 Library mainLibrary = program.mainMethod.enclosingLibrary; |
135 program.uriToSource.remove(mainLibrary.fileUri); | 149 program.uriToSource.remove(mainLibrary.fileUri); |
136 return new Program( | 150 Program platform = new Program( |
137 program.libraries.where((Library l) => l != mainLibrary).toList(), | 151 program.libraries.where((Library l) => l != mainLibrary).toList(), |
138 program.uriToSource); | 152 program.uriToSource); |
| 153 target.performModularTransformations(platform); |
| 154 target.performGlobalTransformations(platform); |
| 155 BytesCollector sink = new BytesCollector(); |
| 156 new BinaryPrinter(sink).writeProgramFile(platform); |
| 157 return sink.collect(); |
139 }); | 158 }); |
| 159 BinaryLoader loader = new BinaryLoader(new Repository()); |
| 160 return new BinaryBuilder(loader, await platform).readProgramFile(); |
140 } | 161 } |
141 | 162 |
142 static Future<FeContext> create(Chain suite, Map<String, String> environment, | 163 static Future<FeContext> create(Chain suite, Map<String, String> environment, |
143 Uri sdk, Uri vm, Uri packages, bool strongMode, DartSdk dartSdk, | 164 Uri sdk, Uri vm, Uri packages, bool strongMode, DartSdk dartSdk, |
144 bool updateExpectations) async { | 165 bool updateExpectations) async { |
145 TranslateUri uriTranslator = await TranslateUri.parse(packages); | 166 TranslateUri uriTranslator = await TranslateUri.parse(packages); |
146 String astKindString = environment[AST_KIND_INDEX]; | 167 String astKindString = environment[AST_KIND_INDEX]; |
147 AstKind astKind = astKindString == null | 168 AstKind astKind = astKindString == null |
148 ? null : AstKind.values[int.parse(astKindString)]; | 169 ? null : AstKind.values[int.parse(astKindString)]; |
149 return new FeContext( | 170 return new FeContext( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 p = await sourceTarget.writeOutline(null); | 203 p = await sourceTarget.writeOutline(null); |
183 if (fullCompile) { | 204 if (fullCompile) { |
184 p = await sourceTarget.writeProgram(null, astKind); | 205 p = await sourceTarget.writeProgram(null, astKind); |
185 } | 206 } |
186 } on InputError catch (e, s) { | 207 } on InputError catch (e, s) { |
187 return fail(null, e.error, s); | 208 return fail(null, e.error, s); |
188 } | 209 } |
189 return pass(p); | 210 return pass(p); |
190 } | 211 } |
191 } | 212 } |
OLD | NEW |