17

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

4

3 回答 3

4

libgtest或库的源代码libgtest_main不包含允许识别其版本(类似GetGTestVersion ()或其他)的特殊功能。头文件也没有任何定义的标识符(类似GTEST_VERSION或其他)。因此,您无法Google C++ Testing Framework在运行时检查用户代码中的版本。

但是维护者提供了作为框架的一部分的特殊脚本scripts/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

注意

该脚本在配置期间通过configure.acgtest-config中声明的变量获取框架的实际版本。

...
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中,并且在编译时可供用户使用。

于 2014-08-16T12:55:34.190 回答
2

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

于 2013-05-15T03:12:34.100 回答
0

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

在我的例子中,提交哈希是 ec44c6c1675c25b9827aacd08c02433cccde7780,结果对应于 release-1.8.0。

于 2019-06-18T16:46:19.743 回答