Comments (4)
I would also love to see this feature implemented.
from rstest.
I know that lot of people love/need this kind of feature. But unfortunately this feature cannot implemented just by use procedural macro.
A procedural macro work just on the syntactic tree of the annotated function and (fortunately) cannot access to the file system or execute code.
The code that you wrote cannot work because procedural macro are executed in the early compile time stage but your code relay on the run time resolution of TEST_CASES
.
The only way to implemented a feature like this is to introduce a build.rs
script that can access to the file system and add the list of files as test cases... But I don't want (for now) tell to my customers to add a build script and cut and paste some code on it. There is at least a crate that implement it to generate tests from files... But I don't remember the name
The completely dynamic implementation (not just files) is impossible without implement a custom test hardness
from rstest.
Right.
The baked-in #[test]
macro collects static references to all the tests "TestDescAndFn" into a static array and passes this to the test runner. So, "all" that is needed to be done is to replace this by having a global vector of TestDescAndFn, populate it with the static tests, and also provide an API (that can be invoked inside lazy_static!
) to dynamically add entries to this vector, then pass the collected tests from the vector to the test runner.
This would require making a (backward-compatible, relatively minor) change in the way #[test]
is implemented. Once this is done, then it would be easy to provide dynamic test generation in user crates, even when using the standard test harness.
Variants of this have been requested for a long time (e.g. https://internals.rust-lang.org/t/pre-rfc-dynamic-tests/6790 is 4 years old), to o avail. It seems that Rust's answer to "dynamic tests" is to require switching to a different test harness. For example https://docs.rs/datatest/0.7.1/datatest/ which, alas, requires nightly
Perhaps they would be amenable to a minimal pull request to overcome this - it does seem like a minor change - but even so, such a thing would spend a long time in nightly before it would be added into stable...
from rstest.
I posted https://internals.rust-lang.org/t/dynamic-tests-revisited/18095 to see whether there's any chance of this getting (eventually) supported. Don't hold your breath :-)
Looking at it again, it seems that by hijacking #[test]
to generate almost-the-same code, it would be possible to implement dynamic tests in a crate even in stable (along the lines I posted above). One would have to be careful to maintain compatibility with the code generated by #[test]
whenever that changed, however.
from rstest.
Related Issues (20)
- Unable to use circular fixtures HOT 3
- Async fixture + Timeout doesn't work HOT 6
- ambiguous template name that isnt visible after import even if it was imported HOT 4
- Code Actions Not Working With Async Tests HOT 3
- Is there an alternative to this .await syntax? HOT 1
- An option to disable "TEST START" println? HOT 9
- once with a test context HOT 5
- Named tests HOT 7
- Detect and error on duplicate test cases HOT 4
- Runtime skipping of tests HOT 4
- Ability to generate test cases from file path HOT 12
- Better name modules to avoid collisions HOT 2
- Omit case_n for named cases of parameterized tests HOT 6
- Compiling on latest nightly fails HOT 5
- Wrong panic message when `#[timeout(...)]` is not expired HOT 9
- Use fixtures in in cases HOT 2
- Prepend `super::` to function call? HOT 2
- Exported rstest_reuse template cannot be defined at the top level HOT 5
- unused_import warning for rstest_reuse templates exported and only used by other crates HOT 1
- Get test case name HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rstest.