Commit 9aa1d439 authored by Nicolas Michon's avatar Nicolas Michon

Add JUnit XML generation option

parent 8f5e72c3
......@@ -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_partial_junit(CU_BOOL bFlag);
void CU_automated_package_name_set(const char *pName);
const char *CU_automated_package_name_get(void);
......
......@@ -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 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 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 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)
setvbuf(f_pTestResultFile, NULL, _IONBF, 0);
if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<testsuites> \n");
if (bPartialSuiteJUnitReport == CU_FALSE) {
fprintf(f_pTestResultFile,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<testsuites> \n");
}
} else {
fprintf(f_pTestResultFile,
"<?xml version=\"1.0\" ?> \n"
......@@ -641,17 +646,20 @@ static CU_ErrorCode uninitialize_result_file(void)
time(&tTime);
szTime = ctime(&tTime);
if (szTime) szTime[24] = '\0';
if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile,
" </testsuite>\n</testsuites>\n");
}
else {
fprintf(f_pTestResultFile,
" <BCUNIT_FOOTER> %s" CU_VERSION " - %s </BCUNIT_FOOTER> \n"
"</BCUNIT_TEST_RUN_REPORT>\n",
_("File Generated By BCUnit v"),
(NULL != szTime) ? szTime : "");
}
if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile,
" </testsuite>\n");
if (bPartialSuiteJUnitReport == CU_FALSE) {
fprintf(f_pTestResultFile, "</testsuites>\n");
}
}
else {
fprintf(f_pTestResultFile,
" <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)) {
CU_set_error(CUE_FCLOSE_FAILED);
......@@ -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
*/
......
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