Giter Site home page Giter Site logo

Dynamic set of tests about rstest HOT 4 CLOSED

la10736 avatar la10736 commented on July 30, 2024 3
Dynamic set of tests

from rstest.

Comments (4)

tgsmith61591 avatar tgsmith61591 commented on July 30, 2024

I would also love to see this feature implemented.

from rstest.

la10736 avatar la10736 commented on July 30, 2024

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.

orenbenkiki avatar orenbenkiki commented on July 30, 2024

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.

orenbenkiki avatar orenbenkiki commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.