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

Side by Side Diff: pkg/analyzer/test/src/task/strong/front_end_inference_test.dart

Issue 2844353002: Wrap front-end inference tests into a reflective test. (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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/src/dart/analysis/driver.dart'; 13 import 'package:analyzer/src/dart/analysis/driver.dart';
14 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
15 import 'package:front_end/src/base/instrumentation.dart' as fasta; 15 import 'package:front_end/src/base/instrumentation.dart' as fasta;
16 import 'package:front_end/src/fasta/compiler_context.dart' as fasta; 16 import 'package:front_end/src/fasta/compiler_context.dart' as fasta;
17 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' 17 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart'
18 as fasta; 18 as fasta;
19 import 'package:kernel/kernel.dart' as fasta; 19 import 'package:kernel/kernel.dart' as fasta;
20 import 'package:path/path.dart' as pathos; 20 import 'package:path/path.dart' as pathos;
21 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
22 import 'package:test_reflective_loader/test_reflective_loader.dart';
22 23
23 import '../../dart/analysis/base.dart'; 24 import '../../dart/analysis/base.dart';
24 25
25 Future<Null> main() async { 26 main() {
26 await _runFrontEndInferenceTests(); 27 defineReflectiveSuite(() {
28 defineReflectiveTests(RunFrontEndInferenceTest);
29 });
27 } 30 }
28 31
29 /** 32 @reflectiveTest
30 * Expects that the [Platform.script] is a test inside of `pkg/analyzer/test` 33 class RunFrontEndInferenceTest {
31 * folder, and return the absolute path of the `pkg` folder. 34 test_run() async {
32 */ 35 String pkgPath = _findPkgRoot();
33 String _findPkgRoot() { 36 String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference');
34 String scriptPath = pathos.fromUri(Platform.script); 37 List<File> dartFiles = new Directory(fePath)
35 List<String> parts = pathos.split(scriptPath); 38 .listSync()
36 for (int i = 0; i < parts.length - 2; i++) { 39 .where((entry) => entry is File && entry.path.endsWith('.dart'))
37 if (parts[i] == 'pkg' && 40 .map((entry) => entry as File)
38 parts[i + 1] == 'analyzer' && 41 .toList();
39 parts[i + 2] == 'test') { 42
40 return pathos.joinAll(parts.sublist(0, i + 1)); 43 var allProblems = new StringBuffer();
44 for (File file in dartFiles) {
45 var test = new _FrontEndInferenceTest();
46 await test.setUp();
47 try {
48 String code = file.readAsStringSync();
49 await test.runTest(file.path, code);
50 } on String catch (problems) {
51 allProblems.writeln(problems);
52 } finally {
53 await test.tearDown();
54 }
55 }
56 if (allProblems.isNotEmpty) {
57 fail(allProblems.toString());
41 } 58 }
42 } 59 }
43 throw new StateError('Unable to find sdk/pkg/ in $scriptPath');
44 }
45 60
46 Future<Null> _runFrontEndInferenceTests() async { 61 /**
47 String pkgPath = _findPkgRoot(); 62 * Expects that the [Platform.script] is a test inside of `pkg/analyzer/test`
48 String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference'); 63 * folder, and return the absolute path of the `pkg` folder.
49 List<File> dartFiles = new Directory(fePath) 64 */
50 .listSync() 65 String _findPkgRoot() {
51 .where((entry) => entry is File && entry.path.endsWith('.dart')) 66 String scriptPath = pathos.fromUri(Platform.script);
52 .map((entry) => entry as File) 67 List<String> parts = pathos.split(scriptPath);
53 .toList(); 68 for (int i = 0; i < parts.length - 2; i++) {
54 69 if (parts[i] == 'pkg' &&
55 for (File file in dartFiles) { 70 parts[i + 1] == 'analyzer' &&
56 var test = new _FrontEndInferenceTest(); 71 parts[i + 2] == 'test') {
57 await test.setUp(); 72 return pathos.joinAll(parts.sublist(0, i + 1));
58 try { 73 }
59 String code = file.readAsStringSync();
60 await test.runTest(file.path, code);
61 } catch (_) {
62 print(_);
63 } finally {
64 await test.tearDown();
65 } 74 }
75 throw new StateError('Unable to find sdk/pkg/ in $scriptPath');
66 } 76 }
67 } 77 }
68 78
69 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { 79 class _FrontEndInferenceTest extends BaseAnalysisDriverTest {
70 Future<Null> runTest(String path, String code) async { 80 Future<Null> runTest(String path, String code) async {
71 Uri uri = provider.pathContext.toUri(path); 81 Uri uri = provider.pathContext.toUri(path);
72 82
73 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; 83 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts;
74 fasta.CompilerContext.current.uriToSource[uri.toString()] = 84 fasta.CompilerContext.current.uriToSource[uri.toString()] =
75 new fasta.Source(lineStarts, UTF8.encode(code)); 85 new fasta.Source(lineStarts, UTF8.encode(code));
76 86
77 var validation = new fasta.ValidatingInstrumentation(); 87 var validation = new fasta.ValidatingInstrumentation();
78 await validation.loadExpectations(uri); 88 await validation.loadExpectations(uri);
79 89
80 provider.newFile(path, code); 90 provider.newFile(path, code);
81 91
82 AnalysisResult result = await driver.getResult(path); 92 AnalysisResult result = await driver.getResult(path);
83 result.unit.accept(new _InstrumentationVisitor(validation, uri)); 93 result.unit.accept(new _InstrumentationVisitor(validation, uri));
84 94
85 validation.finish(); 95 validation.finish();
86 96
87 if (validation.hasProblems) { 97 if (validation.hasProblems) {
88 fail(validation.problemsAsString); 98 throw validation.problemsAsString;
89 } 99 }
90 } 100 }
91 } 101 }
92 102
93 /** 103 /**
94 * Instance of [InstrumentationValue] describing a [DartType]. 104 * Instance of [InstrumentationValue] describing a [DartType].
95 */ 105 */
96 class _InstrumentationValueForType extends fasta.InstrumentationValue { 106 class _InstrumentationValueForType extends fasta.InstrumentationValue {
97 final DartType type; 107 final DartType type;
98 108
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 void _recordType(int offset, DartType type) { 271 void _recordType(int offset, DartType type) {
262 _instrumentation.record( 272 _instrumentation.record(
263 uri, offset, 'type', new _InstrumentationValueForType(type)); 273 uri, offset, 'type', new _InstrumentationValueForType(type));
264 } 274 }
265 275
266 void _recordTypeArguments(int offset, List<DartType> typeArguments) { 276 void _recordTypeArguments(int offset, List<DartType> typeArguments) {
267 _instrumentation.record(uri, offset, 'typeArgs', 277 _instrumentation.record(uri, offset, 'typeArgs',
268 new _InstrumentationValueForTypeArgs(typeArguments)); 278 new _InstrumentationValueForTypeArgs(typeArguments));
269 } 279 }
270 } 280 }
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