xref: /aosp_15_r20/tools/metalava/metalava/src/test/java/com/android/tools/metalava/cli/lint/ApiLintOptionsTest.kt (revision 115816f9299ab6ddd6b9673b81f34e707f6bacab)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.metalava.cli.lint
18 
19 import com.android.tools.metalava.cli.common.BaseOptionGroupTest
20 import com.android.tools.metalava.testing.signature
21 import com.google.common.truth.Truth.assertThat
22 import org.junit.Test
23 
24 val API_LINT_OPTIONS_HELP =
25     """
26 Api Lint:
27 
28   Options controlling API linting.
29 
30   --api-lint                                 Check API for Android API best practices.
31   --api-lint-previous-api <file>             An API signature file that defines, albeit maybe only partially, a
32                                              previously released API.
33 
34                                              If the API surface extends another API surface then this must include all
35                                              the corresponding signature files in order from the outermost API surface
36                                              that does not extend any API surface to the innermost one that represents
37                                              the API surface being generated.
38 
39                                              API Lint issues found in the previously released API will be ignored.
40   --error-message:api-lint <message>         If set, this is output when errors are detected in --api-lint.
41   --baseline:api-lint <file>                 An optional baseline file that contains a list of known API lint issues
42                                              which should be ignored. If this does not exist and
43                                              --update-baseline:api-lint is not specified then it will be created and
44                                              populated with all the known API lint issues.
45   --update-baseline:api-lint <file>          An optional file into which a list of the latest API lint issues found will
46                                              be written. If --baseline:api-lint is specified then any issues listed in
47                                              there will be copied into this file; that minimizes the amount of churn in
48                                              the baseline file when updating by not removing legacy issues that have
49                                              been fixed. If --delete-empty-baselines is specified and this baseline is
50                                              empty then the file will be deleted.
51     """
52         .trimIndent()
53 
54 class ApiLintOptionsTest :
55     BaseOptionGroupTest<ApiLintOptions>(
56         API_LINT_OPTIONS_HELP,
57     ) {
58 
createOptionsnull59     override fun createOptions(): ApiLintOptions = ApiLintOptions()
60 
61     @Test
62     fun `api lint previous api`() {
63         val file =
64             signature("released.txt", "// Signature format: 2.0\n").createFile(temporaryFolder.root)
65         runTest(ARG_API_LINT_PREVIOUS_API, file.path) {
66             assertThat(options.apiLintPreviousApis).isEqualTo(listOf(file))
67         }
68     }
69 }
70