add tests to cover super cycle detection while validating a .cfg file

This commit is contained in:
Rafael Fillipe Silva 2023-12-20 00:37:56 -03:00 committed by Pentarctagon
parent 1c36153f06
commit 40e7dff3ad
4 changed files with 63 additions and 0 deletions

View file

@ -263,4 +263,6 @@ feature_test_WML_macro_define/macro_define_noArgument_ParseAsExpected
feature_test_WML_macro_define/macro_define_1Argument_ParseAsExpected
test_schema_self_validator/test_schema_super_self_reference
test_schema_self_validator/test_schema_super_cycle
test_schema_validator/test_super_cycle
test_schema_validator/test_super_cycle_only_if_used
test_schema_validator/test_super_cycle_crashes_on_unknown_key

View file

@ -27,6 +27,55 @@
BOOST_AUTO_TEST_SUITE( test_schema_validator )
BOOST_AUTO_TEST_CASE( test_super_cycle )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_cycle.cfg";
constexpr auto config_path = "src/tests/wml/schema/test_schema_validator/test_super_cycle.cfg";
auto validator = schema_validation::schema_validator(schema_path, false);
validator.set_create_exceptions(true);
// See: wesnoth.cpp > handle_validate_command
preproc_map defines_map;
defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
defines_map["SCHEMA_VALIDATION"] = preproc_define();
auto stream = preprocess_file(config_path, &defines_map);
config result;
BOOST_CHECK_EXCEPTION(
read(result, *stream, &validator),
wml_exception,
[] (const wml_exception& e) {
return boost::algorithm::contains(
e.dev_message,
"Inheritance cycle from other/second to main/first found"
);
}
);
}
BOOST_AUTO_TEST_CASE( test_super_cycle_only_if_used )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_cycle.cfg";
constexpr auto config_path = "src/tests/wml/schema/test_schema_validator/test_super_cycle_only_if_used.cfg";
auto validator = schema_validation::schema_validator(schema_path, false);
validator.set_create_exceptions(true);
preproc_map defines_map;
defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
defines_map["SCHEMA_VALIDATION"] = preproc_define();
auto stream = preprocess_file(config_path, &defines_map);
config result;
BOOST_CHECK_NO_THROW(read(result, *stream, &validator));
}
BOOST_AUTO_TEST_CASE( test_super_cycle_crashes_on_unknown_key )
{
constexpr auto schema_path = "src/tests/wml/schema/test_schema_validator/test_schema_super_cycle.cfg";

View file

@ -0,0 +1,10 @@
[main]
[first]
[/first]
[/main]
[other]
[second]
[/second]
[/other]
[second]
[/second]

View file

@ -0,0 +1,2 @@
[second]
[/second]