load("@bazel_skylib//:lib.bzl", "asserts", "unittest")
load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library")
load("//thrift:thrift.bzl", "thrift_library")

def _scrooge_transitive_outputs(ctx):
    env = unittest.begin(ctx)

    asserts.set_equals(
        env,
        depset(ctx.attr.expected_jars),
        depset([out.class_jar.basename for out in ctx.attr.dep[JavaInfo].outputs.jars]),
    )

    return unittest.end(env)

scrooge_transitive_outputs_test = unittest.make(
    _scrooge_transitive_outputs,
    attrs = {
        "dep": attr.label(),
        "expected_jars": attr.string_list(),
    },
)

def test_scrooge_provides_transitive_jars():
    # :scrooge1 depends on thrift2_b and thrift2_a which both depend on thrift3
    # All associated jars must be included in the outputs for IntelliJ resolution to function correctly.
    scrooge_transitive_outputs_test(
        name = "transitive_scrooge_test_scala",
        dep = ":scrooge1",
        expected_jars = [
            "thrift_scrooge_scala.jar",
            "thrift2_a_scrooge_scala.jar",
            "thrift2_b_scrooge_scala.jar",
            "thrift3_scrooge_scala.jar",
        ],
    )
    scrooge_transitive_outputs_test(
        name = "transitive_scrooge_test_scala_and_java",
        dep = ":scrooge1_scala_and_java",
        expected_jars = [
            "thrift3_scrooge_scala.jar",
            "thrift2_a_scrooge_scala.jar",
            "thrift2_b_scrooge_scala.jar",
            "thrift3_scrooge_java.jar",
            "thrift_scrooge_scala.jar",
        ],
    )
    scrooge_transitive_outputs_test(
        name = "transitive_scrooge_test_java",
        dep = ":scrooge1_java",
        expected_jars = [
            "thrift_scrooge_java.jar",
            "thrift2_a_scrooge_java.jar",
            "thrift2_b_scrooge_java.jar",
            "thrift3_scrooge_java.jar",
        ],
    )

def twitter_scrooge_test_suite():
    test_scrooge_provides_transitive_jars()

    native.test_suite(
        name = "twitter_scrooge_tests",
        tests = [
            ":transitive_scrooge_test_scala",
            ":transitive_scrooge_test_java",
        ],
    )

@@ -18,12 +18,20 @@
 ib//
-:
 lib
+:unittest
 .bzl
@@ -56,16 +56,74 @@
 ttest%22)%0A
+load(%22@bazel_skylib//lib:collections.bzl%22, %22collections%22)%0A
 load(%22//
@@ -317,12 +317,8 @@
 rts.
-set_
 equa
@@ -342,22 +342,22 @@
         
-depset
+sorted
 (ctx.att
@@ -386,14 +386,31 @@
     
-depset
+sorted(collections.uniq
 (%5Bou
@@ -478,16 +478,17 @@
 s.jars%5D)
+)
 ,%0A    )%0A

Remove call to obsolete function asserts.set_equals (#1069)