|  | # Copyright 2020 The Fuchsia Authors. All rights reserved. | 
|  | # Use of this source code is governed by a BSD-style license that can be | 
|  | # found in the LICENSE file. | 
|  |  | 
|  | import("fuchsia_test_package.gni") | 
|  | import("fuchsia_unittest_component.gni") | 
|  |  | 
|  | # Defines a package that contains a component that launches a test. | 
|  | # See: https://fuchsia.dev/fuchsia-src/development/components/build | 
|  | # | 
|  | # This template is a useful shortcut for defining classic unit tests for target | 
|  | # devices. | 
|  | # Pure unit tests don't require any special capabilities, so their component | 
|  | # manifest can be generated by the template if a manifest is not specified. | 
|  | # | 
|  | # Example: | 
|  | # ``` | 
|  | # executable("rot13_encoder_decoder_test") { | 
|  | #   sources = [ "rot13_encoder_decoder_test.cc" ] | 
|  | #   testonly = true | 
|  | # } | 
|  | # | 
|  | # fuchsia_unittest_package("rot13-test") { | 
|  | #   deps = [ ":rot13_encoder_decoder_test" ] | 
|  | # } | 
|  | # ``` | 
|  | # | 
|  | # The above will generate a manifest and create a test with the launch URL: | 
|  | # fuchsia-pkg://fuchsia.com/rot13-test#meta/rot13-test.cmx | 
|  | # | 
|  | # Parameters | 
|  | # | 
|  | #   package_name (optional) | 
|  | #     The name of the package. | 
|  | #     Type: string | 
|  | #     Default: target_name | 
|  | # | 
|  | #   component_name (optional) | 
|  | #     The name of the component. | 
|  | #     Type: string | 
|  | #     Default: target_name | 
|  | # | 
|  | #   manifest (optional) | 
|  | #     Specify a component manifest for the test. | 
|  | #     If a manifest is not specified, a trivial manifest will be generated. | 
|  | #     The generated manifest requests no special capabilities, which is good | 
|  | #     enough for "pure" unit tests. | 
|  | #     To view the generated manifest, see: | 
|  | #     `fx gn outputs out/default path/to/your:<target_name>_component_generated_manifest` | 
|  | #     Type: path | 
|  | # | 
|  | #   v2 (optional) | 
|  | #     If specified and set to true, will generate a CFv2 (.cml) manifest. | 
|  | #     If `manifest` is specified then this is ignored. | 
|  | #     Type: boolean | 
|  | # | 
|  | #   test_specs (optional) | 
|  | #     Additional test specifications to apply to the test defined above. | 
|  | #     See `test_spec.gni`. | 
|  | #     Type: scope | 
|  | # | 
|  | #   deps | 
|  | #   visibility | 
|  | template("fuchsia_unittest_package") { | 
|  | component_target = "${target_name}_component" | 
|  | fuchsia_unittest_component(component_target) { | 
|  | forward_variables_from(invoker, | 
|  | [ | 
|  | "component_name", | 
|  | "deps", | 
|  | "manifest", | 
|  | "v2", | 
|  | ]) | 
|  | if (!defined(component_name)) { | 
|  | component_name = invoker.target_name | 
|  | } | 
|  | visibility = [ ":*" ] | 
|  | } | 
|  |  | 
|  | fuchsia_test_package(target_name) { | 
|  | forward_variables_from(invoker, | 
|  | [ | 
|  | "package_name", | 
|  | "test_specs", | 
|  | "visibility", | 
|  | ]) | 
|  | test_components = [ ":$component_target" ] | 
|  | } | 
|  | } |