66
77#include " fuzzApp.hpp"
88#include < algorithm>
9+ #include < iostream>
910
1011namespace CLI {
1112/*
@@ -151,7 +152,27 @@ std::shared_ptr<CLI::App> FuzzApp::generateApp() {
151152 return fApp ;
152153}
153154
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 {
155176 if (val32 != other.val32 ) {
156177 return false ;
157178 }
@@ -291,6 +312,20 @@ bool FuzzApp::compare(const FuzzApp &other) const {
291312 std::vector<std::string> res = vstrD;
292313 std::reverse (res.begin (), res.end ());
293314 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+ }
294329 return false ;
295330 }
296331 }
@@ -311,17 +346,28 @@ bool FuzzApp::compare(const FuzzApp &other) const {
311346 return false ;
312347 }
313348 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+ }
316360 }
317361 }
318362 // now test custom vector_options
319363 if (custom_vector_options.size () != other.custom_vector_options .size ()) {
320364 return false ;
321365 }
322366 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+ }
325371 }
326372 }
327373 return true ;
@@ -447,11 +493,17 @@ std::size_t FuzzApp::add_custom_options(CLI::App *app, const std::string &descri
447493 break ;
448494 }
449495 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 );
452498 if (header_close > current_index + 19 ) {
453499 std::string attributes = description_string.substr (current_index + 8 , header_close - 8 - current_index);
454500 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+ }
455507 }
456508
457509 current_index = end_option + 9 ;
@@ -465,12 +517,18 @@ std::size_t FuzzApp::add_custom_options(CLI::App *app, const std::string &descri
465517 break ;
466518 }
467519 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 );
470522
471523 if (header_close > current_index + 17 ) {
472524 std::string attributes = description_string.substr (current_index + 6 , header_close - 6 - current_index);
473525 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+ }
474532 }
475533 current_index = end_option + 7 ;
476534 } 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
483541 break ;
484542 }
485543 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 );
488547 if (header_close > current_index + 19 ) {
489548 std::string attributes = description_string.substr (current_index + 8 , header_close - 8 - current_index);
490549 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+ }
491556 }
492557 current_index = end_option + 9 ;
493558 } else {
0 commit comments