Commit 157821d2 authored by Nicolas Michon's avatar Nicolas Michon

Merge branch 'dev/parallel_tests' into 'master'

Add JUnit XML generation option

See merge request !1
parents 8f5e72c3 9aa1d439
Pipeline #886 passed with stage
in 0 seconds
...@@ -85,6 +85,8 @@ CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot); ...@@ -85,6 +85,8 @@ CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot);
void CU_automated_enable_junit_xml(CU_BOOL bFlag); void CU_automated_enable_junit_xml(CU_BOOL bFlag);
void CU_automated_enable_partial_junit(CU_BOOL bFlag);
void CU_automated_package_name_set(const char *pName); void CU_automated_package_name_set(const char *pName);
const char *CU_automated_package_name_get(void); const char *CU_automated_package_name_get(void);
......
...@@ -75,9 +75,12 @@ static char f_szTestListFileName[MAX_FILENAME_LENGTH] = ""; /**< Current ...@@ -75,9 +75,12 @@ static char f_szTestListFileName[MAX_FILENAME_LENGTH] = ""; /**< Current
static char f_szTestResultFileName[MAX_FILENAME_LENGTH] = ""; /**< Current output file name for the test results file. */ static char f_szTestResultFileName[MAX_FILENAME_LENGTH] = ""; /**< Current output file name for the test results file. */
static FILE* f_pTestResultFile = NULL; /**< FILE pointer the test results file. */ static FILE* f_pTestResultFile = NULL; /**< FILE pointer the test results file. */
static CU_BOOL f_bWriting_BCUNIT_RUN_SUITE = CU_FALSE; /**< Flag for keeping track of when a closing xml tag is required. */ static CU_BOOL f_bWriting_BCUNIT_RUN_SUITE = CU_FALSE; /**< Flag for keeping track of when a closing xml tag is required. */
static CU_BOOL bJUnitXmlOutput = CU_FALSE; /**< Flag for toggling the xml junit output or keeping the original. Off is the default */ static CU_BOOL bJUnitXmlOutput = CU_FALSE; /**< Flag for toggling the xml junit output or keeping the original. Off is the default */
static CU_BOOL bPartialSuiteJUnitReport = CU_FALSE; /** Flag for toggling englobing <testsuites> tags. Warning: allows imcomplete JUnit results file where only <testsuite></testsuite> will be present. This is to allow JUnit-xml output for a single suite */
static char _gPackageName[50] = ""; static char _gPackageName[50] = "";
static time_t f_testStartTime = 0; /**< Start time of current running test suite. */ static time_t f_testStartTime = 0; /**< Start time of current running test suite. */
...@@ -235,9 +238,11 @@ static CU_ErrorCode initialize_result_file(const char* szFilename) ...@@ -235,9 +238,11 @@ static CU_ErrorCode initialize_result_file(const char* szFilename)
setvbuf(f_pTestResultFile, NULL, _IONBF, 0); setvbuf(f_pTestResultFile, NULL, _IONBF, 0);
if (bJUnitXmlOutput == CU_TRUE) { if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile, if (bPartialSuiteJUnitReport == CU_FALSE) {
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" fprintf(f_pTestResultFile,
"<testsuites> \n"); "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<testsuites> \n");
}
} else { } else {
fprintf(f_pTestResultFile, fprintf(f_pTestResultFile,
"<?xml version=\"1.0\" ?> \n" "<?xml version=\"1.0\" ?> \n"
...@@ -641,17 +646,20 @@ static CU_ErrorCode uninitialize_result_file(void) ...@@ -641,17 +646,20 @@ static CU_ErrorCode uninitialize_result_file(void)
time(&tTime); time(&tTime);
szTime = ctime(&tTime); szTime = ctime(&tTime);
if (szTime) szTime[24] = '\0'; if (szTime) szTime[24] = '\0';
if (bJUnitXmlOutput == CU_TRUE) { if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile, fprintf(f_pTestResultFile,
" </testsuite>\n</testsuites>\n"); " </testsuite>\n");
} if (bPartialSuiteJUnitReport == CU_FALSE) {
else { fprintf(f_pTestResultFile, "</testsuites>\n");
fprintf(f_pTestResultFile, }
" <BCUNIT_FOOTER> %s" CU_VERSION " - %s </BCUNIT_FOOTER> \n" }
"</BCUNIT_TEST_RUN_REPORT>\n", else {
_("File Generated By BCUnit v"), fprintf(f_pTestResultFile,
(NULL != szTime) ? szTime : ""); " <BCUNIT_FOOTER> %s" CU_VERSION " - %s </BCUNIT_FOOTER> \n"
} "</BCUNIT_TEST_RUN_REPORT>\n",
_("File Generated By BCUnit v"),
(NULL != szTime) ? szTime : "");
}
if (0 != fclose(f_pTestResultFile)) { if (0 != fclose(f_pTestResultFile)) {
CU_set_error(CUE_FCLOSE_FAILED); CU_set_error(CUE_FCLOSE_FAILED);
...@@ -790,6 +798,15 @@ void CU_automated_enable_junit_xml(CU_BOOL bFlag) ...@@ -790,6 +798,15 @@ void CU_automated_enable_junit_xml(CU_BOOL bFlag)
} }
/** @} */ /** @} */
/*------------------------------------------------------------------------*/
/** Enable or Disable the englobing XML tags for <testsuites> in the JUnit file report
* This allows to create partial JUnit results file that will need to be merged.
*/
void CU_automated_enable_partial_junit(CU_BOOL bFlag)
{
bPartialSuiteJUnitReport = bFlag;
}
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** Set tests suites package name /** Set tests suites package name
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment