include_defs("//common/defs/environment")

if os_getenv('SANDCASTLE') is not None:
    # We don't run this by default on devservers, because python 2.x has a bug
    # that breaks subprocess when threading is used, so we have to run the
    # tests with concurrency=1 and it takes a bit longer.
    custom_unittest(
        name = "runtests-py2",
        command = [
            "$(location @/watchman/facebook:runtests)",
            "--testpilot-json",
        ],
        tags = ["run_as_bundle"],
        type = "json",
        deps = [
            "@/watchman/facebook:runtests",
        ],
    )

custom_unittest(
    name = "runtests-py3",
    command = [
        "$(location @/watchman/facebook:runtests-py3)",
        "--testpilot-json",
    ],
    tags = ["run_as_bundle"],
    type = "json",
    deps = [
        "@/watchman/facebook:runtests-py3",
    ],
)

def t_test(name, srcs=None, deps=None, extra_args=None):
    tname = '{}.t'.format(name)
    actual_deps=['@/watchman/thirdparty:tap']
    if deps:
        actual_deps.extend(deps)

    args=['$(location :{})'.format(tname),]

    if extra_args:
        args.extend(extra_args)

    cpp_binary(
        name=tname,
        srcs=srcs,
        deps=actual_deps,
    )
    buck_sh_test(
        name=name,
        deps=[':{}'.format(tname)],
        test='run.sh',
        args=args
    )

t_test(
    name = "art",
    srcs = [
        "art_test.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "ignore",
    srcs = [
        "ignore_test.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "pending",
    srcs = [
        "log_stub.cpp",
        "pending_test.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "string",
    srcs = [
        "log_stub.cpp",
        "string_test.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "log",
    srcs = ["log.cpp"],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "bser",
    srcs = [
        "bser.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "wildmatch",
    srcs = [
        "log_stub.cpp",
        "wildmatch_test.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
        "@/watchman/thirdparty/wildmatch:wildmatch",
    ],
)

t_test(
    name = "childproc",
    srcs = [
        "childproc.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "result",
    srcs = [
        "ResultTest.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "future",
    srcs = [
        "FutureTest.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)

t_test(
    name = "cache",
    srcs = [
        "CacheTest.cpp",
        "log_stub.cpp",
    ],
    deps = [
        "@/watchman:testsupport",
    ],
)
