From 0709e00d96ff22ce2d716847440d7671ea1af867 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 20:59:27 +0800 Subject: [PATCH] update: add default value for metadata --- src/klotski_core/CMakeLists.txt | 16 +++++++++++++--- test/ffi/metadata.cc | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/klotski_core/CMakeLists.txt b/src/klotski_core/CMakeLists.txt index 56adcb1..269c95d 100644 --- a/src/klotski_core/CMakeLists.txt +++ b/src/klotski_core/CMakeLists.txt @@ -51,13 +51,23 @@ endmacro() ################################################################################ -set(GIT_BRANCH "") set(GIT_TAG_LONG "") -set(GIT_COMMIT_LONG "") - git_tag(GIT_TAG_LONG) +if(GIT_TAG_LONG STREQUAL "") # without git tag + set(GIT_TAG_LONG "unknown") +endif() + +set(GIT_BRANCH "") git_branch(GIT_BRANCH) +if(GIT_BRANCH STREQUAL "") # without git branch + set(GIT_BRANCH "unknown") +endif() + +set(GIT_COMMIT_LONG "") git_commit_id(GIT_COMMIT_LONG) +if(GIT_COMMIT_LONG STREQUAL "") # without git commit + set(GIT_COMMIT_LONG "unknown") +endif() set(PLAT "${CMAKE_SYSTEM_NAME}") set(ARCH "${CMAKE_SYSTEM_PROCESSOR}") diff --git a/test/ffi/metadata.cc b/test/ffi/metadata.cc index 346123b..b241559 100644 --- a/test/ffi/metadata.cc +++ b/test/ffi/metadata.cc @@ -3,6 +3,16 @@ #include "gtest/gtest.h" TEST(FFI, metadata) { + EXPECT_STRNE(get_author(), ""); + EXPECT_STRNE(get_git_tag(), ""); + EXPECT_STRNE(get_version(), ""); + EXPECT_STRNE(get_commit_id(), ""); + EXPECT_STRNE(get_build_time(), ""); + EXPECT_STRNE(get_git_branch(), ""); + EXPECT_STRNE(get_project_url(), ""); + EXPECT_STRNE(get_system_info(), ""); + EXPECT_STRNE(get_compiler_info(), ""); + EXPECT_STREQ(get_author(), AUTHOR); EXPECT_STREQ(get_git_tag(), GIT_TAG_ID); EXPECT_STREQ(get_version(), VERSION_STR);