Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; | |
| 10 | |
| 9 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
| 10 | 12 |
| 11 import 'package:analyzer/src/kernel/loader.dart' show DartLoader; | 13 import 'package:analyzer/src/kernel/loader.dart' |
| 14 show DartLoader, DartOptions, createDartSdk; | |
| 12 | 15 |
| 13 import 'package:testing/testing.dart' | 16 import 'package:testing/testing.dart' |
| 14 show Chain, Result, Step, TestDescription, runMe; | 17 show Chain, Result, Step, TestDescription, runMe; |
| 15 | 18 |
| 16 import 'package:kernel/ast.dart' show Program, Library; | 19 import 'package:kernel/ast.dart' show Program, Library; |
| 17 | 20 |
| 18 import 'package:kernel/transformations/closure_conversion.dart' | 21 import 'package:kernel/transformations/closure_conversion.dart' |
| 19 as closure_conversion; | 22 as closure_conversion; |
| 20 | 23 |
| 21 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; | 24 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; |
| 22 | 25 |
| 23 import 'package:front_end/src/fasta/testing/kernel_chain.dart' | 26 import 'package:front_end/src/fasta/testing/kernel_chain.dart' |
| 24 show TestContext, Print, MatchExpectation, WriteDill, ReadDill, Verify; | 27 show Print, MatchExpectation, WriteDill, ReadDill, Verify; |
| 25 | 28 |
| 26 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 29 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
| 27 | 30 |
| 28 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 31 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
| 29 | 32 |
| 30 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 33 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
| 31 show KernelTarget; | 34 show KernelTarget; |
| 32 | 35 |
| 33 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 36 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
| 34 | 37 |
| 35 import 'package:front_end/src/fasta/errors.dart' show InputError; | 38 import 'package:front_end/src/fasta/errors.dart' show InputError; |
| 36 | 39 |
| 37 class ClosureConversionContext extends TestContext { | 40 import 'package:testing/testing.dart' show Result, StdioProcess, Step; |
| 41 | |
| 42 import 'package:kernel/ast.dart' show Program; | |
| 43 | |
| 44 import 'package:testing/testing.dart' | |
| 45 show Chain, ChainContext, Result, StdioProcess, Step, TestDescription; | |
| 46 | |
| 47 import 'package:package_config/discovery.dart' show loadPackagesFile; | |
| 48 | |
| 49 import 'package:front_end/src/fasta/patched_sdk_location.dart'; | |
| 50 | |
| 51 const String STRONG_MODE = " strong mode "; | |
| 52 | |
| 53 class ClosureConversionContext extends ChainContext { | |
| 54 final Uri vm; | |
| 55 | |
| 56 final Uri packages; | |
| 57 | |
| 58 final DartOptions options; | |
| 59 | |
| 60 final DartSdk dartSdk; | |
| 61 | |
| 38 final TranslateUri uriTranslator; | 62 final TranslateUri uriTranslator; |
| 39 | 63 |
| 40 final List<Step> steps; | 64 final List<Step> steps; |
| 41 | 65 |
| 42 Future<Program> platform; | 66 Future<Program> platform; |
| 43 | 67 |
| 44 ClosureConversionContext(Uri sdk, Uri vm, Uri packages, bool strongMode, | 68 ClosureConversionContext(Uri sdk, this.vm, this.packages, bool strongMode, |
| 45 DartSdk dartSdk, bool updateExpectations, this.uriTranslator) | 69 this.dartSdk, bool updateExpectations, this.uriTranslator) |
| 46 : steps = <Step>[ | 70 : options = new DartOptions( |
| 71 strongMode: strongMode, | |
| 72 sdk: sdk.toFilePath(), | |
| 73 packagePath: packages.toFilePath()), | |
| 74 steps = <Step>[ | |
| 47 const FastaCompile(), | 75 const FastaCompile(), |
| 48 const Print(), | 76 const Print(), |
| 49 const Verify(true), | 77 const Verify(true), |
| 50 const ClosureConversion(), | 78 const ClosureConversion(), |
| 51 const Print(), | 79 const Print(), |
| 52 const Verify(true), | 80 const Verify(true), |
| 53 new MatchExpectation(".expect", | 81 new MatchExpectation(".expect", |
| 54 updateExpectations: updateExpectations), | 82 updateExpectations: updateExpectations), |
| 55 const WriteDill(), | 83 const WriteDill(), |
| 56 const ReadDill(), | 84 const ReadDill(), |
| 57 // TODO(29143): uncomment this when Vectors are added to VM. | 85 // TODO(29143): add `Run` step when Vectors are added to VM. |
| 58 //const Run(), | 86 ]; |
| 59 ], | 87 |
| 60 super(sdk, vm, packages, strongMode, dartSdk); | 88 Future<DartLoader> createLoader() async { |
| 89 Program program = new Program(); | |
| 90 return new DartLoader(program, options, await loadPackagesFile(packages), | |
| 91 ignoreRedirectingFactories: false, dartSdk: dartSdk); | |
| 92 } | |
| 61 | 93 |
| 62 Future<Program> createPlatform() { | 94 Future<Program> createPlatform() { |
| 63 return new Future<Program>(() async { | 95 return new Future<Program>(() async { |
| 64 DartLoader loader = await createLoader(); | 96 DartLoader loader = await createLoader(); |
| 65 Target target = | 97 Target target = |
| 66 getTarget("vm", new TargetFlags(strongMode: options.strongMode)); | 98 getTarget("vm", new TargetFlags(strongMode: options.strongMode)); |
| 67 loader.loadProgram(Uri.base.resolve("pkg/fasta/test/platform.dart"), | 99 loader.loadProgram(Uri.base.resolve("pkg/fasta/test/platform.dart"), |
| 68 target: target); | 100 target: target); |
| 69 var program = loader.program; | 101 var program = loader.program; |
| 70 if (loader.errors.isNotEmpty) { | 102 if (loader.errors.isNotEmpty) { |
| 71 throw loader.errors.join("\n"); | 103 throw loader.errors.join("\n"); |
| 72 } | 104 } |
| 73 Library mainLibrary = program.mainMethod.enclosingLibrary; | 105 Library mainLibrary = program.mainMethod.enclosingLibrary; |
| 74 program.uriToSource.remove(mainLibrary.fileUri); | 106 program.uriToSource.remove(mainLibrary.fileUri); |
| 75 program = new Program( | 107 program = new Program( |
| 76 program.libraries.where((Library l) => l != mainLibrary).toList(), | 108 program.libraries.where((Library l) => l != mainLibrary).toList(), |
| 77 program.uriToSource); | 109 program.uriToSource); |
| 78 target.performModularTransformations(program); | 110 target.performModularTransformations(program); |
| 79 target.performGlobalTransformations(program); | 111 target.performGlobalTransformations(program); |
| 80 return program; | 112 return program; |
| 81 }); | 113 }); |
| 82 } | 114 } |
| 83 | 115 |
| 84 static Future<ClosureConversionContext> create( | 116 static Future<ClosureConversionContext> create( |
| 85 Chain suite, Map<String, String> environment) async { | 117 Chain suite, Map<String, String> environment) async { |
| 86 return TestContext.create(suite, environment, (Chain suite, | 118 Uri sdk = await computePatchedSdk(); |
|
Siggi Cherem (dart-lang)
2017/04/19 20:46:18
The changes in this file (and mainly these lines h
| |
| 87 Map<String, String> environment, | 119 Uri vm = computeDartVm(sdk); |
| 88 Uri sdk, | 120 Uri packages = Uri.base.resolve(".packages"); |
| 89 Uri vm, | 121 bool strongMode = environment.containsKey(STRONG_MODE); |
| 90 Uri packages, | 122 DartSdk dartSdk = createDartSdk(sdk.toFilePath(), strongMode: strongMode); |
| 91 bool strongMode, | 123 bool updateExpectations = environment["updateExpectations"] == "true"; |
| 92 DartSdk dartSdk, | 124 TranslateUri uriTranslator = await TranslateUri.parse(packages); |
| 93 bool updateExpectations) async { | 125 return new ClosureConversionContext(sdk, vm, packages, strongMode, dartSdk, |
| 94 TranslateUri uriTranslator = await TranslateUri.parse(packages); | 126 updateExpectations, uriTranslator); |
| 95 return new ClosureConversionContext(sdk, vm, packages, strongMode, | |
| 96 dartSdk, updateExpectations, uriTranslator); | |
| 97 }); | |
| 98 } | 127 } |
| 99 } | 128 } |
| 100 | 129 |
| 101 Future<ClosureConversionContext> createContext( | 130 Future<ClosureConversionContext> createContext( |
| 102 Chain suite, Map<String, String> environment) async { | 131 Chain suite, Map<String, String> environment) async { |
| 103 environment["updateExpectations"] = | 132 environment["updateExpectations"] = |
| 104 const String.fromEnvironment("updateExpectations"); | 133 const String.fromEnvironment("updateExpectations"); |
| 105 return ClosureConversionContext.create(suite, environment); | 134 return ClosureConversionContext.create(suite, environment); |
| 106 } | 135 } |
| 107 | 136 |
| 108 class FastaCompile | 137 class FastaCompile |
| 109 extends Step<TestDescription, Program, ClosureConversionContext> { | 138 extends Step<TestDescription, Program, ClosureConversionContext> { |
| 110 const FastaCompile(); | 139 const FastaCompile(); |
| 111 | 140 |
| 112 String get name => "fasta compilation"; | 141 String get name => "fasta compilation"; |
| 113 | 142 |
| 114 Future<Result<Program>> run( | 143 Future<Result<Program>> run( |
| 115 TestDescription description, ClosureConversionContext context) async { | 144 TestDescription description, ClosureConversionContext context) async { |
| 116 Program platform = await context.createPlatform(); | 145 Program platform = await context.createPlatform(); |
| 117 Ticker ticker = new Ticker(); | 146 Ticker ticker = new Ticker(); |
| 118 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); | 147 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); |
| 119 dillTarget.loader | 148 dillTarget.loader |
| 120 ..input = Uri.parse("org.dartlang:platform") // Make up a name. | 149 ..input = Uri.parse("org.dartlang:platform") // Make up a name. |
| 121 ..setProgram(platform); | 150 ..setProgram(platform); |
| 122 KernelTarget sourceTarget = | 151 KernelTarget sourceTarget = new KernelTarget( |
| 123 new KernelTarget(dillTarget, context.uriTranslator); | 152 dillTarget, context.uriTranslator, context.options.strongMode); |
| 124 | 153 |
| 125 Program p; | 154 Program p; |
| 126 try { | 155 try { |
| 127 sourceTarget.read(description.uri); | 156 sourceTarget.read(description.uri); |
| 128 await dillTarget.writeOutline(null); | 157 await dillTarget.writeOutline(null); |
| 129 await sourceTarget.writeOutline(null); | 158 await sourceTarget.writeOutline(null); |
| 130 p = await sourceTarget.writeProgram(null); | 159 p = await sourceTarget.writeProgram(null); |
| 131 } on InputError catch (e, s) { | 160 } on InputError catch (e, s) { |
| 132 return fail(null, e.error, s); | 161 return fail(null, e.error, s); |
| 133 } | 162 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 146 try { | 175 try { |
| 147 program = closure_conversion.transformProgram(program); | 176 program = closure_conversion.transformProgram(program); |
| 148 return pass(program); | 177 return pass(program); |
| 149 } catch (e, s) { | 178 } catch (e, s) { |
| 150 return crash(e, s); | 179 return crash(e, s); |
| 151 } | 180 } |
| 152 } | 181 } |
| 153 } | 182 } |
| 154 | 183 |
| 155 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); | 184 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); |
| OLD | NEW |