def test_name_injection(self):
    self.add_to_build_file('foo/bar/BUILD', '\njava_library()\n')
    build_file = self.create_buildfile('foo/bar/BUILD')
    addresses = list(self.build_file_parser.parse_build_file(build_file).keys())
    self.assertEqual(1, len(addresses))
    self.assertEqual('bar', addresses[0].target_name)
    self.add_to_build_file('foo/bar/BUILD', '\njvm_binary()\n')
    self.assert_parser_error(build_file, "defines address 'bar' more than once")
    self.add_to_build_file('BUILD', '\njava_library()\n')
    build_file = self.create_buildfile('BUILD')
    self.assert_parser_error(build_file, 'Targets in root-level BUILD files must be named explicitly')
def test_name_injection(self):
    self.add_to_build_file('foo/bar/BUILD', '\njava_library()\n')
    build_file = self.create_buildfile('foo/bar/BUILD')
    addresses = list(self.build_file_parser.parse_build_file(build_file).keys())
    self.assertEqual(1, len(addresses))
    self.assertEqual('bar', addresses[0].target_name)
    self.add_to_build_file('foo/bar/BUILD', '\njvm_binary()\n')
    self.assert_parser_error(build_file, "defines address 'bar' more than once")
    self.add_to_build_file('BUILD', '\njava_library()\n')
    build_file = self.create_buildfile('BUILD')
    self.assert_parser_error(build_file, 'Targets in root-level BUILD files must be named explicitly')