Files
sdk/pkg/analyzer/test/id_tests/why_not_promoted_test.dart
T
Paul Berry c5a79f9a15 Analyzer: stop using NullSafetyUnderstandingFlag in why_not_promoted_test.dart.
The CL to add why_not_promoted_test.dart and the CL to remove
NullSafetyUnderstandingFlag landed around the same time, so we failed
to notice the conflict between them.  The fix is easy: since
NullSafetyUnderstandingFlag doesn't exist anymore (and isn't needed
anymore), we can just remove this use of it.

Fixes bot failures with the test
`pkg/analyzer/test/id_tests/why_not_promoted_test`.

Change-Id: Icec2d57d371229f103b42c5e25d49aab952adc1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182340
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-02-02 20:29:14 +00:00

85 lines
2.7 KiB
Dart

// Copyright (c) 2020, 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:io';
import 'package:_fe_analyzer_shared/src/testing/id.dart' show ActualData, Id;
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/dart/analysis/testing_data.dart';
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/util/ast_data_extractor.dart';
import '../util/id_testing_helper.dart';
main(List<String> args) async {
Directory dataDir = Directory.fromUri(
Platform.script.resolve('../../../_fe_analyzer_shared/test/flow_analysis/'
'why_not_promoted/data'));
return runTests<String?>(dataDir,
args: args,
createUriForFileName: createUriForFileName,
onFailure: onFailure,
runTest: runTestFor(
const _WhyNotPromotedDataComputer(), [analyzerNnbdConfig]));
}
class _WhyNotPromotedDataComputer extends DataComputer<String?> {
const _WhyNotPromotedDataComputer();
@override
DataInterpreter<String?> get dataValidator =>
const _WhyNotPromotedDataInterpreter();
@override
bool get supportsErrors => true;
@override
void computeUnitData(TestingData testingData, CompilationUnit unit,
Map<Id, ActualData<String?>> actualMap) {
var flowResult =
testingData.uriToFlowAnalysisData[unit.declaredElement!.source.uri]!;
_WhyNotPromotedDataExtractor(
unit.declaredElement!.source.uri, actualMap, flowResult)
.run(unit);
}
}
class _WhyNotPromotedDataExtractor extends AstDataExtractor<String?> {
final FlowAnalysisDataForTesting _flowResult;
_WhyNotPromotedDataExtractor(
Uri uri, Map<Id, ActualData<String?>> actualMap, this._flowResult)
: super(uri, actualMap);
@override
String? computeNodeValue(Id id, AstNode node) {
String? nonPromotionReason = _flowResult.nonPromotionReasons[node];
if (nonPromotionReason != null) {
return 'notPromoted($nonPromotionReason)';
}
return _flowResult.nonPromotionReasonTargets[node];
}
}
class _WhyNotPromotedDataInterpreter implements DataInterpreter<String?> {
const _WhyNotPromotedDataInterpreter();
@override
String getText(String? actualData, [String? indentation]) =>
actualData.toString();
@override
String? isAsExpected(String? actualData, String? expectedData) {
if (actualData == expectedData) {
return null;
} else {
return 'Expected $expectedData, got $actualData';
}
}
@override
bool isEmpty(String? actualData) => actualData == null;
}