-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 test tags as cmake label #2690
base: devel
Are you sure you want to change the base?
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## devel #2690 +/- ##
=======================================
Coverage 91.46% 91.46%
=======================================
Files 194 194
Lines 8188 8188
=======================================
Hits 7489 7489
Misses 699 699 |
@horenmar sorry for pinging, but could you have a look at this PR? |
I want to do #2676 first, and that waits until I have a free weekend that I can spend on it. 🤷 |
extras/CatchAddTests.cmake
Outdated
add_command(set_tests_properties | ||
"${prefix}${test}${suffix}" | ||
PROPERTIES | ||
ENVIRONMENT_MODIFICATION "${environment_modifications}") | ||
LABELS "${tags}" |
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.
IIRC this needs to APPEND
the labels property, to avoid overwriting user-provided labels for the same tests. There should be a discussion of this somewhere in #1590.
Well, I finally had time to fix the other PR and unblock this one. I also looked around various other attempts and old issues, and there is one more problem that is not handled by this, and I am not sure it can be handled with this approach, see #1658. Basically with a long test name like "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu est ut lacus luctus volutpat. Duis convallis massa non neque eleifend porta vel est.",
This will break the registration script, as it does not understand that it needs to reconstruct the two lines into one test, and in general it cannot figure this out -> if we have test cases without tags, there is no way to tell whether the two lines above are two different test cases, or one looong test case. And even if it was possible to figure this out (either a different indentation width for subsequent lines, or a line break marker), we still cannot figure out what whitespace separator is supposed to be there (in the example above, it is a space, but it could also be a tab, or even some weirder WS char). This leads me to conclude that parsing As I see it, there are two options
This is kinda brittle, but it would work, and IIRC the XML reporter output is already tested for being unchanged, so we could just make it so that the registration script needs to be updated if the XML reporter output changes.
This requires more changes to Catch2 and forces newer CMake versions. |
ok, so I guess I should open a new PR following this direction. Are you ok with requiring CMake 3.19? |
for adding a JSON reporter, I guess the most straightforward approach is to follow the XML reporter, right? or is there a specification for JSON reporter also? |
This seems reasonable and modern. But what's the plan on how to get the json parser? Presumably using library, but then would it be a hard dependency? Would it be bundled and/or use FetchContent? |
I think a custom JSON writer will be written, similar to the XML writer. |
Maybe the reporter is doable (probably already have a string sanitizer for quotations etc.), but the parser sounds like could be a bit tricky. |
I don't think we need a JSON parser in Catch2 code, we only need to use the CMake JSON parser for parsing the tests and tags. |
Oh yeah, I misread the previous comment, only the reporter is needed. Isn't there a widely used json format for test-suite data junit? I've recently seen that github action is annotating warnings and some errors directly in the code source. Maybe if there's a format that github action can pick up, it would be nice to have these tests reported in source as well. |
Hi @uyha, thanks for working on this. Do you have plans to complete this feature? The Catch2+CTest community would thank you :) |
4d71b1e
to
53968c9
Compare
This allows people running `cmake -L 'tag'` to run tests matching the tags
foreach(tag_index RANGE "${tag_end}") | ||
string(JSON tag GET "${tags}" "${tag_index}") | ||
add_command(set_tests_properties | ||
"${prefix}${test}${suffix}" | ||
PROPERTIES | ||
LABELS "${tags}" | ||
) | ||
endforeach() |
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 am not sure why, but this does not do what it is supposed to. The resulting ctest script looks like this:
add_test( [==[And now a test case with weird tags.]==] /home/xarn/builds/Catch2/uyha-json-reporter/tests/ctest-registration-test/tests [==[And now a test case with weird tags.]==] )
set_tests_properties( [==[And now a test case with weird tags.]==] PROPERTIES WORKING_DIRECTORY /home/xarn/builds/Catch2/uyha-json-reporter/tests/ctest-registration-test)
set_tests_properties( [==[And now a test case with weird tags.]==] PROPERTIES LABELS [==[[ "foo,bar", "tl;dr", "tl;dw" ]]==])
set_tests_properties( [==[And now a test case with weird tags.]==] PROPERTIES LABELS [==[[ "foo,bar", "tl;dr", "tl;dw" ]]==])
set_tests_properties( [==[And now a test case with weird tags.]==] PROPERTIES LABELS [==[[ "foo,bar", "tl;dr", "tl;dw" ]]==])
Which has the obvious issue of setting the same set of labels multiple times, but also it should set each tag as its own label, rather than the amalgamation of all tags as one big label.
Also check #1658 for proper handling of labels -> they need to be appended, rather than just set.
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.
The reason the amalgamation is there is LABELS "${tags}"
, rather than LABELS "${tag}"
.
Also the
This has two issues
|
Two more general thoughts
|
Is there any progress on this? |
I currently am not working on this (no idea when I will resume), so I hope someone can pick this up or maybe I will find the time to work on this at some point. |
I could probably take a look and take-over. A todo list of what needs to be done and/or some discussion of how this feature should be tested would help a lot. |
I think only the comments from @horenmar above and that should be it. |
Description
This allows people running
ctest -L 'tag'
to run tests matching the tagsGitHub Issues
#1590, #2613