Пример #1
0
 def test_patch_tescases_not_compiling_testcases(self):
     git_url = 'https://github.com/rotba/MavenProj'
     commit_h = 'a71cdc161b0d87e7ee808f5078ed5fefab758773'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == commit_h
     ][0]
     parent = commit.parents[0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_1')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_not_compiling_testcase = [
         t for t in commit_testcases if 'MainTest#gooTest' in t.mvn_name
     ][0]
     commit_new_testcases = get_delta_testcases(commit_testcases)
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None)
     patcher.patch()
     not_compiling_testcases = patcher.get_all_unpatched()
     self.assertTrue(
         expected_not_compiling_testcase in not_compiling_testcases,
         "'MainTest#gooTest should have been picked as for compilation error"
     )
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     parent_tests = mvn_repo.get_tests(module_path)
     parent_testcases = mvn.get_testcases(parent_tests)
     self.assertTrue(len(parent_testcases) > 0, 'Build probably failed')
     self.assertTrue(
         not expected_not_compiling_testcase in parent_testcases,
         expected_not_compiling_testcase.mvn_name +
         ' should have been unpatched')
Пример #2
0
 def test_patch_tescases_not_compiling_testcases_exclusive_patching(self):
     git_url = 'https://github.com/rotba/MavenProj'
     commit_h = 'e4d2bb8efdfa576632b99d0e91b35cf0262e70be'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == commit_h
     ][0]
     parent = commit.parents[0]
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_2')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_not_compiling_delta_testcase = \
      [t for t in commit_testcases if 'p_1.AssafTest#notCompTest' in t.mvn_name][0]
     expected_compiling_delta_testcase = [
         t for t in commit_testcases
         if 'p_1.AssafTest#compTest' in t.mvn_name
     ][0]
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     delta_testcases = get_delta_testcases(commit_testcases)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None).patch()
     unpatched = patcher.get_all_unpatched()
     patched = patcher.get_patched()
     self.assertTrue(
         expected_not_compiling_delta_testcase in unpatched,
         "'p_1.AssafTest#notCompTest' should have been picked for compilation error"
     )
     self.assertTrue(
         not expected_not_compiling_delta_testcase in patched,
         "'p_1.AssafTest#notCompTest' should have not benn patched")
     self.assertTrue(expected_compiling_delta_testcase in patched,
                     "'p_1.AssafTest#compTest' should have been patched")
     self.assertTrue(not expected_compiling_delta_testcase in unpatched,
                     "'p_1.AssafTest#compTest' should have been patched")
Пример #3
0
class TestRunner(object):
    def __init__(self, git_path, out_traces):
        self.git_path = git_path
        self.repo = Repo(self.git_path)
        self.out_traces = out_traces
        self.observations = {}
        self.traces = {}

    def run(self):
        import tempfile
        import shutil
        temp_dir = tempfile.mkdtemp()
        instrument_running(self.repo, self.out_traces)
        self.traces = JcovParser(self.out_traces).parse()
        self.observations = self.repo.observe_tests()
        shutil.rmtree(temp_dir)

    def get_tests(self):
        return set(self.traces.keys()) & set(self.observations.keys())

    def get_packages_tests(self):
        packages_tests = {}
        for test_name in self.get_tests():
            spllited = test_name.split('@')[0].split('.')
            for ind in range(len(spllited)):
                packages_tests.setdefault('.'.join(spllited[:ind]), set()).add(test_name)
        return packages_tests
Пример #4
0
 def trace(self, trace_failed=False):
     repo = Repo(self.get_dir_id().clones)
     DirStructure.mkdir(self.get_dir_id().traces)
     if self.test_traces:
         return
     tests_to_run = list(
         map(lambda t: ".".join(t.split('.')[:5]) + '*',
             self.failing_tests))
     tests = tests_to_run if trace_failed else None
     self.clear()
     traces = list(
         repo.run_under_jcov(self.get_dir_id().traces,
                             False,
                             instrument_only_methods=True,
                             short_type=True,
                             tests_to_run=tests,
                             check_comp_error=False))
     self.test_traces = dict(list(map(lambda t: (t.test_name, t), traces)))
Пример #5
0
 def test_patch_tescases(self):
     git_url = 'https://github.com/rotba/MavenProj'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == 'e00037324027af30134ee1554b93f5969f8f100e'
     ][0]
     parent = commit.parents[0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_1')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_delta_testcase = [
         t for t in commit_testcases if 'p_1.AmitTest#hoo' in t.mvn_name
     ][0]
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None)
     patcher.patch()
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     parent_tests = mvn_repo.get_tests(module_path)
     parent_testcases = mvn.get_testcases(parent_tests)
     self.assertTrue(
         expected_delta_testcase in parent_testcases,
         "'p_1.AmitTest should have been patchd on the parent commit and exist"
     )
Пример #6
0
 def __init__(self, git_path, out_traces):
     self.git_path = git_path
     self.repo = Repo(self.git_path)
     self.out_traces = out_traces
     self.observations = {}
     self.traces = {}
Пример #7
0
 def clean_execution(self):
     repo = Repo(self.get_dir_id().clones)
     build_report = repo.install()
     with open(self.get_dir_id().mvn_outputs, "w") as f:
         f.write(build_report)
Пример #8
0
 def read_test_results(self):
     repo = Repo(self.get_dir_id().clones)
     self.surefire_tests = repo.observe_tests()
Пример #9
0
 def generate_javadoc(self):
     repo = Repo(self.get_dir_id().clones)
     repo.javadoc_command(self.get_dir_id().javadoc)