Ejemplo n.º 1
0
 def update_features_page(details: ReleaseDetails) -> None:
     features_file = '../doc/mdsource/Features.source.md'
     content = read_file(features_file)
     update_file = PrepareDocumentationRelease.prepare_update_features_page(
         details.old_version_as_text(), details.new_version_as_text(),
         content)
     update_file(features_file)
Ejemplo n.º 2
0
    def create_single_header_file(self) -> str:
        self.create_simulated_single_header_file(include_cpps=True)

        simulated_single_header = os.path.abspath(
            self.details.locations.simulated_single_header_file_path)
        with use_directory("../build"):
            print(os.getcwd())
            self.run_for_approval_tests(simulated_single_header,
                                        self.details.release_new_single_header)
            text = read_file(self.details.release_new_single_header)

            text = (
                f'// {self.details.project_details.github_project_name} version {self.details.new_version_as_text()}\n'
                f'// More information at: {self.details.project_details.github_project_url}\n'
                '\n'
                '//----------------------------------------------------------------------\n'
                '// Welcome to Approval Tests.\n'
                '//\n'
                '// If you experience linker errors about missing symbols, it means\n'
                '// you have forgotten to configure your test framework for Approval Tests.\n'
                '//\n'
                '// For help with this, please see:\n'
                '//     https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredMain.md\n'
                '//----------------------------------------------------------------------\n'
                f'{text}')
            write_file(self.details.release_new_single_header, text)

        # HACK! A side-effect of this method is that it overwrites
        # the version-controlled simulated single-header, including .cpp
        # files.
        # Revert that change:
        self.create_simulated_single_header_file(include_cpps=False)

        return os.path.abspath(self.details.release_new_single_header)
Ejemplo n.º 3
0
    def create_single_header_file(self) -> str:
        self.create_simulated_single_header_file(include_cpps=True)

        simulated_single_header = os.path.abspath(
            self.details.locations.simulated_single_header_file_path)
        with use_directory("../build"):
            print(os.getcwd())
            self.run_for_approval_tests(simulated_single_header,
                                        self.details.release_new_single_header)
            text = read_file(self.details.release_new_single_header)

            text = (
                f'// {self.details.project_details.github_project_name} version {self.details.new_version_as_text()}\n'
                f'// More information at: {self.details.project_details.github_project_url}\n'
                '\n'
                f'{text}')
            write_file(self.details.release_new_single_header, text)

        # HACK! A side-effect of this method is that it overwrites
        # the version-controlled simulated single-header, including .cpp
        # files.
        # Revert that change:
        self.create_simulated_single_header_file(include_cpps=False)

        return os.path.abspath(self.details.release_new_single_header)
Ejemplo n.º 4
0
    def update_conan_config_yml(conan_approvaltests_dir: str, new_version: Version) -> None:
        conan_data_file = os.path.join(conan_approvaltests_dir, 'config.yml')
        conandata_yml_text = read_file(conan_data_file)

        conandata_yml_text += PrepareConanRelease.create_conan_config_yml_text(new_version)

        write_file(conan_data_file, conandata_yml_text)
Ejemplo n.º 5
0
 def test_file_reading_and_writing(self) -> None:
     text = '<caterpillar>blue</caterpillar>'
     file_name = 'bug.txt'
     write_file(file_name, text)
     replace_text_in_file(file_name, 'caterpillar', 'butterfly')
     new_text = read_file(file_name)
     self.assertEqual(new_text, '<butterfly>blue</butterfly>')
     os.remove(file_name)
Ejemplo n.º 6
0
 def upload_release_to_github(self) -> None:
     # Draft the upload to github
     release_notes = read_file(self.details.new_release_notes_path)
     pyperclip.copy(release_notes)
     print('The release notes are on the clipboard')
     github_url = F"'https://github.com/approvals/ApprovalTests.cpp/releases/new?tag={self.details.new_version_as_text()}&title=Single%20Hpp%20File%20-%20{self.details.new_version_as_text()}'"
     run(["open", github_url])
     run(["open", release_constants.release_dir])
     check_step("that the release is published")
Ejemplo n.º 7
0
 def upload_release_to_github(self) -> None:
     # Draft the upload to github
     release_notes = read_file(self.details.new_release_notes_path)
     pyperclip.copy(release_notes)
     print('The release notes are on the clipboard')
     github_url = self.get_github_release_url()
     run(["open", github_url])
     run(["open", release_constants.release_dir])
     check_step("that the release is published")
Ejemplo n.º 8
0
 def get_parts(file: str) -> Parts:
     # This is effectively creating a Directed Acyclic Graph of all files
     # and their #includes, which we later sort by dependency order.
     content = read_file(os.path.join('..', file))
     lines = content.splitlines()
     include_lines = filter(lambda t: t.startswith('#include "'), lines)
     include_files = list(
         map(lambda i: i.replace('#include ', '').replace('"', ''),
             include_lines))
     include_files = list(map(lambda f: get_file_name(f), include_files))
     return Parts(file, include_files)
Ejemplo n.º 9
0
    def create_single_header_file(self) -> str:
        self.create_simulated_single_header_file(include_cpps=True)

        simulated_single_header = os.path.abspath(
            self.details.locations.simulated_single_header_file_path)
        with use_directory("../build"):
            print(os.getcwd())
            self.run_for_approval_tests(simulated_single_header,
                                        self.details.release_new_single_header)
            text = read_file(self.details.release_new_single_header)

            year = datetime.now().year
            text = (
                f'// {self.details.project_details.github_project_name} version {self.details.new_version_as_text()}\n'
                f'// More information at: {self.details.project_details.github_project_url}\n'
                f'//\n'
                f'// Copyright (c) {year} Llewellyn Falco and Clare Macrae. All rights reserved.\n'
                f'//\n'
                f'// Distributed under the Apache 2.0 License\n'
                f'// See https://opensource.org/licenses/Apache-2.0\n'
                f'\n'
                '//----------------------------------------------------------------------\n'
                '// Welcome to Approval Tests.\n'
                '//\n'
                '// If you experience linker errors about missing symbols, it means\n'
                '// you have forgotten to configure your test framework for Approval Tests.\n'
                '//\n'
                '// For help with this, please see:\n'
                '//     https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredMain.md\n'
                '//----------------------------------------------------------------------\n'
                f'{text}')
            write_file(self.details.release_new_single_header, text)

        # HACK! A side-effect of this method is that it overwrites
        # the version-controlled simulated single-header, including .cpp
        # files.
        # Revert that change:
        self.create_simulated_single_header_file(include_cpps=False)

        # Check for broken headers in the generated text
        # (but only after we have reverted any modified source code)
        header_files_h = SingleHeaderFile.get_all_files('.', '.h')
        header_files_hpp = SingleHeaderFile.get_all_files('.', '.hpp')
        errors = CppGeneration.validate_single_header_file_content(
            header_files_h, header_files_hpp, text)
        if errors != "":
            raise RuntimeError(errors)

        return os.path.abspath(self.details.release_new_single_header)
Ejemplo n.º 10
0
    def update_conandata_yml(details: ReleaseDetails, conan_approvaltests_dir: str) -> None:
        version = details.new_version
        conan_data_file = os.path.join(conan_approvaltests_dir, 'all', 'conandata.yml')
        conandata_yml_text = read_file(conan_data_file)

        new_single_header = details.release_new_single_header
        licence_file = '../LICENSE'

        single_header_sha = calculate_sha256(new_single_header)
        licence_file_sha = calculate_sha256(licence_file)
        conan_data = PrepareConanRelease.create_conandata_yml_text(details.project_details, version, single_header_sha,
                                                                   licence_file_sha)
        conandata_yml_text += conan_data

        write_file(conan_data_file, conandata_yml_text)
Ejemplo n.º 11
0
    def create_single_header_file(self) -> str:
        self.create_simulated_single_header_file()

        simulated_single_header = os.path.abspath(
            release_constants.simulated_single_header_file_path)
        with use_directory("../build"):
            print(os.getcwd())
            self.run_for_approval_tests(simulated_single_header,
                                        self.details.release_new_single_header)
            text = read_file(self.details.release_new_single_header)
            text = (
                f'// Approval Tests version {self.details.new_version_as_text()}\n'
                '// More information at: https://github.com/approvals/ApprovalTests.cpp\n'
                '\n'
                f'{text}')
            write_file(self.details.release_new_single_header, text)
            return os.path.abspath(self.details.release_new_single_header)
Ejemplo n.º 12
0
 def with_embedded_cpp_file_with_include(filename: str) -> bool:
     content = read_file(filename)
     snippet = ".cpp -->"
     namespace = "\nusing namespace ApprovalTests;"
     return snippet in content and namespace in content
Ejemplo n.º 13
0
 def with_both(filename: str) -> bool:
     content = read_file(filename)
     snippet = "begin-snippet"
     namespace = "\nusing namespace ApprovalTests;"
     return snippet in content and namespace in content