Skip to content

Commit bf4facd

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Handle errors when comparing analyzer and front end behaviors.
For now, if the front end detects an error, we just consider the test to have passed; we don't try to verify that the analyzer also detects an error. This will be improved in a future CL. Drops the number of failing language_2 tests with `--compiler compare_analyzer_cfe` from 2676 to 405. Change-Id: Ib4f3c99710df4a0f0aac9a1c22a9a3279c6a6479 Reviewed-on: https://dart-review.googlesource.com/74968 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent 3e9f4e6 commit bf4facd

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

pkg/analyzer_fe_comparison/lib/comparison.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ void compareTestPrograms(
3636
packagesFileUri,
3737
platformUri,
3838
(uri) => uri.scheme == 'file');
39+
if (kernelNode.text == 'Error occurred') {
40+
// TODO(paulberry): really we should verify that the analyzer detects an
41+
// error as well. But that's not easy to do right now because we use the
42+
// front end to chase imports so that we know which files to pass to the
43+
// analyzer, and we can't rely on the front end import chasing when an error
44+
// occurred.
45+
print('No differences found (skipped due to front end compilation error)');
46+
return;
47+
}
3948
String startingPath;
4049
var inputs = <String>[];
4150
for (var library in kernelNode.children) {
@@ -52,7 +61,7 @@ void compareTestPrograms(
5261
ComparisonNode analyzerNode =
5362
await analyzer.analyzeFiles(startingPath, inputs);
5463
var diff = ComparisonNode.diff(kernelNode, analyzerNode);
55-
if (diff.children.isEmpty) {
64+
if (diff.children.isEmpty && diff.text.startsWith('=')) {
5665
print('No differences found!');
5766
} else {
5867
print('Differences found:');

pkg/analyzer_fe_comparison/lib/src/kernel.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ import 'package:kernel/target/targets.dart';
1515
/// [ComparisonNode] representing them.
1616
Future<ComparisonNode> analyzePackage(
1717
List<Uri> inputs, Uri packagesFileUri, Uri platformUri) async {
18+
bool errorOccurred = false;
1819
var component = await kernelForComponent(
19-
inputs, _makeCompilerOptions(packagesFileUri, platformUri));
20+
inputs,
21+
_makeCompilerOptions(packagesFileUri, platformUri, (_) {
22+
errorOccurred = true;
23+
}));
24+
if (errorOccurred) {
25+
return ComparisonNode('Error occurred');
26+
}
2027
var libraryNodes = <ComparisonNode>[];
2128
var visitor = _KernelVisitor(libraryNodes);
2229
for (var library in component.libraries) {
@@ -33,8 +40,15 @@ Future<ComparisonNode> analyzePackage(
3340
/// Only libraries whose URI passes the [uriFilter] are included in the results.
3441
Future<ComparisonNode> analyzeProgram(Uri input, Uri packagesFileUri,
3542
Uri platformUri, bool uriFilter(Uri uri)) async {
43+
var errorOccurred = false;
3644
var component = await kernelForProgram(
37-
input, _makeCompilerOptions(packagesFileUri, platformUri));
45+
input,
46+
_makeCompilerOptions(packagesFileUri, platformUri, (_) {
47+
errorOccurred = true;
48+
}));
49+
if (errorOccurred) {
50+
return ComparisonNode('Error occurred');
51+
}
3852
var libraryNodes = <ComparisonNode>[];
3953
var visitor = _KernelVisitor(libraryNodes);
4054
for (var library in component.libraries) {
@@ -45,7 +59,8 @@ Future<ComparisonNode> analyzeProgram(Uri input, Uri packagesFileUri,
4559
return ComparisonNode.sorted('Component', libraryNodes);
4660
}
4761

48-
CompilerOptions _makeCompilerOptions(Uri packagesFileUri, Uri platformUri) {
62+
CompilerOptions _makeCompilerOptions(
63+
Uri packagesFileUri, Uri platformUri, ErrorHandler onError) {
4964
var targetFlags = TargetFlags(strongMode: true, syncAsync: true);
5065
var target = NoneTarget(targetFlags);
5166
var fileSystem = StandardFileSystem.instance;
@@ -57,7 +72,8 @@ CompilerOptions _makeCompilerOptions(Uri packagesFileUri, Uri platformUri) {
5772
..strongMode = true
5873
..target = target
5974
..throwOnErrorsForDebugging = false
60-
..embedSourceText = false;
75+
..embedSourceText = false
76+
..onError = onError;
6177
}
6278

6379
/// Visitor for serializing a kernel representation of a program into

0 commit comments

Comments
 (0)