| 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:io' show File; | 9 import 'dart:io' show File; |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 class FastaContext extends ChainContext { | 80 class FastaContext extends ChainContext { |
| 81 final TranslateUri uriTranslator; | 81 final TranslateUri uriTranslator; |
| 82 final List<Step> steps; | 82 final List<Step> steps; |
| 83 final Uri vm; | 83 final Uri vm; |
| 84 | 84 |
| 85 final ExpectationSet expectationSet = | 85 final ExpectationSet expectationSet = |
| 86 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); | 86 new ExpectationSet.fromJsonList(JSON.decode(EXPECTATIONS)); |
| 87 | 87 |
| 88 Future<Program> platform; | 88 Future<Program> platform; |
| 89 | 89 |
| 90 FastaContext(this.vm, bool strongMode, bool updateExpectations, | 90 FastaContext( |
| 91 this.uriTranslator, bool fullCompile, AstKind astKind) | 91 this.vm, |
| 92 bool strongMode, |
| 93 bool updateExpectations, |
| 94 bool updateComments, |
| 95 this.uriTranslator, |
| 96 bool fullCompile, |
| 97 AstKind astKind) |
| 92 : steps = <Step>[ | 98 : steps = <Step>[ |
| 93 new Outline(fullCompile, astKind, strongMode, | 99 new Outline(fullCompile, astKind, strongMode, |
| 94 updateExpectations: updateExpectations), | 100 updateComments: updateComments), |
| 95 const Print(), | 101 const Print(), |
| 96 new Verify(fullCompile), | 102 new Verify(fullCompile), |
| 97 new MatchExpectation( | 103 new MatchExpectation( |
| 98 fullCompile | 104 fullCompile |
| 99 ? ".${shortenAstKindName(astKind, strongMode)}.expect" | 105 ? ".${shortenAstKindName(astKind, strongMode)}.expect" |
| 100 : ".outline.expect", | 106 : ".outline.expect", |
| 101 updateExpectations: updateExpectations) | 107 updateExpectations: updateExpectations) |
| 102 ] { | 108 ] { |
| 103 if (fullCompile) { | 109 if (fullCompile) { |
| 104 steps.add(const WriteDill()); | 110 steps.add(const WriteDill()); |
| 105 steps.add(const Run()); | 111 steps.add(const Run()); |
| 106 } | 112 } |
| 107 } | 113 } |
| 108 | 114 |
| 109 Future<Program> loadPlatform() { | 115 Future<Program> loadPlatform() { |
| 110 return platform ??= new Future<Program>(() async { | 116 return platform ??= new Future<Program>(() async { |
| 111 Uri sdk = await computePatchedSdk(); | 117 Uri sdk = await computePatchedSdk(); |
| 112 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | 118 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); |
| 113 }); | 119 }); |
| 114 } | 120 } |
| 115 | 121 |
| 116 static Future<FastaContext> create( | 122 static Future<FastaContext> create( |
| 117 Chain suite, Map<String, String> environment) async { | 123 Chain suite, Map<String, String> environment) async { |
| 118 Uri sdk = await computePatchedSdk(); | 124 Uri sdk = await computePatchedSdk(); |
| 119 Uri vm = computeDartVm(sdk); | 125 Uri vm = computeDartVm(sdk); |
| 120 Uri packages = Uri.base.resolve(".packages"); | 126 Uri packages = Uri.base.resolve(".packages"); |
| 121 TranslateUri uriTranslator = await TranslateUri.parse(packages); | 127 TranslateUri uriTranslator = await TranslateUri.parse(packages); |
| 122 bool strongMode = environment.containsKey(STRONG_MODE); | 128 bool strongMode = environment.containsKey(STRONG_MODE); |
| 123 bool updateExpectations = environment["updateExpectations"] == "true"; | 129 bool updateExpectations = environment["updateExpectations"] == "true"; |
| 130 bool updateComments = environment["updateComments"] == "true"; |
| 124 String astKindString = environment[AST_KIND_INDEX]; | 131 String astKindString = environment[AST_KIND_INDEX]; |
| 125 AstKind astKind = | 132 AstKind astKind = |
| 126 astKindString == null ? null : AstKind.values[int.parse(astKindString)]; | 133 astKindString == null ? null : AstKind.values[int.parse(astKindString)]; |
| 127 return new FastaContext(vm, strongMode, updateExpectations, uriTranslator, | 134 return new FastaContext(vm, strongMode, updateExpectations, updateComments, |
| 128 environment.containsKey(ENABLE_FULL_COMPILE), astKind); | 135 uriTranslator, environment.containsKey(ENABLE_FULL_COMPILE), astKind); |
| 129 } | 136 } |
| 130 } | 137 } |
| 131 | 138 |
| 132 class Run extends Step<Uri, int, FastaContext> { | 139 class Run extends Step<Uri, int, FastaContext> { |
| 133 const Run(); | 140 const Run(); |
| 134 | 141 |
| 135 String get name => "run"; | 142 String get name => "run"; |
| 136 | 143 |
| 137 bool get isAsync => true; | 144 bool get isAsync => true; |
| 138 | 145 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 } | 160 } |
| 154 | 161 |
| 155 class Outline extends Step<TestDescription, Program, FastaContext> { | 162 class Outline extends Step<TestDescription, Program, FastaContext> { |
| 156 final bool fullCompile; | 163 final bool fullCompile; |
| 157 | 164 |
| 158 final AstKind astKind; | 165 final AstKind astKind; |
| 159 | 166 |
| 160 final bool strongMode; | 167 final bool strongMode; |
| 161 | 168 |
| 162 const Outline(this.fullCompile, this.astKind, this.strongMode, | 169 const Outline(this.fullCompile, this.astKind, this.strongMode, |
| 163 {this.updateExpectations: false}); | 170 {this.updateComments: false}); |
| 164 | 171 |
| 165 final bool updateExpectations; | 172 final bool updateComments; |
| 166 | 173 |
| 167 String get name { | 174 String get name { |
| 168 return fullCompile ? "${astKind} compile" : "outline"; | 175 return fullCompile ? "${astKind} compile" : "outline"; |
| 169 } | 176 } |
| 170 | 177 |
| 171 bool get isCompiler => fullCompile; | 178 bool get isCompiler => fullCompile; |
| 172 | 179 |
| 173 Future<Result<Program>> run( | 180 Future<Result<Program>> run( |
| 174 TestDescription description, FastaContext context) async { | 181 TestDescription description, FastaContext context) async { |
| 175 Program platform = await context.loadPlatform(); | 182 Program platform = await context.loadPlatform(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 190 if (strongMode) { | 197 if (strongMode) { |
| 191 instrumentation = new ValidatingInstrumentation(); | 198 instrumentation = new ValidatingInstrumentation(); |
| 192 await instrumentation.loadExpectations(description.uri); | 199 await instrumentation.loadExpectations(description.uri); |
| 193 sourceTarget.loader.instrumentation = instrumentation; | 200 sourceTarget.loader.instrumentation = instrumentation; |
| 194 } | 201 } |
| 195 p = await sourceTarget.writeOutline(null); | 202 p = await sourceTarget.writeOutline(null); |
| 196 if (fullCompile) { | 203 if (fullCompile) { |
| 197 p = await sourceTarget.writeProgram(null); | 204 p = await sourceTarget.writeProgram(null); |
| 198 instrumentation?.finish(); | 205 instrumentation?.finish(); |
| 199 if (instrumentation != null && instrumentation.hasProblems) { | 206 if (instrumentation != null && instrumentation.hasProblems) { |
| 200 if (updateExpectations) { | 207 if (updateComments) { |
| 201 await instrumentation.fixSource(description.uri); | 208 await instrumentation.fixSource(description.uri); |
| 202 } else { | 209 } else { |
| 203 return fail(null, instrumentation.problemsAsString); | 210 return fail(null, instrumentation.problemsAsString); |
| 204 } | 211 } |
| 205 } | 212 } |
| 206 } | 213 } |
| 207 } on InputError catch (e, s) { | 214 } on InputError catch (e, s) { |
| 208 return fail(null, e.error, s); | 215 return fail(null, e.error, s); |
| 209 } | 216 } |
| 210 return pass(p); | 217 return pass(p); |
| 211 } | 218 } |
| 212 } | 219 } |
| OLD | NEW |