load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
load("//:CPPVARIABLES.bzl", "DDS_CPPOPTS", "DDS_LINKOPTS", "DDS_LOCAL_DEFINES", "DDS_SCHEDULER_DEFINE")

# Test utility sources (glob used for convenience; excludes integration/context equivalence tests)
filegroup(
    name = "test_sources",
    srcs = glob(
        ["*.cpp", "*.hpp"],
        exclude = [
            "itest.cpp",
            "context_equivalence.cpp",
            "calc_par_test.cpp",  # Uses GoogleTest, compiled separately
        ],
    ),
)

# Main test executable for manual invocation
cc_binary(
    name = "dtest",
    srcs = [":test_sources"],
    copts = DDS_CPPOPTS,
    linkopts = DDS_LINKOPTS,
    local_defines = DDS_LOCAL_DEFINES + DDS_SCHEDULER_DEFINE,
    deps = [
        "//library/src:dds",
        "//library/src/api:api_definitions",
    ],
    visibility = ["//visibility:public"],
)

# Test target for Bazel test execution (`bazel test //library/tests:all`)
# Uses testable_dds to expose internal symbols for unit testing
cc_test(
    name = "unit_tests",
    srcs = [":test_sources"],
    size = "small",
    copts = DDS_CPPOPTS,
    linkopts = DDS_LINKOPTS,
    local_defines = DDS_LOCAL_DEFINES + DDS_SCHEDULER_DEFINE,
    deps = [
        "//library/src:testable_dds",
        "//library/src/api:api_definitions",
    ],
)

# Standalone calc_par API test
cc_test(
    name = "calc_par_test",
    srcs = ["calc_par_test.cpp"],
    size = "small",
    copts = DDS_CPPOPTS,
    linkopts = DDS_LINKOPTS,
    local_defines = DDS_LOCAL_DEFINES,
    deps = [
        "//library/src:dds",
        "@googletest//:gtest_main",
    ],
)


