# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/config/python.gni")
import("//build/ohos/build_var.gni")
import("//build/ohos_var.gni")

# Defines ohos_subsystem_test
#
# example:
# ohos_subsystem_test("examples_test") {
#   testonly = true
#   test_packages = [
#     "calculator/test:unittest",
#     "detector/test:unittest",
#     "summator/test:unittest",
#   ]
# }
template("_ohos_part_test") {
  assert(defined(invoker.part_name), "part_name is required.")
  assert(defined(invoker.test_packages), "test_packages is required.")

  part_name = invoker.part_name
  subsystem_name = invoker.subsystem_name
  assert(subsystem_name != "")
  assert(part_name != "")

  _deps = []
  if (defined(invoker.deps)) {
    _deps += invoker.deps
  }

  group(target_name) {
    if (defined(invoker.testonly)) {
      testonly = invoker.testonly
    }
    deps = _deps
    deps += invoker.test_packages
  }
}

template("ohos_part_test") {
  _ohos_part_test(target_name) {
    testonly = invoker.testonly
    deps = invoker.deps
    part_name = invoker.part_name
    subsystem_name = invoker.subsystem_name
    test_packages = invoker.test_packages
  }
}