| # 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") { |
| # executable_path = "bin/rot13_encoder_decoder_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 (required if `executable_path` is not specified) |
| # 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>_generated_manifest` |
| # Type: path |
| # |
| # executable_path (required if `manifest` is not specified) |
| # Specify the packaged path of the test executable. |
| # Example: "test/my_executable" |
| # This executable must be generated by one of the `deps`. |
| # This is used in generating the manifest. |
| # Type: string |
| # |
| # executable_args (ignored if `manifest` is specified) |
| # Specify the args to be passed to test executable. |
| # Example: ["--foo", "bar"] |
| # This is used in generating the manifest. |
| # Type: list of string |
| # |
| # v2_test_runner (optional) |
| # If specified and no manifest is specified, a trivial Components v2 |
| # manifest will be generated using the specified test runner. The |
| # generated manifest will include temporary storage at /tmp but no other |
| # special capabilities. Typical values: "rust_test_runner", |
| # "gtest_runner" or "go_test_runner". |
| # Type: string |
| # |
| # 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", |
| "executable_path", |
| "executable_args", |
| "v2_test_runner", |
| ]) |
| 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" ] |
| } |
| } |