blob: 26c1f400e53f709f2b533b0f54edfbe374cf11f7 [file] [log] [blame]
# 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("//build/components/fuchsia_test_component_manifest.gni")
import("//build/dart/dart_build_config.gni")
import("//build/flutter/internal/flutter_dart_test_component.gni")
# Defines a component which runs tests in the dart test harness
#
# Bundles a set of `package:test` tests into a single Fuchsia component
# with generated helper code to invoke the tests appropriately. The resulting
# application can take Dart test arguments; pass --help to see full options.
#
# ```
# dart_library("lib") {
# package_name = "my_library"
# sources = [
# "foo.dart",
# "bar.dart"
# ]
# }
#
# dart_test_component("my-test-component") {
# manifest = "meta/my-test-component.cml"
# sources = [
# "foo_test.dart",
# "bar_test.dart",
# ]
#
# deps = [
# ":lib",
# "//third_party/dart-pkg/pub/test",
# ]
# }
#
# fuchsia_test_package("my-integration-test") {
# test_components = [ ":my-test-component" ]
# }
# ```
#
# Parameters
#
# manifest (optional)
# The path to the component manifest. If not provided, a basic CML will be auto-generated.
# Type: path
#
# sources (required)
# The list of test sources. These sources must be within the test/ directory.
# Type: List of paths
#
# language_version (optional)
# Specify the Dart language version to use for this test.
# Defaults to "2.8".
#
# component_name (optional)
# The name of the compnonent to test.
# Type: String
# Default: target_name
#
# build_cfg (optional)
# Specifies the parameters for building the component.
# See //build/dart/dart_build_config.gni for predefined configs.
#
# package_root (optional)
# Path to the directory hosting the library.
# This is useful for generated content, and can be ignored otherwise.
# Defaults to ".".
#
# deps
# visibility
# non_dart_deps
template("dart_test_component") {
if (defined(invoker.build_cfg)) {
_build_cfg = invoker.build_cfg
} else {
_build_cfg = dart_default_build_cfg
}
if (defined(invoker.manifest)) {
_manifest = invoker.manifest
} else {
generated_target = "${target_name}_generated_manifest"
fuchsia_test_component_manifest(generated_target) {
visibility = [ ":*" ]
metadata = {
test_component_manifest_cml = [
{
include = [ "syslog/client.shard.cml" ]
},
]
}
}
_manifest = get_target_outputs(":$generated_target")
_manifest = _manifest[0]
}
flutter_dart_test_component(target_name) {
forward_variables_from(invoker, "*", [ "build_cfg" ])
build_cfg = _build_cfg
manifest = _manifest
if (defined(generated_target)) {
manifest_deps = [ ":$generated_target" ]
}
# Add test shard that exposes the suite protocol from test component.
if (get_path_info(_manifest, "extension") == "cml") {
test_runtime_shard = "//build/dart/meta/test_runtime.shard.cml"
}
}
}