def update_version_number_header(self) -> None: with use_directory(release_constants.approval_tests_dir): version_header = os.path.join("ApprovalTestsVersion.h") text = CppGeneration.get_version_number_hpp_text( self.details.new_version) write_file(version_header, text)
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)
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)
def update_vcpkg_vcpkg_json(vcpkg_approvaltests_dir: str, new_version: Version) -> None: vcpkg_data_file = os.path.join(vcpkg_approvaltests_dir, 'vcpkg.json') portfile_cmake_text = PrepareVcpkgRelease.create_vcpkg_vcpkg_json_text( new_version) write_file(vcpkg_data_file, portfile_cmake_text)
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)
def update_version_number_header(self) -> None: with use_directory(self.details.locations.approval_tests_dir): version_header = os.path.join( self.details.project_details.version_header) text = CppGeneration.get_version_number_hpp_text( self.details.new_version, self.details.project_details) write_file(version_header, text)
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)
def create(directory: str, project_details: ProjectDetails, include_cpps: bool) -> str: output = SingleHeaderFile.create_content(directory, project_details, include_cpps) locations = ReleaseLocations(project_details) output_file = os.path.abspath( locations.simulated_single_header_file_path) write_file(output_file, output) return output_file
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)
def update_portfile_cmake(details: ReleaseDetails, vcpkg_approvaltests_dir: str) -> None: version = details.new_version vcpkg_data_file = os.path.join(vcpkg_approvaltests_dir, 'portfile.cmake') new_single_header = details.release_new_single_header licence_file = '../LICENSE' single_header_sha = calculate_sha512(new_single_header) licence_file_sha = calculate_sha512(licence_file) portfile_cmake_text = PrepareVcpkgRelease.create_portfile_cmake_text( version, single_header_sha, licence_file_sha) write_file(vcpkg_data_file, portfile_cmake_text)
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)
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)
def create(directory: str) -> str: files = SingleHeaderFile.get_all_files(directory) files = SingleHeaderFile.sort_by_dependencies(files) output_file = os.path.abspath( release_constants.simulated_single_header_file_path) includes = '\n'.join(map(lambda f: f'#include "{f}"', files)) output = ('#ifndef APPROVALTESTS_CPP_APPROVALS_HPP\n' '#define APPROVALTESTS_CPP_APPROVALS_HPP\n' '\n' '// This file is machine-generated. Do not edit.\n' '\n' f'{includes}\n' '\n' '#endif // APPROVALTESTS_CPP_APPROVALS_HPP\n') write_file(output_file, output) return output_file