@@ -52,9 +52,11 @@ void SetupArgs(ArgsManager& local_args, const std::vector<std::pair<std::string,
5252// functions. The GetSetting method can always be used instead of GetArg
5353// methods to retrieve original values, and there's not always an objective
5454// answer to what GetArg behavior is best in every case. This test makes sure
55- // there's test coverage for whatever the current behavior is, so it's not
56- // broken or changed unintentionally.
57- BOOST_AUTO_TEST_CASE (setting_args)
55+ // there's test coverage for the current behavior with ALLOW_ANY flag, so
56+ // it's not broken or changed unintentionally. Additional test cases with
57+ // flags other than ALLOW_ANY can be found in the setting_arg_allow_types
58+ // test below.
59+ BOOST_AUTO_TEST_CASE (setting_args_allow_any)
5860{
5961 ArgsManager args;
6062 SetupArgs (args, {{" -foo" , ArgsManager::ALLOW_ANY}});
@@ -157,6 +159,62 @@ BOOST_AUTO_TEST_CASE(setting_args)
157159 BOOST_CHECK_EQUAL (args.GetBoolArg (" foo" , false ), false );
158160}
159161
162+ // Test behavior of GetArg functions with a settings.json file when
163+ // ALLOW_BOOL and ALLOW_INT flags are specified, in contrast to
164+ // setting_args_allow_any test above, which tests legacy behavior with the
165+ // ALLOW_ANY flag.
166+ //
167+ // Currently, the ReadSettingsFile() function ignores type flags and just copies
168+ // JSON values in the file directly into the Settings::rw_settings map without
169+ // converting the values to types specified by the flags, or returning errors if
170+ // the values were invalid and couldn't be converted. In the future it would be
171+ // nice to improve ReadSettingsFile() to use the flags so the parsing could be
172+ // more robust and return errors if problems were detected. This test could be
173+ // extended in that case.
174+ BOOST_AUTO_TEST_CASE (setting_args_allow_types)
175+ {
176+ {
177+ ArgsManager args;
178+ args.LockSettings ([&](common::Settings& settings) {
179+ settings.rw_settings [" boolarg1" ] = true ;
180+ settings.rw_settings [" boolarg2" ] = false ;
181+ });
182+ args.ForceSetArg (" -datadir" , fs::PathToString (m_path_root));
183+ BOOST_CHECK (args.WriteSettingsFile ());
184+ }
185+
186+ {
187+ ArgsManager args;
188+ args.ForceSetArg (" -datadir" , fs::PathToString (m_path_root));
189+ BOOST_CHECK (args.ReadSettingsFile ());
190+
191+ BOOST_CHECK_EQUAL (args.GetSetting (" -boolarg1" ).write (), " true" );
192+ BOOST_CHECK_EQUAL (args.GetSetting (" -boolarg2" ).write (), " false" );
193+ }
194+
195+ {
196+ ArgsManager args;
197+ args.AddArg (" -boolarg1" , " " , ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
198+ args.AddArg (" -boolarg2" , " " , ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
199+ args.ForceSetArg (" -datadir" , fs::PathToString (m_path_root));
200+ BOOST_CHECK (args.ReadSettingsFile ());
201+
202+ BOOST_CHECK_EQUAL (args.GetBoolArg (" -boolarg1" ).value (), true );
203+ BOOST_CHECK_EQUAL (args.GetBoolArg (" -boolarg2" ).value (), false );
204+ }
205+
206+ {
207+ ArgsManager args;
208+ args.AddArg (" -boolarg1" , " " , ArgsManager::ALLOW_INT, OptionsCategory::OPTIONS);
209+ args.AddArg (" -boolarg2" , " " , ArgsManager::ALLOW_INT, OptionsCategory::OPTIONS);
210+ args.ForceSetArg (" -datadir" , fs::PathToString (m_path_root));
211+ BOOST_CHECK (args.ReadSettingsFile ());
212+
213+ BOOST_CHECK_EQUAL (args.GetIntArg (" -boolarg1" ).value (), 1 );
214+ BOOST_CHECK_EQUAL (args.GetIntArg (" -boolarg2" ).value (), 0 );
215+ }
216+ }
217+
160218BOOST_AUTO_TEST_CASE (boolarg)
161219{
162220 ArgsManager local_args;
0 commit comments