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

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

Issue 2846463003: Instrument analyzer's type analysis and run front_end inference tests. (Closed)
Patch Set: Updates. Created 3 years, 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:io';
8
9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:front_end/src/base/instrumentation.dart' as fasta;
11 import 'package:front_end/src/fasta/compiler_context.dart' as fasta;
12 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart'
13 as fasta;
14 import 'package:kernel/kernel.dart' as fasta;
15 import 'package:path/path.dart' as pathos;
16 import 'package:test/test.dart';
17
18 import '../../dart/analysis/base.dart';
19
20 Future<Null> main() async {
21 await _runFrontEndInferenceTests();
22 }
23
24 /**
25 * Expects that the [Platform.script] is a test inside of `pkg/analyzer/test`
26 * folder, and return the absolute path of the `pkg` folder.
27 */
28 String _findPkgRoot() {
29 String scriptPath = pathos.fromUri(Platform.script);
30 List<String> parts = pathos.split(scriptPath);
31 for (int i = 0; i < parts.length - 2; i++) {
32 if (parts[i] == 'pkg' &&
33 parts[i + 1] == 'analyzer' &&
34 parts[i + 2] == 'test') {
35 return pathos.joinAll(parts.sublist(0, i + 1));
36 }
37 }
38 throw new StateError('Unable to find sdk/pkg/ in $scriptPath');
39 }
40
41 Future<Null> _runFrontEndInferenceTests() async {
42 String pkgPath = _findPkgRoot();
43 String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference');
44 List<File> dartFiles = new Directory(fePath)
45 .listSync()
46 .where((entry) => entry is File && entry.path.endsWith('.dart'))
47 .map((entry) => entry as File)
48 .toList();
49
50 for (File file in dartFiles) {
51 var test = new _FrontEndInferenceTest();
52 await test.setUp();
53 try {
54 String code = file.readAsStringSync();
55 await test.runTest(file.path, code);
56 } catch (_) {
57 print(_);
58 } finally {
59 await test.tearDown();
60 }
61 }
62 }
63
64 class _FrontEndInferenceTest extends BaseAnalysisDriverTest {
65 Future<Null> runTest(String path, String code) async {
66 var uri = provider.pathContext.toUri(path);
67
68 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts;
69 fasta.CompilerContext.current.uriToSource[uri.toString()] =
70 new fasta.Source(lineStarts, UTF8.encode(code));
71
72 var validation = new fasta.ValidatingInstrumentation();
73 await validation.loadExpectations(uri);
74
75 driver.test.instrumentation = new _Instrumentation(validation);
76 provider.newFile(path, code);
77 await driver.getResult(path);
78
79 validation.finish();
80
81 if (validation.hasProblems) {
82 var problem = validation.problemsAsString;
83 fail(problem);
84 }
85 }
86 }
87
88 class _Instrumentation implements fasta.Instrumentation {
89 final fasta.Instrumentation instrumentation;
90 final Set<String> _seenKeys = new Set<String>();
91
92 _Instrumentation(this.instrumentation);
93
94 @override
95 void record(
96 Uri uri, int offset, String property, fasta.InstrumentationValue value) {
97 // Analyzer's resolver reports many of instance creations twice.
98 if (_seenKeys.add('$uri:$offset:$property')) {
99 instrumentation.record(uri, offset, property, value);
100 }
101 }
102 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/analysis/base.dart ('k') | pkg/analyzer/test/src/task/strong/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698