| 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 Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import '../ticker.dart' show Ticker; | 27 import '../ticker.dart' show Ticker; |
| 28 | 28 |
| 29 import '../translate_uri.dart' show TranslateUri; | 29 import '../translate_uri.dart' show TranslateUri; |
| 30 | 30 |
| 31 import '../analyzer/analyzer_target.dart' show AnalyzerTarget; | 31 import '../analyzer/analyzer_target.dart' show AnalyzerTarget; |
| 32 | 32 |
| 33 import '../kernel/kernel_target.dart' show KernelTarget; | 33 import '../kernel/kernel_target.dart' show KernelTarget; |
| 34 | 34 |
| 35 import '../dill/dill_target.dart' show DillTarget; | 35 import '../dill/dill_target.dart' show DillTarget; |
| 36 | 36 |
| 37 export 'kernel_chain.dart' show TestContext; | 37 export 'kernel_chain.dart' show STRONG_MODE, TestContext; |
| 38 | 38 |
| 39 export 'package:testing/testing.dart' show Chain, runMe; | 39 export 'package:testing/testing.dart' show Chain, runMe; |
| 40 | 40 |
| 41 const String ENABLE_FULL_COMPILE = " full compile "; | 41 const String ENABLE_FULL_COMPILE = " full compile "; |
| 42 | 42 |
| 43 const String AST_KIND_INDEX = " AST kind index "; | 43 const String AST_KIND_INDEX = " AST kind index "; |
| 44 | 44 |
| 45 const String EXPECTATIONS = ''' | 45 const String EXPECTATIONS = ''' |
| 46 [ | 46 [ |
| 47 { | 47 { |
| 48 "name": "VerificationError", | 48 "name": "VerificationError", |
| 49 "group": "Fail" | 49 "group": "Fail" |
| 50 } | 50 } |
| 51 ] | 51 ] |
| 52 '''; | 52 '''; |
| 53 | 53 |
| 54 String shortenAstKindName(AstKind astKind) { | 54 String shortenAstKindName(AstKind astKind, bool strongMode) { |
| 55 switch (astKind) { | 55 switch (astKind) { |
| 56 case AstKind.Analyzer: | 56 case AstKind.Analyzer: |
| 57 return "dartk"; | 57 return strongMode ? "dartk-strong" : "dartk"; |
| 58 case AstKind.Kernel: | 58 case AstKind.Kernel: |
| 59 return "direct"; | 59 return strongMode ? "strong" : "direct"; |
| 60 } | 60 } |
| 61 throw "Unknown AST kind: $astKind"; | 61 throw "Unknown AST kind: $astKind"; |
| 62 } | 62 } |
| 63 | 63 |
| 64 enum AstKind { | 64 enum AstKind { |
| 65 Analyzer, | 65 Analyzer, |
| 66 Kernel, | 66 Kernel, |
| 67 } | 67 } |
| 68 | 68 |
| 69 class FastaContext extends TestContext { | 69 class FastaContext extends TestContext { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 Uri sdk, | 80 Uri sdk, |
| 81 Uri vm, | 81 Uri vm, |
| 82 Uri packages, | 82 Uri packages, |
| 83 bool strongMode, | 83 bool strongMode, |
| 84 DartSdk dartSdk, | 84 DartSdk dartSdk, |
| 85 bool updateExpectations, | 85 bool updateExpectations, |
| 86 this.uriTranslator, | 86 this.uriTranslator, |
| 87 bool fullCompile, | 87 bool fullCompile, |
| 88 AstKind astKind) | 88 AstKind astKind) |
| 89 : steps = <Step>[ | 89 : steps = <Step>[ |
| 90 new Outline(fullCompile, astKind), | 90 new Outline(fullCompile, astKind, strongMode), |
| 91 const Print(), | 91 const Print(), |
| 92 new Verify(fullCompile), | 92 new Verify(fullCompile), |
| 93 new MatchExpectation( | 93 new MatchExpectation( |
| 94 fullCompile | 94 fullCompile |
| 95 ? ".${shortenAstKindName(astKind)}.expect" | 95 ? ".${shortenAstKindName(astKind, strongMode)}.expect" |
| 96 : ".outline.expect", | 96 : ".outline.expect", |
| 97 updateExpectations: updateExpectations) | 97 updateExpectations: updateExpectations) |
| 98 ], | 98 ], |
| 99 super(sdk, vm, packages, strongMode, dartSdk) { | 99 super(sdk, vm, packages, strongMode, dartSdk) { |
| 100 if (fullCompile) { | 100 if (fullCompile) { |
| 101 steps.add(const WriteDill()); | 101 steps.add(const WriteDill()); |
| 102 steps.add(const Run()); | 102 steps.add(const Run()); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 astKind); | 152 astKind); |
| 153 }); | 153 }); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 class Outline extends Step<TestDescription, Program, FastaContext> { | 157 class Outline extends Step<TestDescription, Program, FastaContext> { |
| 158 final bool fullCompile; | 158 final bool fullCompile; |
| 159 | 159 |
| 160 final AstKind astKind; | 160 final AstKind astKind; |
| 161 | 161 |
| 162 const Outline(this.fullCompile, this.astKind); | 162 final bool strongMode; |
| 163 |
| 164 const Outline(this.fullCompile, this.astKind, this.strongMode); |
| 163 | 165 |
| 164 String get name { | 166 String get name { |
| 165 return fullCompile ? "${astKind} compile" : "outline"; | 167 return fullCompile ? "${astKind} compile" : "outline"; |
| 166 } | 168 } |
| 167 | 169 |
| 168 bool get isCompiler => fullCompile; | 170 bool get isCompiler => fullCompile; |
| 169 | 171 |
| 170 Future<Result<Program>> run( | 172 Future<Result<Program>> run( |
| 171 TestDescription description, FastaContext context) async { | 173 TestDescription description, FastaContext context) async { |
| 172 Program platform = await context.createPlatform(); | 174 Program platform = await context.createPlatform(); |
| 173 Ticker ticker = new Ticker(); | 175 Ticker ticker = new Ticker(); |
| 174 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); | 176 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); |
| 175 dillTarget.loader | 177 dillTarget.loader |
| 176 ..input = Uri.parse("org.dartlang:platform") // Make up a name. | 178 ..input = Uri.parse("org.dartlang:platform") // Make up a name. |
| 177 ..setProgram(platform); | 179 ..setProgram(platform); |
| 178 KernelTarget sourceTarget = astKind == AstKind.Analyzer | 180 KernelTarget sourceTarget = astKind == AstKind.Analyzer |
| 179 ? new AnalyzerTarget(dillTarget, context.uriTranslator) | 181 ? new AnalyzerTarget(dillTarget, context.uriTranslator, strongMode) |
| 180 : new KernelTarget(dillTarget, context.uriTranslator); | 182 : new KernelTarget(dillTarget, context.uriTranslator, strongMode); |
| 181 | 183 |
| 182 Program p; | 184 Program p; |
| 183 try { | 185 try { |
| 184 sourceTarget.read(description.uri); | 186 sourceTarget.read(description.uri); |
| 185 await dillTarget.writeOutline(null); | 187 await dillTarget.writeOutline(null); |
| 186 p = await sourceTarget.writeOutline(null); | 188 p = await sourceTarget.writeOutline(null); |
| 187 if (fullCompile) { | 189 if (fullCompile) { |
| 188 p = await sourceTarget.writeProgram(null); | 190 p = await sourceTarget.writeProgram(null); |
| 189 } | 191 } |
| 190 } on InputError catch (e, s) { | 192 } on InputError catch (e, s) { |
| 191 return fail(null, e.error, s); | 193 return fail(null, e.error, s); |
| 192 } | 194 } |
| 193 return pass(p); | 195 return pass(p); |
| 194 } | 196 } |
| 195 } | 197 } |
| OLD | NEW |