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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/task/strong/front_end_inference_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/front_end_inference_test.dart b/pkg/analyzer/test/src/task/strong/front_end_inference_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8ea1c54921b7e1b4772acdf9ca89830b3c1bee3b
--- /dev/null
+++ b/pkg/analyzer/test/src/task/strong/front_end_inference_test.dart
@@ -0,0 +1,102 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:analyzer/src/generated/source.dart';
+import 'package:front_end/src/base/instrumentation.dart' as fasta;
+import 'package:front_end/src/fasta/compiler_context.dart' as fasta;
+import 'package:front_end/src/fasta/testing/validating_instrumentation.dart'
+ as fasta;
+import 'package:kernel/kernel.dart' as fasta;
+import 'package:path/path.dart' as pathos;
+import 'package:test/test.dart';
+
+import '../../dart/analysis/base.dart';
+
+Future<Null> main() async {
+ await _runFrontEndInferenceTests();
+}
+
+/**
+ * Expects that the [Platform.script] is a test inside of `pkg/analyzer/test`
+ * folder, and return the absolute path of the `pkg` folder.
+ */
+String _findPkgRoot() {
+ String scriptPath = pathos.fromUri(Platform.script);
+ List<String> parts = pathos.split(scriptPath);
+ for (int i = 0; i < parts.length - 2; i++) {
+ if (parts[i] == 'pkg' &&
+ parts[i + 1] == 'analyzer' &&
+ parts[i + 2] == 'test') {
+ return pathos.joinAll(parts.sublist(0, i + 1));
+ }
+ }
+ throw new StateError('Unable to find sdk/pkg/ in $scriptPath');
+}
+
+Future<Null> _runFrontEndInferenceTests() async {
+ String pkgPath = _findPkgRoot();
+ String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference');
+ List<File> dartFiles = new Directory(fePath)
+ .listSync()
+ .where((entry) => entry is File && entry.path.endsWith('.dart'))
+ .map((entry) => entry as File)
+ .toList();
+
+ for (File file in dartFiles) {
+ var test = new _FrontEndInferenceTest();
+ await test.setUp();
+ try {
+ String code = file.readAsStringSync();
+ await test.runTest(file.path, code);
+ } catch (_) {
+ print(_);
+ } finally {
+ await test.tearDown();
+ }
+ }
+}
+
+class _FrontEndInferenceTest extends BaseAnalysisDriverTest {
+ Future<Null> runTest(String path, String code) async {
+ var uri = provider.pathContext.toUri(path);
+
+ List<int> lineStarts = new LineInfo.fromContent(code).lineStarts;
+ fasta.CompilerContext.current.uriToSource[uri.toString()] =
+ new fasta.Source(lineStarts, UTF8.encode(code));
+
+ var validation = new fasta.ValidatingInstrumentation();
+ await validation.loadExpectations(uri);
+
+ driver.test.instrumentation = new _Instrumentation(validation);
+ provider.newFile(path, code);
+ await driver.getResult(path);
+
+ validation.finish();
+
+ if (validation.hasProblems) {
+ var problem = validation.problemsAsString;
+ fail(problem);
+ }
+ }
+}
+
+class _Instrumentation implements fasta.Instrumentation {
+ final fasta.Instrumentation instrumentation;
+ final Set<String> _seenKeys = new Set<String>();
+
+ _Instrumentation(this.instrumentation);
+
+ @override
+ void record(
+ Uri uri, int offset, String property, fasta.InstrumentationValue value) {
+ // Analyzer's resolver reports many of instance creations twice.
+ if (_seenKeys.add('$uri:$offset:$property')) {
+ instrumentation.record(uri, offset, property, value);
+ }
+ }
+}
« 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