Google テストを使用するプログラムがあり、オプションを解析するためにプログラム オプション ライブラリをブーストします。問題は、Google テストにも独自のオプション パーサーがあるため、Google テストにオプションを与える前に除外する必要があることです。
たとえば、hello を実行するときは、次のように使用します
hello --option1=X --gtest_filter=Footest.*
--option1 は、 --gtest_filter オプションを Google テストに渡す前に使用するオプションです。
次のコードを実行すると--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();
}