Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

trevershick
Copy link

  • 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/
Issue #334

Trever Shick added 2 commits September 18, 2021 20:42
* 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/
@trevershick
Copy link
Author

trevershick commented Sep 25, 2021

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.

Screen Shot 2021-09-24 at 9 13 27 PM

@trevershick
Copy link
Author

trevershick commented Sep 25, 2021

@mikkoi Any tips for getting a maintainer to run the workflows? I'd like to contribute more.

@brarcher
Copy link
Contributor

Hm. I did not realize that the tests would not run automatically for first-time collaborators. That must be a recent change:
https://github.blog/changelog/2021-04-22-github-actions-maintainers-must-approve-first-time-contributor-workflow-runs/

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 master branch to have the option to run the workflow? The docs do not mention this as a requirement:

https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks

@trevershick
Copy link
Author

Thanks for looking at this @brarcher . I've brought the PR up to date with master, perhaps this will allow the workflows to be run.

@brarcher
Copy link
Contributor

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
Copy link
Contributor

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" ?

Copy link
Author

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
Copy link
Contributor

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

Copy link
Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xml -> XML

Copy link
Author

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,
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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");
Copy link
Contributor

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?

Copy link
Author

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;
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 2e7563c

enum print_output print_mode CK_ATTRIBUTE_UNUSED)
{
char status[10];
char type[10];
Copy link
Contributor

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

Copy link
Author

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

@trevershick
Copy link
Author

Got a linux box up and going - got a clean test run:

$ CTEST_OUTPUT_ON_FAILURE=1 ninja -C build test
ninja: Entering directory `build'
[0/1] Running tests...
Test project /home/trevershick/workspace/check/build
    Start 1: check_check
1/9 Test #1: check_check ......................   Passed  178.07 sec
    Start 2: check_check_export
2/9 Test #2: check_check_export ...............   Passed  176.53 sec
    Start 3: test_output.sh
3/9 Test #3: test_output.sh ...................   Passed    0.11 sec
    Start 4: test_log_output.sh
4/9 Test #4: test_log_output.sh ...............   Passed    0.03 sec
    Start 5: test_xml_output.sh
5/9 Test #5: test_xml_output.sh ...............   Passed    0.09 sec
    Start 6: test_tap_output.sh
6/9 Test #6: test_tap_output.sh ...............   Passed    0.03 sec
    Start 7: test_check_nofork.sh
7/9 Test #7: test_check_nofork.sh .............   Passed    0.01 sec
    Start 8: test_check_nofork_teardown.sh
8/9 Test #8: test_check_nofork_teardown.sh ....   Passed    0.01 sec
    Start 9: test_set_max_msg_size.sh
9/9 Test #9: test_set_max_msg_size.sh .........   Passed    0.02 sec

100% tests passed, 0 tests failed out of 9

Total Test time (real) = 354.89 sec

@trevershick trevershick requested a review from brarcher October 30, 2021 00:03
Trever Shick added 2 commits October 29, 2021 19:36
* 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
@trevershick
Copy link
Author

I just noticed this is still open. I believe I addressed most comments. There are a couple where I attempted to explain my reasoning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants