def test_get_non_synthetic_scala_targets(self):
// scala_library - should remain.
scala_target_address = BuildFileAddress(
self.add_to_build_file(
"a/scala/BUILD", "scala_library(name="s", sources=["Source.scala"])"),
"s")self.build_graph.inject_address_closure(scala_target_address)
scala_target = self.build_graph.get_target(scala_target_address)
// scala_library but with java sources - should be filtered
scala_target_java_source_address = BuildFileAddress(
self.add_to_build_file(
"a/scala_java/BUILD", "scala_library(name="sj", sources=["Source.java"])"),
"sj")
self.build_graph.inject_address_closure(scala_target_java_source_address)
scala_target_with_java_source = self.build_graph.get_target(
scala_target_java_source_address)
// java_library - should be filtered
java_target_address = BuildFileAddress(
self.add_to_build_file(
"a/java/BUILD", "java_library(name="j", sources=["Source.java"])"),
"j")
self.build_graph.inject_address_closure(java_target_address)
java_target = self.build_graph.get_target(java_target_address)
// synthetic scala_library - should be filtered
synthetic_scala_target = self.make_target("a/synthetic_scala:ss", ScalaLibrary)
// Create a custom context so we can manually inject multiple targets of different source types
// and synthetic vs non-synthetic to test the target filtering logic.
context = self._create_context(
target_roots=[
java_target,
scala_target,
scala_target_with_java_source,
synthetic_scala_target
])
// scala_library would bring in "scala-library defined in BUILD.tools
// so we have an extra target here.
self.assertEqual(5, len(context.targets()))
// Now create the task and run the non_synthetic scala-only filtering.
task = self._create_scalastyle_task_from_context(context)
result_targets = task.get_non_synthetic_scala_targets(context.targets())
// Only the scala target should remain
self.assertEquals(1, len(result_targets))
self.assertEqual(scala_target, result_targets[0])