【发布时间】:2011-02-17 19:01:01
【问题描述】:
我有一个使用 google test 的程序,以及用于解析选项的 boost 程序选项库。 问题是谷歌测试也有它自己的选项解析器,所以我需要在将选项提供给谷歌测试之前过滤掉。
例如,当我运行你好时,我使用如下
hello --option1=X --gtest_filter=Footest.*
--option1 是我在将 --gtest_filter 选项传递给 google 测试之前使用的选项。
当我运行以下代码时,我得到了异常,因为 --gtest_filter 不是我用于提升程序选项的选项。如何组合那些 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();
}
【问题讨论】:
标签: c++ boost boost-program-options googletest