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

CLI filtering/matching test case sections #99

Open
jeremyong opened this issue May 26, 2023 · 3 comments
Open

CLI filtering/matching test case sections #99

jeremyong opened this issue May 26, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@jeremyong
Copy link

First of all, thanks a lot for this library!

I was curious if there was a mechanism to list/match sections contained within test cases. Sections are a very convenient way to handle test setup/teardown, but the unfortunate drawback is that sections can't be run in isolation as far as I can tell.

@cschreib
Copy link
Member

cschreib commented May 26, 2023

Hi! There is currently no way to do this. Filtering a test case to only run certain sections would be possible, without too much cost, but figuring out the filtering syntax and how it meshes with the existing test case filtering will require some thinking.

As for listing sections, that would also be possible but with a big caveat: it would require actually executing all the test code. Indeed, sections aren't known when entering a test case, they are discovered as the test code executes and encounters SECTION blocks. To bypass this, we'd need some sort of introspection (reflexion) on the code of the test case, and that's not likely to happen anytime soon! In the meantime, it could be implemented in the naive way, executing the code, but that's going to be too slow for most applications, and also risks executing failing REQUIRE*() checks that fail and abort... I suspect that's not going to be practical.

I know it's tempting to have one big test case with lots of sections in it :) But my advice here is, if you start to feel the need to execute only one section, then it's probably a sign that you should create a different test case. You can factor out the common code the old fashioned way, with functions and classes.

@cschreib cschreib added enhancement New feature or request maybe For issues that aren't critial, or need more exploration labels May 26, 2023
@jeremyong
Copy link
Author

For the filtering syntax, I was thinking that something simple would be to use a . access pattern. For example, a test case named Foo with sections S0, S1, and S2 could be filtered using Foo.S0 to run only the section S0 of test case Foo. This has the drawback of possibly colliding with tests that have a ., but given that . is used as a special symbol in the case of tags, it's not unreasonable to expect that . behaves differently in the test naming case also. I feel like . subsection handling is far too natural to consider anything more complicated (although I could be persuaded of course, this is just my gut reaction). You can imagine that *-based pattern matching could apply to the test case prefix in addition to the section suffix (if present).

Agreed that providing test section listing support might be too much trouble than what it's worth.

@cschreib
Copy link
Member

For reference, Catch2 does this with a separate CLI option --section .... If this is implemented in snitch, we will want to follow the same CLI API to benefit from IDE integrations etc.

@cschreib cschreib removed the maybe For issues that aren't critial, or need more exploration label Aug 13, 2023
@cschreib cschreib added this to the v1.x milestone Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants