Add separate - non BOOST - test program to test exit(1)
This commit is contained in:
@@ -215,6 +215,7 @@ if(ENABLE_ECL_INPUT)
|
||||
tests/parser/MULTREGTScannerTests.cpp
|
||||
tests/parser/OrderedMapTests.cpp
|
||||
tests/parser/ParseContextTests.cpp
|
||||
tests/parser/ParseContext_EXIT1.cpp
|
||||
tests/parser/PORVTests.cpp
|
||||
tests/parser/RawKeywordTests.cpp
|
||||
tests/parser/RestartConfigTests.cpp
|
||||
|
||||
@@ -749,15 +749,6 @@ BOOST_AUTO_TEST_CASE( test_invalid_wtemplate_config ) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Test_EXIT1) {
|
||||
/*
|
||||
The error handler EXIT1 is not tested at all. The reason is that testing that
|
||||
would require the setup of an extra process and then check the exit status of
|
||||
the extra process - that kind of feelt a bit over the top.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
If there are errors the ErrorGuard destructor will print error messages and
|
||||
call std::terminate(); if you do not accept the std::terminate in the
|
||||
|
||||
51
tests/parser/ParseContext_EXIT1.cpp
Normal file
51
tests/parser/ParseContext_EXIT1.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
|
||||
|
||||
void exit1() {
|
||||
const char * deckString =
|
||||
"RUNSPEC\n"
|
||||
"DIMENS\n"
|
||||
" 10 10 10 10 /n"
|
||||
"\n";
|
||||
|
||||
Opm::ParseContext parseContext;
|
||||
Opm::Parser parser;
|
||||
Opm::ErrorGuard errors;
|
||||
|
||||
parseContext.update(Opm::ParseContext::PARSE_EXTRA_DATA , Opm::InputError::EXIT1 );
|
||||
parser.parseString( deckString , parseContext, errors );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
This test checks that the application will exit with status 1 - if that is
|
||||
requested; since the boost test framework has registered atexit() handlers
|
||||
which will unconditionally fail the complete test in the face of an exit(1) -
|
||||
this test is implemented without the BOOST testing framework.
|
||||
*/
|
||||
|
||||
int main() {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
exit1();
|
||||
|
||||
int wait_status;
|
||||
waitpid(pid, &wait_status, 0);
|
||||
|
||||
if (WIFEXITED(wait_status))
|
||||
/*
|
||||
We *want* the child process to terminate with status exit(1), here we
|
||||
capture the exit status of the child process, and then we invert that
|
||||
and return the inverted status as the status of the complete test.
|
||||
*/
|
||||
std::exit( !WEXITSTATUS(wait_status) );
|
||||
else
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
Reference in New Issue
Block a user