6
6
7
7
#include " fuzzApp.hpp"
8
8
#include < algorithm>
9
+ #include < iostream>
9
10
10
11
namespace CLI {
11
12
/*
@@ -151,7 +152,27 @@ std::shared_ptr<CLI::App> FuzzApp::generateApp() {
151
152
return fApp ;
152
153
}
153
154
154
- bool FuzzApp::compare (const FuzzApp &other) const {
155
+ static void print_string_comparison (const std::string &s1,
156
+ const std::string &s2,
157
+ const std::string &prefix,
158
+ const std::string &s1name,
159
+ const std::string &s2name) {
160
+ for (size_t jj = 0 ; jj < (std::max)(s1.size (), s2.size ()); ++jj) {
161
+ if (jj >= s1.size ()) {
162
+ std::cout << prefix << " :" << s1name << " [" << jj << " ] = [empty], " << s2name << " [" << jj
163
+ << " ]=" << static_cast <int >(s2[jj]) << ' \n ' ;
164
+ } else if (jj >= s2.size ()) {
165
+ std::cout << prefix << " :" << s1name << " [" << jj << " ]=" << static_cast <int >(s1[jj]) << " , " << s2name
166
+ << " [" << jj << " ]=[empty] \n " ;
167
+ } else if (s1[jj] != s2[jj]) {
168
+ std::cout << " -->" << prefix << " :" << s1name << " [" << jj << " ]=" << static_cast <int >(s1[jj]) << " , "
169
+ << s2name << " [" << jj << " ]=" << static_cast <int >(s2[jj]) << ' \n ' ;
170
+ } else {
171
+ std::cout << prefix << " :" << s1name << " [" << jj << " ]=" << static_cast <int >(s1[jj]) << ' \n ' ;
172
+ }
173
+ }
174
+ }
175
+ bool FuzzApp::compare (const FuzzApp &other, bool print_error) const {
155
176
if (val32 != other.val32 ) {
156
177
return false ;
157
178
}
@@ -291,6 +312,20 @@ bool FuzzApp::compare(const FuzzApp &other) const {
291
312
std::vector<std::string> res = vstrD;
292
313
std::reverse (res.begin (), res.end ());
293
314
if (res != other.vstrD ) {
315
+ if (print_error) {
316
+ if (res.size () != other.vstrD .size ()) {
317
+ std::cout << " size is different vstrD.size()=" << res.size ()
318
+ << " other.vstrD.size=" << other.vstrD .size () << ' \n ' ;
319
+ } else {
320
+ for (size_t ii = 0 ; ii < res.size (); ++ii) {
321
+ print_string_comparison (res[ii],
322
+ other.vstrD [ii],
323
+ std::string (" string[" ) + std::to_string (ii) + ' ]' ,
324
+ " vstrD" ,
325
+ " other.vstrD" );
326
+ }
327
+ }
328
+ }
294
329
return false ;
295
330
}
296
331
}
@@ -311,17 +346,28 @@ bool FuzzApp::compare(const FuzzApp &other) const {
311
346
return false ;
312
347
}
313
348
for (std::size_t ii = 0 ; ii < custom_string_options.size (); ++ii) {
314
- if (*custom_string_options[ii] != *other.custom_string_options [ii]) {
315
- return false ;
349
+ if (custom_string_options[ii]->first != other.custom_string_options [ii]->first ) {
350
+ if (custom_string_options[ii]->second ) {
351
+ if (print_error) {
352
+ print_string_comparison (custom_string_options[ii]->first ,
353
+ other.custom_string_options [ii]->first ,
354
+ std::string (" custom_string[" ) + std::to_string (ii) + ' ]' ,
355
+ " c1" ,
356
+ " other.c1" );
357
+ }
358
+ return false ;
359
+ }
316
360
}
317
361
}
318
362
// now test custom vector_options
319
363
if (custom_vector_options.size () != other.custom_vector_options .size ()) {
320
364
return false ;
321
365
}
322
366
for (std::size_t ii = 0 ; ii < custom_vector_options.size (); ++ii) {
323
- if (*custom_vector_options[ii] != *other.custom_vector_options [ii]) {
324
- return false ;
367
+ if (custom_vector_options[ii]->first != other.custom_vector_options [ii]->first ) {
368
+ if (custom_vector_options[ii]->second ) {
369
+ return false ;
370
+ }
325
371
}
326
372
}
327
373
return true ;
@@ -447,11 +493,17 @@ std::size_t FuzzApp::add_custom_options(CLI::App *app, const std::string &descri
447
493
break ;
448
494
}
449
495
std::string name = description_string.substr (header_close + 1 , end_option - header_close - 1 );
450
- custom_string_options.push_back (std::make_shared<std::string>( ));
451
- auto *opt = app->add_option (name, *( custom_string_options.back ()) );
496
+ custom_string_options.push_back (std::make_shared<std::pair<std:: string, bool >>( " " , true ));
497
+ auto *opt = app->add_option (name, custom_string_options.back ()-> first );
452
498
if (header_close > current_index + 19 ) {
453
499
std::string attributes = description_string.substr (current_index + 8 , header_close - 8 - current_index);
454
500
modify_option (opt, attributes);
501
+ if (!opt->get_configurable ()) {
502
+ custom_string_options.back ()->second = false ;
503
+ if (opt->get_required ()) {
504
+ non_config_required = true ;
505
+ }
506
+ }
455
507
}
456
508
457
509
current_index = end_option + 9 ;
@@ -465,12 +517,18 @@ std::size_t FuzzApp::add_custom_options(CLI::App *app, const std::string &descri
465
517
break ;
466
518
}
467
519
std::string name = description_string.substr (header_close + 1 , end_option - header_close - 1 );
468
- custom_string_options.push_back (std::make_shared<std::string>( ));
469
- auto *opt = app->add_option (name, *( custom_string_options.back ()) );
520
+ custom_string_options.push_back (std::make_shared<std::pair<std:: string, bool >>( " " , true ));
521
+ auto *opt = app->add_option (name, custom_string_options.back ()-> first );
470
522
471
523
if (header_close > current_index + 17 ) {
472
524
std::string attributes = description_string.substr (current_index + 6 , header_close - 6 - current_index);
473
525
modify_option (opt, attributes);
526
+ if (!opt->get_configurable ()) {
527
+ custom_string_options.back ()->second = false ;
528
+ if (opt->get_required ()) {
529
+ non_config_required = true ;
530
+ }
531
+ }
474
532
}
475
533
current_index = end_option + 7 ;
476
534
} else if (description_string.compare (current_index, 7 , " <vector" ) == 0 ) {
@@ -483,11 +541,18 @@ std::size_t FuzzApp::add_custom_options(CLI::App *app, const std::string &descri
483
541
break ;
484
542
}
485
543
std::string name = description_string.substr (header_close + 1 , end_option - header_close - 1 );
486
- custom_vector_options.push_back (std::make_shared<std::vector<std::string>>());
487
- auto *opt = app->add_option (name, *(custom_vector_options.back ()));
544
+ custom_vector_options.push_back (std::make_shared<std::pair<std::vector<std::string>, bool >>());
545
+ custom_vector_options.back ()->second = true ;
546
+ auto *opt = app->add_option (name, custom_vector_options.back ()->first );
488
547
if (header_close > current_index + 19 ) {
489
548
std::string attributes = description_string.substr (current_index + 8 , header_close - 8 - current_index);
490
549
modify_option (opt, attributes);
550
+ if (!opt->get_configurable ()) {
551
+ custom_vector_options.back ()->second = false ;
552
+ if (opt->get_required ()) {
553
+ non_config_required = true ;
554
+ }
555
+ }
491
556
}
492
557
current_index = end_option + 9 ;
493
558
} else {
0 commit comments