xref: /aosp_15_r20/external/bazel-skylib/docs/analysis_test_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifan<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2*bcb5dc79SHONG Yifan
3*bcb5dc79SHONG YifanA test verifying other targets can be successfully analyzed as part of a `bazel test`
4*bcb5dc79SHONG Yifan
5*bcb5dc79SHONG Yifan<a id="analysis_test"></a>
6*bcb5dc79SHONG Yifan
7*bcb5dc79SHONG Yifan## analysis_test
8*bcb5dc79SHONG Yifan
9*bcb5dc79SHONG Yifan<pre>
10*bcb5dc79SHONG Yifananalysis_test(<a href="#analysis_test-name">name</a>, <a href="#analysis_test-targets">targets</a>)
11*bcb5dc79SHONG Yifan</pre>
12*bcb5dc79SHONG Yifan
13*bcb5dc79SHONG YifanTest rule checking that other targets can be successfully analyzed.
14*bcb5dc79SHONG Yifan
15*bcb5dc79SHONG YifanThis rule essentially verifies that all targets under `targets` would
16*bcb5dc79SHONG Yifangenerate no errors when analyzed with `bazel build [targets] --nobuild`.
17*bcb5dc79SHONG YifanAction success/failure for the targets and their transitive dependencies
18*bcb5dc79SHONG Yifanare not verified. An analysis test simply ensures that each target in the transitive
19*bcb5dc79SHONG Yifandependencies propagate providers appropriately and register actions for their outputs
20*bcb5dc79SHONG Yifanappropriately.
21*bcb5dc79SHONG Yifan
22*bcb5dc79SHONG YifanNOTE: If the targets fail to analyze, instead of the analysis_test failing, the analysis_test
23*bcb5dc79SHONG Yifanwill fail to build. Ideally, it would instead result in a test failure. This is a current
24*bcb5dc79SHONG Yifaninfrastructure limitation that may be fixed in the future.
25*bcb5dc79SHONG Yifan
26*bcb5dc79SHONG YifanTypical usage:
27*bcb5dc79SHONG Yifan
28*bcb5dc79SHONG Yifan  load("@bazel_skylib//rules:analysis_test.bzl", "analysis_test")
29*bcb5dc79SHONG Yifan  analysis_test(
30*bcb5dc79SHONG Yifan      name = "my_analysis_test",
31*bcb5dc79SHONG Yifan      targets = [
32*bcb5dc79SHONG Yifan          "//some/package:rule",
33*bcb5dc79SHONG Yifan      ],
34*bcb5dc79SHONG Yifan  )
35*bcb5dc79SHONG Yifan
36*bcb5dc79SHONG YifanArgs:
37*bcb5dc79SHONG Yifan  name: The name of the test rule.
38*bcb5dc79SHONG Yifan  targets: A list of targets to ensure build.
39*bcb5dc79SHONG Yifan
40*bcb5dc79SHONG Yifan**ATTRIBUTES**
41*bcb5dc79SHONG Yifan
42*bcb5dc79SHONG Yifan
43*bcb5dc79SHONG Yifan| Name  | Description | Type | Mandatory | Default |
44*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- | :------------- | :------------- |
45*bcb5dc79SHONG Yifan| <a id="analysis_test-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |  |
46*bcb5dc79SHONG Yifan| <a id="analysis_test-targets"></a>targets |  -   | <a href="https://bazel.build/concepts/labels">List of labels</a> | required |  |
47*bcb5dc79SHONG Yifan
48*bcb5dc79SHONG Yifan
49