-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JUnit XML support #337
base: master
Are you sure you want to change the base?
Conversation
* Added an srunner_set_xml_format function and also an CK_XML_FORMAT_NAME environment variable to select JUnit formatting * Test timings are not supported at this time * Add tests to cover new functionality * Update documentation The implementation was inspired by Glenn Washburn's original patches. references - Original Patches - https://sourceforge.net/p/check/mailman/message/2963561/
My CircleCI job for a pet project is using the patched version of check based on these changes. You can see the results files on any given build in https://app.circleci.com/pipelines/github/trevershick/wpp under the tests tab ( a recent build: https://app.circleci.com/pipelines/github/trevershick/wpp/48/workflows/8d0d5d1a-8fc2-4eac-95aa-bae3f84435a5/jobs/48/tests ). I can't guarantee that build will be there when you look though. |
@mikkoi Any tips for getting a maintainer to run the workflows? I'd like to contribute more. |
Hm. I did not realize that the tests would not run automatically for first-time collaborators. That must be a recent change: On another PR I saw this week there was a "run workflow" button I could click to start the workflows. However, on this PR there is no such button. Does the branch need to be up-to-date with the |
Thanks for looking at this @brarcher . I've brought the PR up to date with |
Ah, that was is, thanks. The test workflows did run, though a number of them hit test failures. The tests are passing on the master branch, so I don't believe the test failures are pre-existing. |
doc/check.texi
Outdated
@@ -2048,6 +2052,59 @@ If both plain text and XML log files are specified, by any of above methods, | |||
then check will log to both files. In other words logging in plain text and XML | |||
format simultaneously is supported. | |||
|
|||
JUnit Support is also available. It is enabled by a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it "JUnit support" or "JUnit XML support" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 2e7563c
doc/check.texi
Outdated
@@ -2048,6 +2052,59 @@ If both plain text and XML log files are specified, by any of above methods, | |||
then check will log to both files. In other words logging in plain text and XML | |||
format simultaneously is supported. | |||
|
|||
JUnit Support is also available. It is enabled by a call to | |||
@code{srunner_set_xml_format(CK_XML_FORMAT_JUNIT)} before the tests are run. | |||
It can also be enabled by environment variable as well. It is enabled by setting the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could combine two sentences this way:
It can also be enabled by setting the environment varaible @code{CK_XML_FORMAT_NAME} to @code{junit}.
Also, if a new environment variable is being added, add a reference here:
https://github.com/libcheck/check/blob/master/doc/check.texi#L2286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 2e7563c
doc/check.texi
Outdated
It can also be enabled by environment variable as well. It is enabled by setting the | ||
@code{CK_XML_FORMAT_NAME} environment variable to @code{junit}. | ||
|
||
Here is an example of the JUnit xml format: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xml -> XML
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 2e7563c
* enum describing the specific XML format used for XML logging | ||
*/ | ||
enum xml_format { | ||
CK_XML_FORMAT_UNSPECIFIED, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the unspecified state be the default state? What is the motivation for having an unspecified state? And, if it were unspecified what XML stlye ends up being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CK_XML_FORMAT_UNSPECIFIED
is the default value when srunner_create
is called. This is in fact what I was missing and why my tests were failing.
srunner_xml_format
is used to determine what format to use.
srunner_xml_format
will never yield CK_XML_FORMAT_UNSPECIFIED
, it will yield only CK_XML_FORMAT_DEFAULT
or CK_XML_FORMAT_JUNIT
.
The motivation for the unspecified state is that I needed an initial state which was unspecified since the environment variable to set the format only overrides the selected format if it's unspecified. If it were set to 'default', then I couldn't tell if someone had set it explicitly or not.
* This value can be explicitly set via `srunner_set_xml_format` or can | ||
* be set via the CK_XML_FORMAT_NAME environment variable. | ||
* | ||
* @return CK_XML_FORMAT_DEFAULT unless the format is explicitly set via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If another XML style were introduced in the future, the docs here would need to be updated to remove the JUNIT reference (as there would be other possibilities).
Perhaps mention how the environment variable and value set in the code interact instead, so that is more clear. For example, mention that if the environment variable is set then its value is used, otherwise whatever is set in srunner_set_xml_format is used, and the default is CK_XML_FORMAT_DEFAULT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 2e7563c
|
||
// junit is the only value of CK_XML_FORMAT_NAME that will | ||
// return something other than CK_XML_FORMAT_DEFAULT | ||
const char *format_name = getenv("CK_XML_FORMAT_NAME"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in other places in the code the environment variable takes precedence. Example:
https://github.com/libcheck/check/blob/master/src/check.c#L317
Should that be the case here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's logging, I made the precedence the same as srunner_xml_fname
. This seems sane to me even if it's different than other items. These two should at least agree probably.
src/check_impl.h
Outdated
@@ -121,6 +122,7 @@ struct SRunner | |||
List *resultlst; /* List of unit test results */ | |||
const char *log_fname; /* name of log file */ | |||
const char *xml_fname; /* name of xml output file */ | |||
enum xml_format xml_format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are comments on the other fields, maybe add one for this field too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 2e7563c
src/check_print.c
Outdated
enum print_output print_mode CK_ATTRIBUTE_UNUSED) | ||
{ | ||
char status[10]; | ||
char type[10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see type used in the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type was removed in f6d5589
Got a linux box up and going - got a clean test run:
|
* JUnit Support -> JUnit XML Support * Combine two sentences in check.texi * xml->XML * Add a line in the environment appendix * Update the xml_format source code header comment * Add a comment to xml_format
I just noticed this is still open. I believe I addressed most comments. There are a couple where I attempted to explain my reasoning. |
The implementation was inspired by Glenn Washburn's original patches.
references -
Original Patches - https://sourceforge.net/p/check/mailman/message/2963561/
Issue #334