diff --git a/opm/parser/eclipse/Parser/ParseContext.hpp b/opm/parser/eclipse/Parser/ParseContext.hpp index 2d1133edc..5264a7829 100644 --- a/opm/parser/eclipse/Parser/ParseContext.hpp +++ b/opm/parser/eclipse/Parser/ParseContext.hpp @@ -79,7 +79,9 @@ namespace Opm { class ParseContext { public: ParseContext(); + explicit ParseContext(InputError::Action default_action); explicit ParseContext(const std::vector>& initial); + Message::type handleError( const std::string& errorKey, MessageContainer& msgContainer, const std::string& msg ) const; bool hasKey(const std::string& key) const; ParseContext withKey(const std::string& key, InputError::Action action = InputError::WARN) const; diff --git a/src/opm/parser/eclipse/Parser/ParseContext.cpp b/src/opm/parser/eclipse/Parser/ParseContext.cpp index a07e2dec9..aefe7342e 100644 --- a/src/opm/parser/eclipse/Parser/ParseContext.cpp +++ b/src/opm/parser/eclipse/Parser/ParseContext.cpp @@ -56,6 +56,17 @@ namespace Opm { } + /* + This constructor will initialize all actions to @default_action. The + environment variables will be used. + */ + + ParseContext::ParseContext(InputError::Action default_action) { + initDefault(); + update(default_action); + initEnv(); + } + void ParseContext::initDefault() { addKey(PARSE_UNKNOWN_KEYWORD); addKey(PARSE_RANDOM_TEXT); diff --git a/tests/parser/ParseContextTests.cpp b/tests/parser/ParseContextTests.cpp index 89ccbed5a..a6373ef15 100644 --- a/tests/parser/ParseContextTests.cpp +++ b/tests/parser/ParseContextTests.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #define BOOST_TEST_MODULE ParseContextTests @@ -406,3 +407,13 @@ BOOST_AUTO_TEST_CASE( test_too_much_data ) { parseContext.update(ParseContext::PARSE_EXTRA_DATA , InputError::IGNORE ); auto deck = parser.parseString( deckString , parseContext ); } + + +BOOST_AUTO_TEST_CASE(test_1arg_constructor) { + setenv("OPM_ERRORS_IGNORE", "PARSE_RANDOM_SLASH", 1); + { + ParseContext ctx(InputError::WARN); + BOOST_CHECK_EQUAL(ctx.get(ParseContext::UNSUPPORTED_COMPORD_TYPE), InputError::WARN); + BOOST_CHECK_EQUAL(ctx.get(ParseContext::PARSE_RANDOM_SLASH), InputError::IGNORE); + } +}