From d92d1e4ca20753d43e6806bbefe7074f596660d1 Mon Sep 17 00:00:00 2001 From: Azhara Assanova Date: Thu, 1 Jul 2021 15:41:33 +0000 Subject: [PATCH] Enable Android Lint tests for AndroidFrameworkLintChecker Create AndroidFrameworkLintCheckerTest module and add .allowMissingSdk(true) to all tests to enable tests running on gerrit. "unit_test: true" marks the module as a unit test target which runs it on the host without a device and it automatically gets onboarded in the presubmit. Bug: 157626959 Test: atest AndroidFrameworkLintCheckerTest --host Change-Id: I66c6e331e72dfca45d341a49eb43fbd73ccd28ff --- tools/lint/Android.bp | 26 +++++++++---------- .../lint/CallingIdentityTokenDetectorTest.kt | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/lint/Android.bp b/tools/lint/Android.bp index dcbc32b4e2888..17547ef8b561a 100644 --- a/tools/lint/Android.bp +++ b/tools/lint/Android.bp @@ -31,16 +31,16 @@ java_library_host { ], } -// TODO: (b/162368644) Implement these (working in gradle) Kotlin Tests to run on Soong -//java_test_host { -// name: "AndroidFrameworkLintCheckerTest", -// srcs: [ -// "checks/src/test/java/**/*.kt", -// "checks/src/main/java/**/*.kt", -// ], -// plugins: ["auto_service_plugin"], -// static_libs: [ -// "auto_service_annotations", -// "lint_api", -// ], -//} +java_test_host { + name: "AndroidFrameworkLintCheckerTest", + srcs: ["checks/src/test/java/**/*.kt"], + static_libs: [ + "AndroidFrameworkLintChecker", + "junit", + "lint", + "lint_tests", + ], + test_options: { + unit_test: true, + }, +} diff --git a/tools/lint/checks/src/test/java/com/google/android/lint/CallingIdentityTokenDetectorTest.kt b/tools/lint/checks/src/test/java/com/google/android/lint/CallingIdentityTokenDetectorTest.kt index 0532c2013c874..8f67555ec1b72 100644 --- a/tools/lint/checks/src/test/java/com/google/android/lint/CallingIdentityTokenDetectorTest.kt +++ b/tools/lint/checks/src/test/java/com/google/android/lint/CallingIdentityTokenDetectorTest.kt @@ -18,6 +18,7 @@ package com.google.android.lint import com.android.tools.lint.checks.infrastructure.LintDetectorTest import com.android.tools.lint.checks.infrastructure.TestFile +import com.android.tools.lint.checks.infrastructure.TestLintTask import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue @@ -34,6 +35,8 @@ class CallingIdentityTokenDetectorTest : LintDetectorTest() { CallingIdentityTokenDetector.ISSUE_CLEAR_IDENTITY_CALL_NOT_FOLLOWED_BY_TRY_FINALLY ) + override fun lint(): TestLintTask = super.lint().allowMissingSdk(true) + /** No issue scenario */ fun testDoesNotDetectIssuesInCorrectScenario() {