def test_two_repos_oxygen(self):
        """
        Make sure that running Oxygen on two repos throws an error.

        That's meant to happen because the
        functionality is not yet implemented.
        """
        with raises(UserInputError):
            run_two_repos(self.modules1, self.modules2, OXYGEN)
    def _func_def_generic(self, second, algorithm, single):
        result = run_single_repo(self.reference + second, algorithm) \
            if single else run_two_repos(self.reference, second, algorithm)

        assert result is not None
        assert isinstance(result, DetectionResult)

        return result
예제 #3
0
def main():
    """Entry point of the application."""
    try:
        # Parse command start arguments
        repos, algorithm = handle_cli_args()

        time_snap("Arguments handled; Repositories parsed")

        module_list_1 = get_modules_from_dir(repos[0])
        time_snap("First repository modules parsed")

        if not module_list_1:
            raise UserInputError(f"First repository is empty: \"{repos[0]}\"")

        if repos[1]:
            module_list_2 = get_modules_from_dir(repos[1])
            time_snap("Second repository modules parsed")

            if not module_list_2:
                raise UserInputError(
                    f"Second repository is empty: \"{repos[1]}\"")

            log.info("Running a two-repository analysis...")
            result = run_two_repos(module_list_1, module_list_2, algorithm)

        else:
            log.info("Running a single-repository analysis...")
            result = run_single_repo(module_list_1, algorithm)

        time_snap("Analysis completed")

        # Save detection result to a JSON file.

        repo_0 = repos[0][repos[0].rfind('/') + 1:]
        json_filename = "clones_" + algorithm + "_" + repo_0 + "_"
        if repos[1]:
            repo_1 = repos[1][repos[1].rfind('/') + 1:]
            json_filename += repo_1 + "_"
        json_filename += datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".json"

        with open(json_filename, "w") as f:
            f.write(result.json())

    except UserInputError as ex:
        if ex.message:
            log.error(ex.message)

        sys.exit(ex.code)
예제 #4
0
def main():
    """Entry point of the application."""
    try:
        # Parse command line arguments
        repos, algorithm = handle_cli_args()

        time_snap("Cloned repositories")

        # Find all functions and parse their syntax tree using the TreeNode wrapper
        log.info("Parsing methods in repositories...")
        module_list_1 = get_modules_from_dir(repos[0])

        if not module_list_1:
            raise UserInputError(f"First repository is empty: \"{repos[0]}\"")

        time_snap("Parsed first repository")

        module_list_2 = get_modules_from_dir(repos[1])

        if not module_list_2:
            raise UserInputError(f"Second repository is empty: \"{repos[1]}\"")

        time_snap("Parsed second repository")

        log.info("Beginning full analysis...")
        clones = run_two_repos(module_list_1, module_list_2, algorithm)
        time_snap("Analysis completed")

        # Create output directory if it doesn't exist and print output
        output_path = os.getcwd()
        output_filename = "clones_" + \
            datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".json"
        os.makedirs(output_path, exist_ok=True)
        with open(os.path.join(output_path, output_filename),
                  "w") as output_file:
            output_file.write(clones.json())

    except UserInputError as ex:
        if ex.message:
            log.error(ex.message)

        sys.exit(ex.code)
    def test_two_repos_iodine(self):
        """Compare direct Iodine result with the algorithm runner result."""
        direct_result = iodine(self.modules1, self.modules2)
        runner_result = run_two_repos(self.modules1, self.modules2, IODINE)

        assert direct_result.json() == runner_result.json()
    def test_two_repos_chlorine(self):
        """Compare direct Chlorine result with the algorithm runner result."""
        direct_result = chlorine_two_repos(self.modules1, self.modules2)
        runner_result = run_two_repos(self.modules1, self.modules2, CHLORINE)

        assert direct_result.json() == runner_result.json()