Пример #1
0
 def test_find_test_cases_diff(self):
     print('test_find_test_cases_diff')
     Main.set_up(['', 'https://github.com/rotba/MavenProj'])
     commit = [
         c for c in list(Main.repo.iter_commits(Main.branch_inspected))
         if c.hexsha == '14ef5aa7f71f2beb78f38227399ec4b3388b4127'
     ][0]
     proj_name = 'MavenProj'
     test_path = reduce(
         lambda acc, curr: os.path.join(acc, curr),
         ['sub_mod_2', 'src', 'test', 'java', 'p_1', 'AssafTest.java'],
         settings.ProjFiles(proj_name).repo)
     module_path = os.path.join(
         settings.ProjFiles(proj_name).repo, 'sub_mod_2')
     Main.prepare_project_repo_for_testing(commit, module_path)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     test = Main.TestObjects.TestClass(test_path)
     expected_delta_testcase = [
         t for t in test.testcases if 'p_1.AssafTest#goo' in t.mvn_name
     ][0]
     Main.prepare_project_repo_for_testing(commit.parents[0], module_path)
     diff_testcases = Main.find_test_cases_diff(test, test.src_path)
     self.assertTrue(expected_delta_testcase in diff_testcases)
Пример #2
0
 def test_get_bugged_components_2(self):
     repo_path = settings.ProjFiles('MavenProj').repo
     Main.USE_CACHE = False
     Main.GENERATE_DATA = False
     repo = git.Repo(repo_path)
     repo.git.add('.')
     repo.git.clean('-xdf')
     repo.git.checkout('master', '-f')
     commits = list(
         filter(
             lambda c:
             ('2e1ab62576cf3a76067b794bce8a603d3b877309' in c.hexsha or
              'c3ce28f10eade94a6ebf2c280c29c432e378be69' in c.hexsha),
             list(repo.iter_commits())))
     commit_fix = commits[0]
     commit_bug = commits[1]
     Main.repo = repo
     repo.git.add('.')
     repo.git.clean('-xdf')
     repo.git.checkout(commit_bug, '-f')
     changed_methods = Main.get_bugged_components(commit_fix=commit_fix,
                                                  commit_bug=commit_bug,
                                                  module=os.path.join(
                                                      repo_path,
                                                      'sub_mod_1'))
     self.assertTrue(len(changed_methods) == 2)
     self.assertTrue('sub_mod_1#Main#int_foo()' in changed_methods)
     self.assertTrue('sub_mod_1#Main#void_goo()' in changed_methods)
Пример #3
0
 def test_get_bugged_components_1(self):
     repo_path = settings.ProjFiles('MavenProj').repo
     Main.USE_CACHE = False
     Main.GENERATE_DATA = False
     repo = git.Repo(repo_path)
     repo.git.add('.')
     repo.git.clean('-xdf')
     repo.git.checkout('master', '-f')
     commits = list(
         filter(
             lambda c:
             ('b9bccfb7a5dc2bf3537d59341ac2622713393065' in c.hexsha or
              '6553c2aabc39f8749bae6939f4e8c216a0b08050' in c.hexsha),
             list(repo.iter_commits())))
     commit_fix = commits[0]
     commit_bug = commits[1]
     Main.repo = repo
     repo.git.add('.')
     repo.git.clean('-xdf')
     repo.git.checkout(commit_bug, '-f')
     changed_methods = Main.get_bugged_components(commit_fix=commit_fix,
                                                  commit_bug=commit_bug,
                                                  module=os.path.join(
                                                      repo_path,
                                                      'sub_mod_1'))
     self.assertTrue(len(changed_methods) == 2)
     self.assertTrue('sub_mod_1#Main#int_foo()' in changed_methods)
     self.assertTrue('sub_mod_1#Main#void_goo()' in changed_methods)
Пример #4
0
 def test_extract_bugs_delta_testcases_that_passed_in_parrent(self):
     print('test_extract_bugs_pick_up_failures')
     Main.set_up(['', 'https://github.com/rotba/MavenProj'])
     issue = jira.issue('TIKA-19')
     possible_bugs_extractor = JiraExtractor(
         repo_dir=Main.repo.working_dir,
         branch_inspected=Main.branch_inspected,
         jira_url='')
     proj_name = 'MavenProj'
     exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [
         'sub_mod_1', 'src', 'test', 'java', 'p_1',
         'AmitTest.java#AmitTest#None_deltaPassedTest()'
     ],
                              settings.ProjFiles(proj_name).repo)
     commit = [
         c for c in list(Main.repo.iter_commits(Main.branch_inspected))
         if c.hexsha == 'd03e45c84ad903435fae8f1814a56569906663eb'
     ][0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     Main.repo.git.reset('--hard')
     Main.repo.git.checkout(commit.hexsha)
     tests_paths = possible_bugs_extractor.get_tests_paths_from_commit(
         commit)
     res = Main.extract_bugs(
         issue, commit, tests_paths,
         possible_bugs_extractor.get_changed_components(commit))
     for bug in res:
         if not bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.DELTA \
           and bug.desctiption == Main.mvn_bug.invalid_passed_desc:
             return
     self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
Пример #5
0
 def test_extract_bugs_pick_up_failures(self):
     print('test_extract_bugs_pick_up_failures')
     Main.set_up(['', 'https://github.com/rotba/MavenProj'])
     issue = jira.issue('TIKA-19')
     possible_bugs_extractor = JiraExtractor(
         repo_dir=Main.repo.working_dir,
         branch_inspected=Main.branch_inspected,
         jira_url='')
     proj_name = 'MavenProj'
     exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [
         'sub_mod_1', 'src', 'test', 'java', 'p_1',
         'AmitTest.java#AmitTest#None_RTerrorTest()'
     ],
                              settings.ProjFiles(proj_name).repo)
     commit = [
         c for c in list(Main.repo.iter_commits(Main.branch_inspected))
         if c.hexsha == '1d3c81c1f7a4722408264cc5279df7abb22a3c04'
     ][0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     Main.repo.git.reset('--hard')
     Main.repo.git.checkout(commit.hexsha)
     tests_paths = possible_bugs_extractor.get_tests_paths_from_commit(
         commit)
     res = Main.extract_bugs(
         issue, commit, tests_paths,
         possible_bugs_extractor.get_changed_components(commit))
     for bug in res:
         if not bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.REGRESSION \
           and bug.desctiption.startswith(Main.mvn_bug.invalid_rt_error_desc):
             return
     self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
Пример #6
0
 def test_extract_bugs_2(self):
     Main.set_up(['', 'https://github.com/rotba/MavenProj'])
     possible_bugs_extractor = JiraExtractor(
         repo_dir=Main.repo.working_dir,
         branch_inspected=Main.branch_inspected,
         jira_url='')
     issue = jira.issue('TIKA-19')
     proj_name = 'MavenProj'
     exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [
         'sub_mod_1', 'src', 'test', 'java', 'p_1',
         'AmitTest.java#AmitTest#None_fooTest()'
     ],
                              settings.ProjFiles(proj_name).repo)
     commit = [
         c for c in list(Main.repo.iter_commits(Main.branch_inspected))
         if c.hexsha == '19f6c78889f9e929bc964d420315a043b62c7967'
     ][0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     Main.repo.git.reset('--hard')
     Main.repo.git.checkout(commit.hexsha)
     tests_paths = possible_bugs_extractor.get_tests_paths_from_commit(
         commit)
     res = Main.extract_bugs(
         issue, commit, tests_paths,
         possible_bugs_extractor.get_changed_components(commit))
     for bug in res:
         if bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.DELTA:
             return
     self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
Пример #7
0
 def test_get_commit_created_testcases(self):
     print('test_get_commit_created_testcases')
     Main.set_up(['', 'https://github.com/rotba/MavenProj'])
     proj_name = 'MavenProj'
     commit = [
         c for c in list(Main.repo.iter_commits(Main.branch_inspected))
         if c.hexsha == '1fd244f006c96fa820efa850f5f31e3f9a727d84'
     ][0]
     parent = commit.parents[0]
     module_path = settings.ProjFiles(proj_name).repo
     Main.repo.git.reset('--hard')
     Main.repo.git.checkout(commit.hexsha)
     tests = Main.mvn_repo.get_tests(module_path)
     testcases = Main.mvn.get_testcases(tests)
     Main.prepare_project_repo_for_testing(parent, module_path)
     new_testcases = Main.get_delta_testcases(testcases)
     expected_new_testcase = [
         t for t in testcases if 'MainTest#foo_2' in t.mvn_name
     ][0]
     self.assertTrue(expected_new_testcase in new_testcases,
                     'MainTest#foo_2 should be picked for being new test')
Пример #8
0
def set_up(git_url, jira_url, specific_commit=None, RESET=False):
    def clone_repo(base, url, label=''):
        # git_cmds_wrapper(lambda: git.Git(base).init())
        repo_url = url.geturl().replace('\\', '/').replace('////', '//')
        git_cmds_wrapper(lambda: git.Git(base).clone(repo_url))

    global dict_key_issue
    global dict_hash_commit
    global reg_repo
    global reg_mvn_repo
    global repo
    global mvn_repo
    global patches_dir
    global traces_dir
    global outcomes_dir
    global xmls_dir
    global builds_dir
    global test_results_path
    global test_results_path_trace
    global test_results_path_fix
    global proj_results_dir
    global proj_name
    global bug_data_handler
    global cache_dir
    global tmp_files_dir
    global data_dir
    global branch_inspected
    global state_patches_cache_dir
    git_url = urlparse(git_url)
    proj_name = os.path.basename(git_url.path)
    proj_files = settings.ProjFiles(proj_name)
    if os.path.exists(proj_files.base):
        shutil.rmtree(proj_files.base, ignore_errors=True)
    cache_dir = proj_files.cache
    state_patches_cache_dir = proj_files.states
    tmp_files_dir = proj_files.tmp
    patches_dir = proj_files.patches
    traces_dir = proj_files.traces
    outcomes_dir = proj_files.outcomes
    xmls_dir = proj_files.xmls
    builds_dir = proj_files.builds
    test_results_path = proj_files.test_results
    test_results_path_trace = proj_files.test_results_path_trace
    test_results_path_fix = proj_files.test_results_path_fix
    results_dir = settings.RESULTS_DIR
    data_dir = settings.DATA_DIR
    proj_results_dir = os.path.join(results_dir, proj_name)
    if not os.path.isdir(proj_results_dir):
        os.makedirs(proj_results_dir)
    if not os.path.isdir(settings.TESTED_PROJECTS_DIR):
        os.makedirs(settings.TESTED_PROJECTS_DIR)
    if not os.path.isdir(cache_dir):
        os.makedirs(cache_dir)
    if not os.path.isdir(state_patches_cache_dir):
        os.makedirs(state_patches_cache_dir)
    if not os.path.isdir(proj_files.reg):
        os.makedirs(proj_files.reg)
    if not os.path.isdir(tmp_files_dir):
        os.makedirs(tmp_files_dir)
    else:
        shutil.rmtree(tmp_files_dir)
        os.makedirs(tmp_files_dir)
    set_up_traces_dir()
    set_up_outcomes_dir()
    set_up_xmls_dir()
    set_up_builds_dir()
    if not RESET:
        bug_data_handler = mvn_bug.Bug_data_handler(proj_results_dir)
    if not RESET:
        LOG_FILENAME = os.path.join(proj_results_dir, 'log.log')
        logging.basicConfig(filename=LOG_FILENAME,
                            level=logging.INFO,
                            format='%(asctime)s %(message)s')
    clone_repo(proj_files.base, git_url)
    clone_repo(proj_files.reg, git_url, 'regression')
    mvn_repo = MavenRepo.Repo(proj_files.repo)
    repo = Repo(proj_files.repo)
    reg_mvn_repo = MavenRepo.Repo(proj_files.reg_repo)
    reg_repo = Repo(proj_files.reg_repo)
    if not os.path.isdir(cache_dir):
        os.makedirs(cache_dir)
    if branch_inspected == None or branch_inspected == '':
        branch_inspected = repo.branches[0].name