| # Copyright 2021 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/host.gni") | |
| import("//build/rust/rustc_binary.gni") | |
| import("//tools/testgen/build/testgen_golden_files.gni") | |
| if (is_host) { | |
| _integration_test_templates = [ | |
| "templates/integration_test/tests/BUILD.gn.hbrs", | |
| "templates/integration_test/tests/meta/test-root.cml.hbrs", | |
| "templates/integration_test/tests/meta/test-suite.cml.hbrs", | |
| "templates/integration_test/tests/src/main.rs.hbrs", | |
| "templates/integration_test/testing/fidl/BUILD.gn.hbrs", | |
| "templates/integration_test/testing/fidl/realm_factory.test.fidl.hbrs", | |
| "templates/integration_test/testing/realm-factory/BUILD.gn.hbrs", | |
| "templates/integration_test/testing/realm-factory/meta/default.cml.hbrs", | |
| "templates/integration_test/testing/realm-factory/src/main.rs.hbrs", | |
| "templates/integration_test/testing/realm-factory/src/realm_factory_impl.rs.hbrs", | |
| "templates/integration_test/testing/realm-factory/src/realm_factory_server.rs.hbrs", | |
| ] | |
| rustc_binary("testgen") { | |
| name = "testgen" | |
| edition = "2021" | |
| source_root = "src/main.rs" | |
| sources = [ | |
| "src/cmd_integration_test.rs", | |
| "src/flags.rs", | |
| "src/main.rs", | |
| ] | |
| inputs = _integration_test_templates | |
| deps = [ | |
| "//src/lib/fuchsia", | |
| "//third_party/rust_crates:anyhow", | |
| "//third_party/rust_crates:argh", | |
| "//third_party/rust_crates:chrono", | |
| "//third_party/rust_crates:handlebars", | |
| "//third_party/rust_crates:serde", | |
| "//third_party/rust_crates:serde_json", | |
| "//third_party/rust_crates:tempfile", | |
| "//third_party/rust_crates:tracing", | |
| "//third_party/rust_crates:walkdir", | |
| ] | |
| } | |
| install_host_tools("host") { | |
| deps = [ ":testgen" ] | |
| outputs = [ "testgen" ] | |
| } | |
| # TODO(127883): Add a golden file test for the helptext. | |
| testgen_golden_files("integration_test_goldens") { | |
| testgen = { | |
| label = ":testgen" | |
| test_root = "$target_gen_dir/$target_name" | |
| args = [ | |
| "integration_test", | |
| "--test-root", | |
| rebase_path(test_root, root_build_dir), | |
| "--component-manifest", | |
| rebase_path("testdata/meta/example-component.cml", root_build_dir), | |
| ] | |
| inputs = [ "testdata/meta/example-component.cml" ] | |
| outputs = [] # This is filled in below | |
| } | |
| _template_dir = "templates/integration_test" | |
| _goldens_dir = "//tools/testgen/testdata/goldens/integration_test" | |
| comparisons = [] | |
| foreach(template_path, _integration_test_templates) { | |
| output = string_replace(template_path, ".hbrs", "") | |
| candidate = string_replace(output, _template_dir, testgen.test_root) | |
| golden = string_replace(output, _template_dir, _goldens_dir) | |
| testgen.outputs += [ candidate ] | |
| comparisons += [ | |
| { | |
| candidate = candidate | |
| golden = golden | |
| }, | |
| ] | |
| } | |
| } | |
| } | |
| # Tests for the integration_test subcommand. | |
| group("integration_test_tests") { | |
| testonly = true | |
| deps = [ | |
| ":integration_test_goldens($host_toolchain)", | |
| # Ensure the generated test builds and passes. | |
| "testdata/goldens/integration_test/tests", | |
| ] | |
| } | |
| group("tests") { | |
| testonly = true | |
| deps = [ ":integration_test_tests" ] | |
| } |