From d22b566c31f67da2e4dbfbd76f5b26e93e537a20 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 11 Jun 2026 07:53:15 -0700 Subject: [PATCH] CQ. Migrate ManifestValidatorTest to inline expected diagnostics. Change-Id: I499057965ea93aae9f550b9a383033ea6072db41 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/511140 Reviewed-by: Johnni Winther Commit-Queue: Konstantin Shcheglov --- .../src/manifest/manifest_validator_test.dart | 141 +++++++++--------- 1 file changed, 67 insertions(+), 74 deletions(-) diff --git a/pkg/analyzer/test/src/manifest/manifest_validator_test.dart b/pkg/analyzer/test/src/manifest/manifest_validator_test.dart index 6813ea9c443..06f62199850 100644 --- a/pkg/analyzer/test/src/manifest/manifest_validator_test.dart +++ b/pkg/analyzer/test/src/manifest/manifest_validator_test.dart @@ -2,17 +2,16 @@ // 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 'package:analyzer/diagnostic/diagnostic.dart'; -import 'package:analyzer/error/error.dart'; import 'package:analyzer/source/file_source.dart'; -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer/src/manifest/manifest_validator.dart'; import 'package:analyzer/src/manifest/manifest_values.dart'; import 'package:analyzer_testing/resource_provider_mixin.dart'; +import 'package:analyzer_testing/src/expected_diagnostics.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; -import '../../generated/test_support.dart'; +import '../../util/diff.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { @@ -435,40 +434,41 @@ Text @reflectiveTest class ManifestValidatorTest with ResourceProviderMixin { - late final ManifestValidator validator; + /// Assert that validator diagnostics match the inline diagnostic markers in + /// [content]. + void assertDiagnostics(String content) { + var cleanContent = removeDiagnosticExpectations(content); - /// Assert that when the validator is used on the given [content] the - /// [expectedCodes] are produced. - void assertDiagnostics(String content, List expectedCodes) { - List diagnostics = validator.validate(content, true); - GatheringDiagnosticListener listener = GatheringDiagnosticListener(); - listener.addAll(diagnostics); - listener.assertErrorsWithCodes(expectedCodes); + var source = FileSource(getFile('/sample/Manifest.xml')); + var validator = ManifestValidator(source); + var diagnostics = validator.validate(cleanContent, true); + var actual = updateExpectedDiagnostics( + content: cleanContent, + actualDiagnostics: diagnostics, + ); + if (actual != content) { + NodeTextExpectationsCollector.add(actual); + printPrettyDiff(content, actual); + fail('See the difference above.'); + } } /// Assert that when the validator is used on the given [content] no errors /// are produced. void assertNoErrors(String content) { - assertDiagnostics(content, []); - } - - void setUp() { - var file = getFile('/sample/Manifest.xml'); - var source = FileSource(file); - validator = ManifestValidator(source); + assertDiagnostics(content); } test_cameraPermissions_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' - - + xmlns:android="http://schemas.android.com/apk/res/android"> + + +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.cameraPermissionsIncompatible] Camera permissions make app incompatible for Chrome OS, consider adding optional features "android.hardware.camera" and "android.hardware.camera.autofocus". -''', - [diag.cameraPermissionsIncompatible], - ); +'''); } test_cameraPermissions_ok() { @@ -484,28 +484,26 @@ class ManifestValidatorTest with ResourceProviderMixin { } test_featureNotSupported_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' - + xmlns:android="http://schemas.android.com/apk/res/android"> + +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.unsupportedChromeOsHardware] The feature android.hardware.touchscreen isn't supported on Chrome OS, consider making it optional. -''', - [diag.unsupportedChromeOsHardware], - ); +'''); } test_hardwareNotSupported_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' - - + xmlns:android="http://schemas.android.com/apk/res/android"> + + +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.unsupportedChromeOsHardware] The feature android.software.home_screen isn't supported on Chrome OS, consider making it optional. -''', - [diag.unsupportedChromeOsHardware], - ); +'''); } test_no_errors() { @@ -518,65 +516,60 @@ class ManifestValidatorTest with ResourceProviderMixin { android:exported="false"> -''', []); +'''); } test_noTouchScreen_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' +// [diag.noTouchscreenFeature][column 1][length 83] The default "android.hardware.touchscreen" needs to be optional for Chrome OS. + xmlns:android="http://schemas.android.com/apk/res/android"> -''', - [diag.noTouchscreenFeature], - ); +'''); } test_resizeableactivity_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' + xmlns:android="http://schemas.android.com/apk/res/android"> - - +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.nonResizableActivity] The `` element should be allowed to be resized to allow users to take advantage of the multi-window environment on Chrome OS + android:exported="false"> + + -''', - [diag.nonResizableActivity], - ); +'''); } test_screenOrientation_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' + xmlns:android="http://schemas.android.com/apk/res/android"> - - +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.settingOrientationOnActivity] The `` element should not be locked to any orientation so that users can take advantage of the multi-window environments and larger screens on Chrome OS + android:exported="false"> + + -''', - [diag.settingOrientationOnActivity], - ); +'''); } test_touchScreenNotSupported_error() { - assertDiagnostics( - ''' + assertDiagnostics(''' - + xmlns:android="http://schemas.android.com/apk/res/android"> + +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.unsupportedChromeOsFeature] The feature android.hardware.touchscreen isn't supported on Chrome OS, consider making it optional. -''', - [diag.unsupportedChromeOsFeature], - ); +'''); } }