C++ 集成';谷歌测试&x27;和';增强程序选项';
我有一个程序,它使用谷歌测试和boost程序选项库来解析选项。 问题是谷歌测试也有自己的选项解析器,所以我需要在给谷歌测试提供选项之前过滤掉 例如,当我运行hello时,我使用如下C++ 集成';谷歌测试&x27;和';增强程序选项';,c++,boost,boost-program-options,googletest,C++,Boost,Boost Program Options,Googletest,我有一个程序,它使用谷歌测试和boost程序选项库来解析选项。 问题是谷歌测试也有自己的选项解析器,所以我需要在给谷歌测试提供选项之前过滤掉 例如,当我运行hello时,我使用如下 hello --option1=X --gtest_filter=Footest.* --option1是我在将--gtest_过滤器选项传递到google测试之前使用的选项 当我运行下面的代码时,我得到了异常,因为--gtest_filter不是我用于boost程序选项的选项。如何组合boost程序选项无法识别的
hello --option1=X --gtest_filter=Footest.*
--option1是我在将--gtest_过滤器选项传递到google测试之前使用的选项
当我运行下面的代码时,我得到了异常,因为--gtest_filter
不是我用于boost程序选项的选项。如何组合boost程序选项无法识别的选项以提供gtest的输入
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <fstream>
#include <iterator>
using namespace std;
#include <gtest/gtest.h>
int main(int argc, char **argv) {
// filter out the options so that only the google related options survive
try {
int opt;
string config_file;
po::options_description generic("Generic options");
generic.add_options()
("option1,o", "print version string")
;
...
}
catch(exception& e) // *****************
{
cout << e.what() << "\n";
return 1;
}
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#包括
名称空间po=boost::program\u选项;
#包括
#包括
#包括
使用名称空间std;
#包括
int main(int argc,字符**argv){
//过滤掉这些选项,这样只有与谷歌相关的选项才能保留下来
试一试{
int-opt;
字符串配置文件;
po::选项\描述通用(“通用选项”);
generic.add_options()
(“选项1,o”,“打印版本字符串”)
;
...
}
捕获(例外和e)//*****************
{
cout我在这个页面中找到了一个忽略未知选项的选项-
InitGoogleTest
谷歌测试知道的选项,剩下的留在argv
argc
中的选项也会相应调整。只需在其他选项解析代码之前调用InitGoogleTest
。这是正确的响应,应该被接受为最佳答案。
store(po::command_line_parser(argc, argv).
options(cmdline_options).positional(p).allow_unregistered().run(), vm);