def test_call_without_specifying_dir(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "dev1+rev%s" GIT_TAG_NAME = "master" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False """ % (commit_id[0:7], commit_id[0:7]) script_dir = os.getcwd() with ChDir(git.dir), open("/dev/null", 'w') as devnull: subprocess.check_call([ sys.executable, "-m", "gitversionbuilder", "--lang", "python", out_file ], stdout=devnull, env={"PYTHONPATH": script_dir}) self.assertCodeEqual(expected, self.read_file(out_file))
def test_call_cpp(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ // --------------------------------------------------- // This file is autogenerated by git-version. // DO NOT MODIFY! // --------------------------------------------------- #pragma once #ifndef MESSMER_GITVERSION_VERSION_H #define MESSMER_GITVERSION_VERSION_H namespace version { constexpr const char *VERSION_STRING = "dev1+rev%s"; constexpr const char *GIT_TAG_NAME = "master"; constexpr const unsigned int GIT_COMMITS_SINCE_TAG = 1; constexpr const char *GIT_COMMIT_ID = "%s"; constexpr bool MODIFIED_SINCE_COMMIT = false; constexpr bool IS_DEV_VERSION = true; constexpr bool IS_STABLE_VERSION = false; } #endif """ % (commit_id[0:7], commit_id[0:7]) with open("/dev/null", 'w') as devnull: subprocess.check_call([ sys.executable, "-m", "gitversionbuilder", "--lang", "cpp", "--dir", git.dir, out_file ], stdout=devnull) self.assertCodeEqual(expected, self.read_file(out_file))
def test_tagged_git_with_commits_after_tag(self): with GitDir() as git, TempFile() as out_file: git.create_git_commit() git.create_git_tag("1.0.1") commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "1.0.1.dev1+rev%s" GIT_TAG_NAME = "1.0.1" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False VERSION_COMPONENTS = ["1", "0", "1"] VERSION_TAG = "" """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_empty_git_cpp(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ // --------------------------------------------------- // This file is autogenerated by git-version. // DO NOT MODIFY! // --------------------------------------------------- #pragma once #ifndef MESSMER_GITVERSION_VERSION_H #define MESSMER_GITVERSION_VERSION_H namespace version { constexpr const char *VERSION_STRING = "dev1+rev%s"; constexpr const char *GIT_TAG_NAME = "master"; constexpr const unsigned int GIT_COMMITS_SINCE_TAG = 1; constexpr const char *GIT_COMMIT_ID = "%s"; constexpr bool MODIFIED_SINCE_COMMIT = false; constexpr bool IS_DEV_VERSION = true; constexpr bool IS_STABLE_VERSION = false; } #endif """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="cpp") self.assertCodeEqual(expected, self.read_file(out_file))
def test_tagged_git_with_different_tagname_scheme(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() git.create_git_tag("versionone") expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "versionone" GIT_TAG_NAME = "versionone" GIT_COMMITS_SINCE_TAG = 0 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = False """ % commit_id[0:7] main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_empty_git_python(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "dev1+rev%s" GIT_TAG_NAME = "master" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))