@@ -16,7 +16,6 @@ TEST_GROUP(ArgsTestGroup)
1616// clang-format on
1717
1818TEST (ArgsTestGroup, Args_BasicParse) {
19- UT_PRINT (" Args_BasicParse\r\n " );
2019 std::vector<const char *> av{" " ," --config" ," configs/basic_parse.toml" };
2120int argc = av.size ();
2221
@@ -265,6 +264,64 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
265264" {compiled_sources}" );
266265}
267266
267+ TEST (ArgsTestGroup, Args_CustomCallback) {
268+ std::vector<const char *> av{" " ,
269+ " --config" ,
270+ " configs/basic_parse.toml" ,
271+ " --random_bool" ,
272+ " true" ,
273+ " --random_string" ,
274+ " hello world" };
275+ int argc = av.size ();
276+
277+ bool random_bool{false };
278+ std::string random_string;
279+ auto &instance =buildcc::Args::Init ();
280+ instance.AddCustomCallback ([&](CLI::App &app) {
281+ app.add_option (" --random_bool" , random_bool," Random bool" );
282+ app.add_option (" --random_string" , random_string," Random string" );
283+ });
284+ instance.Parse (argc, av.data ());
285+
286+ STRCMP_EQUAL (buildcc::Args::GetProjectRootDir ().string ().c_str ()," root" );
287+ STRCMP_EQUAL (buildcc::Args::GetProjectBuildDir ().string ().c_str ()," build" );
288+ CHECK (buildcc::Args::GetLogLevel () == buildcc::env::LogLevel::Trace);
289+ CHECK_TRUE (buildcc::Args::Clean ());
290+ CHECK_TRUE (random_bool);
291+ STRCMP_EQUAL (random_string.c_str ()," hello world" );
292+ }
293+
294+ TEST (ArgsTestGroup, Args_CustomData) {
295+ struct RandomGroupedData :public buildcc ::ArgCustom {
296+ void Add (CLI::App &app)override {
297+ app.add_option (" --random_bool" , random_bool," Random bool" );
298+ app.add_option (" --random_string" , random_string," Random string" );
299+ }
300+
301+ bool random_bool{false };
302+ std::string random_string;
303+ };
304+
305+ std::vector<const char *> av{" " ,
306+ " --config" ,
307+ " configs/basic_parse.toml" ,
308+ " --random_bool" ,
309+ " true" ,
310+ " --random_string" ,
311+ " hello world" };
312+ int argc = av.size ();
313+
314+ RandomGroupedData grouped_data;
315+ buildcc::Args::Init ().AddCustomData (grouped_data).Parse (argc, av.data ());
316+
317+ STRCMP_EQUAL (buildcc::Args::GetProjectRootDir ().string ().c_str ()," root" );
318+ STRCMP_EQUAL (buildcc::Args::GetProjectBuildDir ().string ().c_str ()," build" );
319+ CHECK (buildcc::Args::GetLogLevel () == buildcc::env::LogLevel::Trace);
320+ CHECK_TRUE (buildcc::Args::Clean ());
321+ CHECK_TRUE (grouped_data.random_bool );
322+ STRCMP_EQUAL (grouped_data.random_string .c_str ()," hello world" );
323+ }
324+
268325int main (int ac,char **av) {
269326MemoryLeakWarningPlugin::destroyGlobalDetector ();
270327return CommandLineTestRunner::RunAllTests (ac, av);