建立gtest版本

Establish gtest version

本文关键字:版本 gtest 建立      更新时间:2023-10-16

我如何知道我正在处理的项目中使用的是Gtest的哪个版本?我在linux平台上工作。

libgtestlibgtest_main库的源代码不包含允许识别其版本的特殊函数(类似于GetGTestVersion ()或其他)。头文件也没有任何定义的标识符(比如GTEST_VERSION或其他什么)。所以您不能在运行时在用户代码中检查Google C++ Testing Framework的版本。

但是,作为框架的一部分,维护人员提供了特殊的脚本/gtest-conf,它是:

...
provides access to the necessary compile and linking
flags to connect with Google C++ Testing Framework, both in a build prior to
installation, and on the system proper after installation.
...

除其他外,这个脚本有几个与版本相关的选项:

...
Installation Queries:
...
--version the version of the Google Test installation
Version Queries:
--min-version=VERSION return 0 if the version is at least VERSION
--exact-version=VERSION return 0 if the version is exactly VERSION
--max-version=VERSION return 0 if the version is at most VERSION
...

该脚本还包含它的用法示例:

Examples:
gtest-config --min-version=1.0 || echo "Insufficient Google Test version."
...

这意味着用户可以使用脚本gtest-config在构建时测试框架的版本。

注意

脚本gtest-config在配置期间通过config.ac.中声明的变量获得框架的实际版本

...
AC_INIT([Google C++ Testing Framework],
        [1.7.0],
        [googletestframework@googlegroups.com],
        [gtest])
...

在调用autoconf之后,填充了configure文件中的以下标识符:

...
# Identity of this package.
PACKAGE_NAME='Google C++ Testing Framework'
PACKAGE_TARNAME='gtest'
PACKAGE_VERSION='1.7.0'
PACKAGE_STRING='Google C++ Testing Framework 1.7.0'
PACKAGE_BUGREPORT='googletestframework@googlegroups.com'
PACKAGE_URL=''
...
# Define the identity of the package.
PACKAGE='gtest'
VERSION='1.7.0'
...

到目前为止,使用选项AC_CONFIG_HEADERS编译的框架将该标识符存储在文件build-aux/config.h中,并在编译时可供用户使用。

gtest主目录中的文件CHANGES包含gtest版本号。

如果您已经克隆了官方repo,您可以在Google Test的目录中检查最新的Git提交(例如使用git log -n 1git rev-parse HEAD),并将其与发布版本列表进行比较。

在我的案例中,提交哈希是ec44c6c1675c25b9827aacd08c02433cccde7780,它对应于版本1.8.0。