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

Getting current test case description from within the test function #112

Open
didrocks opened this issue Jan 11, 2023 · 4 comments
Open

Comments

@didrocks
Copy link

Hey, great crate enabling to do table testing in Rust!

As part of most of the tests, I generate golden files after deserializing structs for instance or generated tree content. One way to identify them in a table testing environment is to generate based on the sub test name, and I feel the description will be really helpful for this.

Is there a way to get back the description within the test to achieve this? I would prefer not add an additional attribute and repeating the test description, but that’s a possible workaround.

Thanks!

@luke-biel
Copy link
Collaborator

There's currently no way to get the description or name of a test from within it's body. There were discussions regarding having this functionality #37, however we didn't implement anything this far.

It shouldn't be hard to add tc_context!() macro to the scope of each test case, however I'm lagging with contributions to this crate due to a lot of things happening in my private life, so I won't be able to implement that any time soon. If you have time and energy to do that on your own we can discuss implementation details and I can review the code + release it, but that's about it.

@frondeus
Copy link
Owner

I know there is separate https://crates.io/crates/function_name crate that gives such a macro. I wonder if this will work as workaround or even inspiration for this issue solution

@didrocks
Copy link
Author

@luke-biel: thanks for the honest feedback! I’m still unsure about my macro foo in rust so I will not tackle that right away before getting more familiar with the language.

@frondeus: I did try that the other day as a workaround, but the function name reported it the original function name (which is untouched in the DSL I guess). The only workaorund I found was to go through the thread name, (which work unless you force all your tests in a single thread).

@frondeus
Copy link
Owner

Ah yes, I made test by myself, you are right. Those two macros are incompatible :(

I will think about the solution :)

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

No branches or pull requests

3 participants