def test_small_block(self): self.assertEqual( [ Command("cd /tmp", "/tmp", [MAKEANNOTATIONHINT]), Command("cc -c -o main.o main.c", "/tmp"), Command("cc -c -o divisible.o divisible.c", "/tmp"), Command("cc -o divisible main.o divisible.o", "/tmp") ], # "cd " + os.getcwd() + MAKEANNOTATIONHINT], translate_to_commands( dedent("""\ make: Entering directory '/tmp' + cc -c -o main.o main.c + cc -c -o divisible.o divisible.c + cc -o divisible main.o divisible.o """)) # make: Leaving directory '/tmp' )
def apply_transformation_on(cmd, container): print("TransformCmakeLink " + cmd.bashcmd) link_file_name = re.split('\\s', cmd.bashcmd)[3] link_file = open(cmd.curdir + "/" + link_file_name, 'r') link_line = link_file.readline() link_cmd = Command(link_line, cmd.curdir) relevant = directory.list_all_llvm_transformers() for transformer in relevant: if transformer is TransformCmakeLink: continue if transformer.can_be_applied_on(link_cmd): transformed_cmd = transformer.apply_transformation_on( link_cmd, container) print("Transformed cmake link command " + transformed_cmd.bashcmd) return transformed_cmd print("Could not transform from cmake file ") print(cmd.curdir + "/" + link_file_name) print("Command") print(link_cmd.bashcmd) exit(-1) return None
def test_failcount(self): self.assertEqual(0, self.llvm.skipped) self.llvm.transform( Command("just impossible to translate wtf", "/tmp")) self.assertEqual(1, self.llvm.skipped)
def test_empty(self): self.assertEqual( Command("", "/tmp"), self.llvm.transform(Command("", "/tmp")))
def register(self, cmd, curdir): self.llvm.register(Command(cmd, curdir))
def test_spaces(self): self.assertTrue(Command(" ", "/tmp").is_noop())
def test_empty(self): self.assertTrue(Command("", "/tmp").is_noop())
def test_command_with_comment(self): self.assertFalse( Command("cd dir # change directory", "/tmp").is_noop())
def test_comment_with_leading_space(self): self.assertTrue(Command(" # comment", "/tmp").is_noop())
def test_comment(self): self.assertTrue(Command("# comment", "/tmp").is_noop())
def test_command(self): self.assertFalse(Command("cd dir", "/tmp").is_noop()) self.assertFalse(Command("cc -c main.c", "/tmp").is_noop())
def assertTransformation(self, transformation, command, curdir="/tmp"): self.assertEqual(Command(transformation, curdir), self.llvm.transform(Command(command, curdir)))
def test_cd_keep_make(self): self.assertEqual( Command("cd mydir", "/tmp", [MAKEANNOTATIONHINT]), self.llvm.transform( Command("cd mydir", "/tmp", [MAKEANNOTATIONHINT])))
def test_make_statement(self): self.assertEqual( [Command("cd /tmp", "/tmp", [MAKEANNOTATIONHINT])], translate_to_commands("make: Entering directory '/tmp'"))
def test_string_representation(self): self.assertTrue( str(Command("cmd that does something", "/somedir")).startswith("cmd that does something"))