def test_classpath_does_not_include_extra_classes_dirs(self): target_rel_spec = 'testprojects/src/java/org/pantsbuild/testproject/phrases:' classpath_file_by_target_id = {} for target_name in [ 'there-was-a-duck', 'lesser-of-two', 'once-upon-a-time', 'ten-thousand' ]: target_id = Target.compute_target_id( Address.parse('{}{}'.format(target_rel_spec, target_name))) classpath_file_by_target_id[target_id] = '{}.txt'.format(target_id) with self.do_test_compile( target_rel_spec, expected_files=classpath_file_by_target_id.values(), extra_args=['--compile-zinc-capture-classpath']) as found: for target_id, filename in classpath_file_by_target_id.items(): found_classpath_file = self.get_only(found, filename) with open(found_classpath_file, 'r') as f: contents = f.read() self.assertIn(target_id, contents) other_target_ids = set( classpath_file_by_target_id.keys()) - {target_id} for other_id in other_target_ids: self.assertNotIn(other_id, contents)
def test_classpath_does_not_include_extra_classes_dirs(self): target_rel_spec = "testprojects/src/java/org/pantsbuild/testproject/phrases:" classpath_file_by_target_id = {} for target_name in [ "there-was-a-duck", "lesser-of-two", "once-upon-a-time", "ten-thousand", ]: target_id = Target.compute_target_id( Address.parse("{}{}".format(target_rel_spec, target_name)) ) classpath_file_by_target_id[target_id] = f"{target_id}.txt" with self.do_test_compile( target_rel_spec, expected_files=list(classpath_file_by_target_id.values()), extra_args=["--compile-rsc-capture-classpath"], ) as found: for target_id, filename in classpath_file_by_target_id.items(): found_classpath_file = self.get_only(found, filename) with open(found_classpath_file, "r") as f: contents = f.read() self.assertIn(target_id, contents) other_target_ids = set(classpath_file_by_target_id.keys()) - {target_id} for other_id in other_target_ids: self.assertNotIn(other_id, contents)
def test_no_record_classpath(self): target_spec = 'testprojects/src/java/org/pantsbuild/testproject/printversion:printversion' target_id = Target.compute_target_id(Address.parse(target_spec)) classpath_filename = '{}.txt'.format(target_id) with self.do_test_compile(target_spec, expected_files=['PrintVersion.class'], extra_args=['--no-compile-zinc-capture-classpath']) as found: self.assertFalse(classpath_filename in found)
def test_no_record_classpath(self): target_spec = "testprojects/src/java/org/pantsbuild/testproject/printversion:printversion" target_id = Target.compute_target_id(Address.parse(target_spec)) classpath_filename = f"{target_id}.txt" with self.do_test_compile( target_spec, expected_files=["PrintVersion.class"], extra_args=["--no-compile-rsc-capture-classpath"], ) as found: self.assertFalse(classpath_filename in found)
def test_record_classpath(self): target_spec = 'testprojects/src/java/org/pantsbuild/testproject/printversion:printversion' target_id = Target.compute_target_id(Address.parse(target_spec)) classpath_filename = '{}.txt'.format(target_id) with self.do_test_compile(target_spec, expected_files=[classpath_filename, 'PrintVersion.class'], extra_args=['--compile-zinc-capture-classpath']) as found: found_classpath_file = self.get_only(found, classpath_filename) self.assertTrue(found_classpath_file .endswith(os.path.join('compile_classpath', classpath_filename))) with open(found_classpath_file, 'r') as f: self.assertIn(target_id, f.read())
def test_record_classpath(self): target_spec = "testprojects/src/java/org/pantsbuild/testproject/printversion:printversion" target_id = Target.compute_target_id(Address.parse(target_spec)) classpath_filename = f"{target_id}.txt" with self.do_test_compile( target_spec, expected_files=[classpath_filename, "PrintVersion.class"], extra_args=["--compile-rsc-capture-classpath"], ) as found: found_classpath_file = self.get_only(found, classpath_filename) self.assertTrue( found_classpath_file.endswith(os.path.join("compile_classpath", classpath_filename)) ) with open(found_classpath_file, "r") as f: self.assertIn(target_id, f.read())
def test_classpath_does_not_include_extra_classes_dirs(self): target_rel_spec = 'testprojects/src/java/org/pantsbuild/testproject/phrases:' classpath_file_by_target_id = {} for target_name in ['there-was-a-duck', 'lesser-of-two', 'once-upon-a-time', 'ten-thousand']: target_id = Target.compute_target_id(Address.parse('{}{}' .format(target_rel_spec, target_name))) classpath_file_by_target_id[target_id] = '{}.txt'.format(target_id) with self.do_test_compile(target_rel_spec, expected_files=classpath_file_by_target_id.values(), extra_args=['--compile-zinc-capture-classpath']) as found: for target_id, filename in classpath_file_by_target_id.items(): found_classpath_file = self.get_only(found, filename) with open(found_classpath_file, 'r') as f: contents = f.read() self.assertIn(target_id, contents) other_target_ids = set(classpath_file_by_target_id.keys()) - {target_id} for other_id in other_target_ids: self.assertNotIn(other_id, contents)
def skip_instrumentation(**kwargs): return Target.compute_target_id(kwargs["address"]).startswith( ".pants.d.gen") or ScoveragePlatform.global_instance( ).is_blacklisted(kwargs["address"].spec)