Merge pull request #590 from abrogley/unit-test-return-code

Unit test exit code
This commit is contained in:
Alex Lin 2018-04-12 08:47:44 -05:00 committed by GitHub
commit 2db059679b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -53,6 +53,9 @@ namespace Trick {
/** Create test xml output.\n*/
bool enabled ; /**< trick_units(--) */
/** Send the unit test exit code up the chain to Executive.\n*/
bool exit_code_enabled ; /**< trick_units(--) */
/** Name of Unit test\n*/
std::string name ;
@ -77,6 +80,12 @@ namespace Trick {
*/
bool enable() ;
/**
@brief Enable/Disable exit code return feature.
@return always 0
*/
int set_exit_code_enabled( bool in_enable ) ;
/**
@brief Output message to the file.
*/
@ -96,6 +105,10 @@ namespace Trick {
*/
int set_file_name(std::string in_name) ;
/**
@brief Write output to xml file.
@return always 0
*/
int write_output() ;
} ;

View File

@ -3,6 +3,7 @@
#include <fstream>
#include "trick/UnitTest.hh"
#include "trick/exec_proto.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
@ -55,6 +56,7 @@ void Trick::TestSuite::delete_test_results() {
Trick::UnitTest::UnitTest() {
the_unit_test_output = this ;
enabled = false ;
exit_code_enabled = false ;
file_name = std::string("test_details.xml") ;
name = std::string("AllTests") ;
}
@ -93,6 +95,11 @@ bool Trick::UnitTest::enable() {
return(true) ;
}
int Trick::UnitTest::set_exit_code_enabled(bool in_enable) {
exit_code_enabled = in_enable ;
return 0 ;
}
int Trick::UnitTest::set_test_name(std::string in_name) {
name = in_name ;
return 0 ;
@ -149,6 +156,10 @@ int Trick::UnitTest::write_output() {
out << " </testsuite>" << std::endl ;
}
out << "</testsuites>" << std::endl ;
if ( exit_code_enabled && num_failures > 0 ) {
exec_terminate_with_return( 1 , __FILE__ , __LINE__ , "Unit Test failure detected." ) ;
}
}
return(0) ;