blob: d44784402e3c4e0221f9361eb2e5f8aa9cbb2153 [file]
# 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/json/validate_json.gni")
import("//build/testing/host_test.gni")
import("//build/testing/host_test_data.gni")
group("tests") {
testonly = true
deps = [
":test_json_validator($host_toolchain)",
":test_json_validator_valico($host_toolchain)",
":test_json_validator_with_comments($host_toolchain)",
":test_validate_json_valico($host_toolchain)",
]
}
validate_json("test_json_validator") {
testonly = true
data = "test_document.json"
schema = "test_schema.json"
}
validate_json("test_json_validator_with_comments") {
testonly = true
data = "test_document_with_comments.json"
schema = "test_schema.json"
allow_comments = true
}
if (is_host) {
# The valico-based JSON validator tool is a Bazel root host target.
# To find its path relative to the Ninja build directory, and corresponding
# GN dependency, scan the list of Bazel root targets.
import("//build/bazel/bazel_root_targets.gni")
_valico_validator_label = "//build/tools/json_validator:json_validator_valico"
_valico_validator_path = ""
_valico_validator_target = ""
foreach(_root_target, resolved_bazel_root_targets) {
if (_root_target.bazel_label == _valico_validator_label) {
_valico_validator_path = "${host_out_dir}/json_validator_valico"
_valico_validator_target = _root_target.host_bin_label
}
}
assert(_valico_validator_path != "",
"Cannot find ${_valico_validator_label} in Bazel root targets list!")
host_test_data("test_json_validator_valico_data") {
sources = [
"test_document.json",
"test_document_with_comments.json",
"test_schema.json",
"test_schema_with_ref.json",
_valico_validator_path,
]
}
host_test("test_json_validator_valico") {
binary_path = "json_validator_valico_test.sh"
deps = [ _valico_validator_target ]
data_deps = [ ":test_json_validator_valico_data" ]
args = [
rebase_path(_valico_validator_path, root_build_dir),
rebase_path(".", root_build_dir),
]
}
}
# Test (at build time) that the use_valico option of the validate_json build
# rule.
validate_json("test_validate_json_valico") {
testonly = true
data = "test_document.json"
schema = "test_schema.json"
}