我有一个使用谷歌测试的程序,以及用于解析选项的提升程序选项库。问题是谷歌测试也有它自己的选项解析器,所以我需要在将选项提供给谷歌测试之前过滤掉。
例如,当我运行 hello 我使用如下
hello --option1=X --gtest_filter=Footest.*
--option1 是我在将 --gtest_filter 选项传递给谷歌测试之前使用的选项。
当我运行以下代码时,我得到了异常,因为--gtest_filter
这不是我用于提升程序选项的选项。如何结合那些提升程序选项无法识别的选项来提供 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();
}